Merge lp:~rockstar/phazr/string-constants into lp:phazr

Proposed by Paul Hummer
Status: Merged
Approved by: Paul Hummer
Approved revision: 16
Merged at revision: 15
Proposed branch: lp:~rockstar/phazr/string-constants
Merge into: lp:phazr
Diff against target: 246 lines (+66/-43)
3 files modified
src/editableplugin/js/editable.js (+29/-20)
src/formplugin/js/form.js (+20/-13)
src/phazroverlay/js/overlay.js (+17/-10)
To merge this branch: bzr merge lp:~rockstar/phazr/string-constants
Reviewer Review Type Date Requested Status
Deryck Hodge code Approve
Review via email: mp+74545@code.launchpad.net

Commit message

Consolidate duplicate strings for better compressability.

Description of the change

So this evening I wrote this little tool[1] to detect duplicate strings in javascript files. Ideally, our compressor would detect these and figure it out for us, but that's the future, not the present. I used this tool on the phazr files to see where we might have duplicate strings, and then made "constants" out of them. It's a trivial thing, but something I think is still beneficial, at least until our compressor does it.

[1] https://github.com/rockstar/node-skillet

To post a comment you must log in.
Revision history for this message
Deryck Hodge (deryck) wrote :

Looks good. Cool idea for a little tool, too.

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/editableplugin/js/editable.js'
2--- src/editableplugin/js/editable.js 2011-08-24 21:17:37 +0000
3+++ src/editableplugin/js/editable.js 2011-09-08 05:07:08 +0000
4@@ -1,26 +1,35 @@
5-Y.Editable = Y.Base.create('editable', Y.Plugin.Base, [], {
6+var CLICK = 'click',
7+ EDITABLE = 'editable',
8+ EDITOR = 'editor',
9+ EMPTYDIV = '<div></div>',
10+ FIRSTCHILD = 'firstChild',
11+ HOST = 'host',
12+ MULTILINE = 'multiline',
13+ VALUE = 'value';
14+
15+Y.Editable = Y.Base.create(EDITABLE, Y.Plugin.Base, [], {
16 initializer: function(config) {
17- var host = this.get('host');
18- host.addClass('editable');
19- host.on('click', Y.bind(this.edit, this));
20+ var host = this.get(HOST);
21+ host.addClass(EDITABLE);
22+ host.on(CLICK, Y.bind(this.edit, this));
23 },
24 cancel: function() {
25- var editor = this.get('editor'),
26- host = this.get('host');
27+ var editor = this.get(EDITOR),
28+ host = this.get(HOST);
29 editor.hide();
30 host.show();
31 },
32 edit: function(e) {
33 e.preventDefault();
34- var host = this.get('host');
35- multiline = this.get('multiline'),
36+ var host = this.get(HOST);
37+ multiline = this.get(MULTILINE),
38 text = Y.Lang.trim(host.get('text')),
39- editor = this.get('editor');
40+ editor = this.get(EDITOR);
41
42 if (editor === null) {
43 var parentNode = host.get('parentNode'),
44- editor = Y.Node.create('<div></div>'),
45- controlTemplate = multiline ? '<div></div>' : '<span></span>',
46+ editor = Y.Node.create(EMPTYDIV),
47+ controlTemplate = multiline ? EMPTYDIV : '<span></span>',
48 controls = Y.Node.create(controlTemplate),
49 save = Y.Node.create(this.get('saveTemplate')),
50 cancel = Y.Node.create(this.get('cancelTemplate')),
51@@ -32,8 +41,8 @@
52 textbox = Y.Node.create('<input type="text" />');
53 }
54
55- save.on('click', this.save, this);
56- cancel.on('click', this.cancel, this);
57+ save.on(CLICK, this.save, this);
58+ cancel.on(CLICK, this.cancel, this);
59
60 controls.appendChild(save);
61 controls.appendChild(cancel);
62@@ -43,18 +52,18 @@
63
64 textbox.on('keyup', this._handleKeyPress, this);
65 parentNode.insert(editor, host);
66- this.set('editor', editor);
67+ this.set(EDITOR, editor);
68 }
69
70- editor.get('firstChild').set('value', text);
71+ editor.get(FIRSTCHILD).set(VALUE, text);
72 editor.show();
73 host.hide();
74 },
75 save: function() {
76- var editor = this.get('editor'),
77- host = this.get('host'),
78+ var editor = this.get(EDITOR),
79+ host = this.get(HOST),
80 save = this.get('saveFn'),
81- value = editor.get('firstChild').get('value');
82+ value = editor.get(FIRSTCHILD).get(VALUE);
83 if (save !== null) { save(value); }
84 host.setContent(value);
85 editor.hide();
86@@ -63,7 +72,7 @@
87 _handleKeyPress: function(e) {
88 if (e.keyCode) {
89 if (e.keyCode === 27) { this.cancel(); }
90- if (e.keyCode === 13 && this.get('multiline') === false) {
91+ if (e.keyCode === 13 && this.get(MULTILINE) === false) {
92 this.save();
93 }
94 }
95@@ -76,5 +85,5 @@
96 saveFn: { value: null },
97 saveTemplate: { value: '<button class="phazr-button phazr-save">Save</button>' }
98 },
99- NS: 'editable'
100+ NS: EDITABLE
101 });
102
103=== modified file 'src/formplugin/js/form.js'
104--- src/formplugin/js/form.js 2011-08-24 21:00:55 +0000
105+++ src/formplugin/js/form.js 2011-09-08 05:07:08 +0000
106@@ -1,18 +1,25 @@
107+var CANCELBUTTON = 'cancelButton',
108+ CLICK = 'click',
109+ FORM = 'form',
110+ HOST = 'host',
111+ SAVEBUTTON = 'saveButton',
112+ SUBMITFN = 'submitFn';
113+
114 Y.FormPlugin = Y.Base.create('formplugin', Y.Plugin.Base, [], {
115 initializer: function(config) {
116- var host = this.get('host');
117+ var host = this.get(HOST);
118
119 if (config.submitFn) {
120- this.set('submitFn', config.submitFn);
121+ this.set(SUBMITFN, config.submitFn);
122 }
123
124 this.afterHostMethod('renderUI', this.renderUI);
125 this.afterHostMethod('bindUI', this.bindUI);
126 },
127 renderUI: function() {
128- var host = this.get('host'),
129- saveButton = this.get('saveButton'),
130- cancelButton = this.get('cancelButton'),
131+ var host = this.get(HOST),
132+ saveButton = this.get(SAVEBUTTON),
133+ cancelButton = this.get(CANCELBUTTON),
134 controls = Y.Node.create('<div></div>');
135 controls.addClass(host.getClassName() + '-controls');
136 controls.appendChild(saveButton);
137@@ -20,23 +27,23 @@
138 host.get('contentBox').appendChild(controls);
139 },
140 bindUI: function() {
141- var host = this.get('host');
142+ var host = this.get(HOST);
143 footer = host.get('boundingBox').one('.yui3-widget-ft');
144- this.get('saveButton').on('click', this.get('submitFn'), this.get('host'));
145- this.get('cancelButton').on('click', this.close, this);
146+ this.get(SAVEBUTTON).on(CLICK, this.get(SUBMITFN), this.get(HOST));
147+ this.get(CANCELBUTTON).on(CLICK, this.close, this);
148 },
149 close: function(e) {
150 e.preventDefault();
151- this.get('host').hide();
152+ this.get(HOST).hide();
153 },
154 loadForm: function(form) {
155- var host = this.get('host'),
156+ var host = this.get(HOST),
157 form_node = Y.Node.create(form);
158 host.set('bodyContent', form_node);
159- this.set('form', form_node);
160+ this.set(FORM, form_node);
161 },
162 loadFormFromURL: function(url) {
163- var host = this.get('host');
164+ var host = this.get(HOST);
165 Y.io(url, {
166 on: {
167 success: function(id, response) {
168@@ -70,5 +77,5 @@
169 }
170 }
171 },
172- NS: 'form'
173+ NS: FORM
174 });
175
176=== modified file 'src/phazroverlay/js/overlay.js'
177--- src/phazroverlay/js/overlay.js 2011-08-25 03:24:53 +0000
178+++ src/phazroverlay/js/overlay.js 2011-09-08 05:07:08 +0000
179@@ -1,3 +1,10 @@
180+var BOUNDINGBOX = 'boundingBox',
181+ CLOSEBUTTON = 'closeButton',
182+ CLOSEBUTTONSUFFIX = '-close-button',
183+ HTML = 'html',
184+ MODALOUTSIDECLICK = 'modaloutside|click',
185+ PERIOD = '.';
186+
187 var ModalOverlay = function(config) {
188 Y.Do.after(this.afterRenderUI, this, 'renderUI');
189 Y.Do.after(this.afterBindUI, this, 'bindUI');
190@@ -12,27 +19,27 @@
191 className = this.getClassName(),
192 context = {
193 containerClassName: className + '-close',
194- linkClassName: className + '-close-button'
195+ linkClassName: className + CLOSEBUTTONSUFFIX
196 },
197 closeContainer = Y.Node.create(
198 Y.substitute(template, context));
199 this.get('contentBox').prepend(closeContainer);
200- this.set('closeButton',
201- closeContainer.one('.' + className + '-close-button'));
202+ this.set(CLOSEBUTTON,
203+ closeContainer.one(PERIOD + className + CLOSEBUTTONSUFFIX));
204 },
205 afterBindUI: function() {
206 this.after('renderedChange', this.afterRenderedChange, this);
207 this.after('visibleChange', this.afterVisibleChange, this);
208- this.get('closeButton').on('click', this.hide, this);
209+ this.get(CLOSEBUTTON).on('click', this.hide, this);
210 Y.on('keyup', function(e) {
211 if (e.keyCode == 27) {
212 this.hide();
213 }
214 }, window, this);
215
216- var box = this.get('boundingBox'),
217+ var box = this.get(BOUNDINGBOX),
218 className = this.getClassName(),
219- header = box.one('.' + className + '-hd'),
220+ header = box.one(PERIOD + className + '-hd'),
221 dd = new Y.DD.Drag({
222 node: box,
223 handle: header
224@@ -53,19 +60,19 @@
225 }
226 },
227 attachModalOutside: function() {
228- var box = this.get('boundingBox');
229- Y.one("html").on("modaloutside|click",
230+ var box = this.get(BOUNDINGBOX);
231+ Y.one(HTML).on(MODALOUTSIDECLICK,
232 function(e) {
233 var targ = e.target;
234 if (!box.contains(targ)) {
235 this.hide();
236- Y.detach("modaloutside|click");
237+ Y.detach(MODALOUTSIDECLICK);
238 }
239 },
240 this);
241 },
242 detachModalOutside: function() {
243- Y.one("html").detach("modaloutside|click");
244+ Y.one(HTML).detach(MODALOUTSIDECLICK);
245 }
246 };
247

Subscribers

People subscribed via source and target branches

to all changes: