diff options
Diffstat (limited to 'js/panels/css-panel/styles-view-mediator.js')
-rw-r--r-- | js/panels/css-panel/styles-view-mediator.js | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/js/panels/css-panel/styles-view-mediator.js b/js/panels/css-panel/styles-view-mediator.js new file mode 100644 index 00000000..c93a5e73 --- /dev/null +++ b/js/panels/css-panel/styles-view-mediator.js | |||
@@ -0,0 +1,111 @@ | |||
1 | /* <copyright> | ||
2 | This file contains proprietary software owned by Motorola Mobility, Inc.<br/> | ||
3 | No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/> | ||
4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | ||
5 | </copyright> */ | ||
6 | |||
7 | var Montage = require("montage/core/core").Montage, | ||
8 | Component = require("montage/ui/component").Component, | ||
9 | Keyboard = require("js/mediators/keyboard-mediator").Keyboard; | ||
10 | |||
11 | exports.StylesViewMediator = Montage.create(Component, { | ||
12 | stylesController : { | ||
13 | get: function() { | ||
14 | return this.application.ninja.stylesController; | ||
15 | }, | ||
16 | set: function(){ | ||
17 | return; | ||
18 | } | ||
19 | }, | ||
20 | handleAddAction : { | ||
21 | value: function(e) { | ||
22 | var selector, newRule; | ||
23 | |||
24 | ///// Add rule to the container | ||
25 | |||
26 | ///// Get selection prefix | ||
27 | if(this.ruleListContainer.displayedList.selection.length > 1) { | ||
28 | selector = this.stylesController.generateClassName(null, true); | ||
29 | } else { | ||
30 | selector = this.stylesController.generateClassName(this.ruleListContainer.displayedList.selection[0].nodeName); | ||
31 | } | ||
32 | |||
33 | newRule = this.application.ninja.stylesController.addRule('.'+selector, ' { }'); | ||
34 | |||
35 | this.ruleListContainer.displayedList.component.addRule(newRule); | ||
36 | |||
37 | } | ||
38 | }, | ||
39 | handleStyleStop: { | ||
40 | value: function(e) { | ||
41 | console.log("Handle Style Stop"); | ||
42 | //debugger; | ||
43 | if(e._event.detail.type === 'keydown') { | ||
44 | |||
45 | } | ||
46 | } | ||
47 | }, | ||
48 | handlePropertyChange : { | ||
49 | value: function(rule, property, value, oldProperty, style) { | ||
50 | var browserValue; | ||
51 | |||
52 | if(style.editingNewStyle) { | ||
53 | return false; | ||
54 | } | ||
55 | |||
56 | ///// Remove old property and add new one | ||
57 | this.stylesController.deleteStyle(rule, oldProperty); | ||
58 | browserValue = this.stylesController.setStyle(rule, property, value); | ||
59 | |||
60 | ///// Mark style as invalid if the browser doesn't accept it | ||
61 | style.invalid = (browserValue === null); | ||
62 | |||
63 | console.log("BrowserValue: ", browserValue, rule); | ||
64 | |||
65 | this._dispatchChange(property, browserValue); | ||
66 | } | ||
67 | }, | ||
68 | handleValueChange : { | ||
69 | value: function(rule, property, value, style) { | ||
70 | var browserValue, units; | ||
71 | |||
72 | ///// Auto-fill units if not provided and units | ||
73 | ///// not previously stored | ||
74 | units = style.getUnits(value); | ||
75 | if(style.units && units === null && parseInt(value)) { | ||
76 | value += style.units; | ||
77 | style.valueField.value = value; | ||
78 | } else if (value !== '0') { | ||
79 | style.units = units; | ||
80 | } | ||
81 | |||
82 | ///// update value | ||
83 | browserValue = this.stylesController.setStyle(rule, property, value); | ||
84 | |||
85 | ///// Mark style as invalid if the browser doesn't accept it | ||
86 | style.invalid = (browserValue === null); | ||
87 | |||
88 | console.log("BrowserValue: ", browserValue, rule); | ||
89 | |||
90 | this._dispatchChange(property, browserValue); | ||
91 | |||
92 | if(style.editingNewStyle) { | ||
93 | style.treeView.parentComponent.addNewStyle(); | ||
94 | } | ||
95 | } | ||
96 | }, | ||
97 | |||
98 | _dispatchChange : { | ||
99 | value: function(property, value) { | ||
100 | this.application.ninja.stage.updatedStage = true; | ||
101 | NJevent('elementChange', { | ||
102 | type : 'cssChange', | ||
103 | data: { | ||
104 | "prop": property, | ||
105 | "value": value | ||
106 | }, | ||
107 | redraw: null | ||
108 | }); | ||
109 | } | ||
110 | } | ||
111 | }); \ No newline at end of file | ||