~ubuntu-branches/ubuntu/raring/maas/raring-updates

« back to all changes in this revision

Viewing changes to src/maasserver/static/jslibs/yui/3.4.1/build/editor-para/editor-para-debug.js

  • Committer: Package Import Robot
  • Author(s): Andres Rodriguez
  • Date: 2012-07-03 17:42:37 UTC
  • mfrom: (1.1.13)
  • Revision ID: package-import@ubuntu.com-20120703174237-p8l0keuuznfg721k
Tags: 0.1+bzr709+dfsg-0ubuntu1
* New Upstream release
* debian/control:
  - Depends on python-celery, python-tempita, libjs-yui3-{full,min},
    libjs-raphael
* debian/maas.install:
  - Install apiclient, celeryconfig.py, maas-import-pxe-files, preseeds_v2.
  - Update to install various files from chroot, rather tha manually copy
    them from the source.
* debian/maas.links: symlink celeryconfig.py
* debian/maas.maas-celery.upstart: Add job.
* debian/rules:
  - Install celery upstart job.
  - Do not install jslibs as packages are now used.
  - Drop copying of maas_local_settings_sample.py as source now ships
    a maas_local_settings.py
* debian/patches:
  - 04-maas-http-fix.patch: Drop. Merged upstream.
  - 01-fix-database-settings.patch: Refreshed.
  - 99_enums_js.patch: Added until creation of enum.js / build process
    is fixed.
* debian/maas.postinst: Update bzr version to correctly handle upgrades.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
YUI 3.4.1 (build 4118)
3
 
Copyright 2011 Yahoo! Inc. All rights reserved.
4
 
Licensed under the BSD License.
5
 
http://yuilibrary.com/license/
6
 
*/
7
 
YUI.add('editor-para', function(Y) {
8
 
 
9
 
 
10
 
    /**
11
 
     * Plugin for Editor to paragraph auto wrapping and correction.
12
 
     * @class Plugin.EditorPara
13
 
     * @extends Base
14
 
     * @constructor
15
 
     * @module editor
16
 
     * @submodule editor-para
17
 
     */
18
 
 
19
 
 
20
 
    var EditorPara = function() {
21
 
        EditorPara.superclass.constructor.apply(this, arguments);
22
 
    }, HOST = 'host', BODY = 'body', NODE_CHANGE = 'nodeChange', PARENT_NODE = 'parentNode',
23
 
    FIRST_P = BODY + ' > p', P = 'p', BR = '<br>', FC = 'firstChild', LI = 'li';
24
 
 
25
 
 
26
 
    Y.extend(EditorPara, Y.Base, {
27
 
        /**
28
 
        * Utility method to create an empty paragraph when the document is empty.
29
 
        * @private
30
 
        * @method _fixFirstPara
31
 
        */
32
 
        _fixFirstPara: function() {
33
 
            Y.log('Fix First Paragraph', 'info', 'editor-para');
34
 
            var host = this.get(HOST), inst = host.getInstance(), sel, n,
35
 
                body = inst.config.doc.body,
36
 
                html = body.innerHTML,
37
 
                col = ((html.length) ? true : false);
38
 
 
39
 
            if (html === BR) {
40
 
                html = '';
41
 
                col = false;
42
 
            }
43
 
 
44
 
            body.innerHTML = '<' + P + '>' + html + inst.Selection.CURSOR + '</' + P + '>';
45
 
 
46
 
            n = inst.one(FIRST_P);
47
 
            sel = new inst.Selection();
48
 
 
49
 
            sel.selectNode(n, true, col);
50
 
        },
51
 
        /**
52
 
        * nodeChange handler to handle fixing an empty document.
53
 
        * @private
54
 
        * @method _onNodeChange
55
 
        */
56
 
        _onNodeChange: function(e) {
57
 
            var host = this.get(HOST), inst = host.getInstance(),
58
 
                html, txt, par , d, sel, btag = inst.Selection.DEFAULT_BLOCK_TAG,
59
 
                inHTML, txt2, childs, aNode, index, node2, top, n, sib,
60
 
                ps, br, item, p, imgs, t, LAST_CHILD = ':last-child';
61
 
 
62
 
            switch (e.changedType) {
63
 
                case 'enter-up':
64
 
                    var para = ((this._lastPara) ? this._lastPara : e.changedNode),
65
 
                        b = para.one('br.yui-cursor');
66
 
 
67
 
                    if (this._lastPara) {
68
 
                        delete this._lastPara;
69
 
                    }
70
 
 
71
 
                    if (b) {
72
 
                        if (b.previous() || b.next()) {
73
 
                            if (b.ancestor(P)) {
74
 
                                b.remove();
75
 
                            }
76
 
                        }
77
 
                    }
78
 
                    if (!para.test(btag)) {
79
 
                        var para2 = para.ancestor(btag);
80
 
                        if (para2) {
81
 
                            para = para2;
82
 
                            para2 = null;
83
 
                        }
84
 
                    }
85
 
                    if (para.test(btag)) {
86
 
                        var prev = para.previous(), lc, lc2, found = false;
87
 
                        if (prev) {
88
 
                            lc = prev.one(LAST_CHILD);
89
 
                            while (!found) {
90
 
                                if (lc) {
91
 
                                    lc2 = lc.one(LAST_CHILD);
92
 
                                    if (lc2) {
93
 
                                        lc = lc2;
94
 
                                    } else {
95
 
                                        found = true;
96
 
                                    }
97
 
                                } else {
98
 
                                    found = true;
99
 
                                }
100
 
                            }
101
 
                            if (lc) {
102
 
                                host.copyStyles(lc, para);
103
 
                            }
104
 
                        }
105
 
                    }
106
 
                    break;
107
 
                case 'enter':
108
 
                    if (Y.UA.ie) {
109
 
                        if (e.changedNode.test('br')) {
110
 
                            e.changedNode.remove();
111
 
                        } else if (e.changedNode.test('p, span')) {
112
 
                            var b = e.changedNode.one('br.yui-cursor');
113
 
                            if (b) {
114
 
                                b.remove();
115
 
                            }
116
 
                        }
117
 
                    }
118
 
                    if (Y.UA.webkit) {
119
 
                        //Webkit doesn't support shift+enter as a BR, this fixes that.
120
 
                        if (e.changedEvent.shiftKey) {
121
 
                            host.execCommand('insertbr');
122
 
                            e.changedEvent.preventDefault();
123
 
                        }
124
 
                    }
125
 
                    if (e.changedNode.test('li') && !Y.UA.ie) {
126
 
                        html = inst.Selection.getText(e.changedNode);
127
 
                        if (html === '') {
128
 
                            par = e.changedNode.ancestor('ol,ul');
129
 
                            var dir = par.getAttribute('dir');
130
 
                            if (dir !== '') {
131
 
                                dir = ' dir = "' + dir + '"';
132
 
                            }
133
 
                            par = e.changedNode.ancestor(inst.Selection.BLOCKS);
134
 
                            d = inst.Node.create('<p' + dir + '>' + inst.Selection.CURSOR + '</p>');
135
 
                            par.insert(d, 'after');
136
 
                            e.changedNode.remove();
137
 
                            e.changedEvent.halt();
138
 
 
139
 
                            sel = new inst.Selection();
140
 
                            sel.selectNode(d, true, false);
141
 
                        }
142
 
                    }
143
 
                    //TODO Move this to a GECKO MODULE - Can't for the moment, requires no change to metadata (YMAIL)
144
 
                    if (Y.UA.gecko && host.get('defaultblock') !== 'p') {
145
 
                        par = e.changedNode;
146
 
 
147
 
                        if (!par.test(LI) && !par.ancestor(LI)) {
148
 
                            if (!par.test(btag)) {
149
 
                                par = par.ancestor(btag);
150
 
                            }
151
 
                            d = inst.Node.create('<' + btag + '></' + btag + '>');
152
 
                            par.insert(d, 'after');
153
 
                            sel = new inst.Selection();
154
 
                            if (sel.anchorOffset) {
155
 
                                inHTML = sel.anchorNode.get('textContent');
156
 
 
157
 
                                txt = inst.one(inst.config.doc.createTextNode(inHTML.substr(0, sel.anchorOffset)));
158
 
                                txt2 = inst.one(inst.config.doc.createTextNode(inHTML.substr(sel.anchorOffset)));
159
 
 
160
 
                                aNode = sel.anchorNode;
161
 
                                aNode.setContent(''); //I
162
 
                                node2 = aNode.cloneNode(); //I
163
 
                                node2.append(txt2); //text
164
 
                                top = false;
165
 
                                sib = aNode; //I
166
 
                                while (!top) {
167
 
                                    sib = sib.get(PARENT_NODE); //B
168
 
                                    if (sib && !sib.test(btag)) {
169
 
                                        n = sib.cloneNode();
170
 
                                        n.set('innerHTML', '');
171
 
                                        n.append(node2);
172
 
                                        
173
 
                                        //Get children..
174
 
                                        childs = sib.get('childNodes');
175
 
                                        var start = false;
176
 
                                        childs.each(function(c) {
177
 
                                            if (start) {
178
 
                                                n.append(c);
179
 
                                            }
180
 
                                            if (c === aNode) {
181
 
                                                start = true;
182
 
                                            }
183
 
                                        });
184
 
 
185
 
                                        aNode = sib; //Top sibling
186
 
                                        node2 = n;
187
 
                                    } else {
188
 
                                        top = true;
189
 
                                    }
190
 
                                }
191
 
                                txt2 = node2;
192
 
                                sel.anchorNode.append(txt);
193
 
 
194
 
                                if (txt2) {
195
 
                                    d.append(txt2);
196
 
                                }
197
 
                            }
198
 
                            if (d.get(FC)) {
199
 
                                d = d.get(FC);
200
 
                            }
201
 
                            d.prepend(inst.Selection.CURSOR);
202
 
                            sel.focusCursor(true, true);
203
 
                            html = inst.Selection.getText(d);
204
 
                            if (html !== '') {
205
 
                                inst.Selection.cleanCursor();
206
 
                            }
207
 
                            e.changedEvent.preventDefault();
208
 
                        }
209
 
                    }
210
 
                    break;
211
 
                case 'keyup':
212
 
                    if (Y.UA.gecko) {
213
 
                        if (inst.config.doc && inst.config.doc.body && inst.config.doc.body.innerHTML.length < 20) {
214
 
                            if (!inst.one(FIRST_P)) {
215
 
                                this._fixFirstPara();
216
 
                            }
217
 
                        }
218
 
                    }
219
 
                    break;
220
 
                case 'backspace-up':
221
 
                case 'backspace-down':
222
 
                case 'delete-up':
223
 
                    if (!Y.UA.ie) {
224
 
                        ps = inst.all(FIRST_P);
225
 
                        item = inst.one(BODY);
226
 
                        if (ps.item(0)) {
227
 
                            item = ps.item(0);
228
 
                        }
229
 
                        br = item.one('br');
230
 
                        if (br) {
231
 
                            br.removeAttribute('id');
232
 
                            br.removeAttribute('class');
233
 
                        }
234
 
 
235
 
                        txt = inst.Selection.getText(item);
236
 
                        txt = txt.replace(/ /g, '').replace(/\n/g, '');
237
 
                        imgs = item.all('img');
238
 
                        
239
 
                        if (txt.length === 0 && !imgs.size()) {
240
 
                            //God this is horrible..
241
 
                            if (!item.test(P)) {
242
 
                                this._fixFirstPara();
243
 
                            }
244
 
                            p = null;
245
 
                            if (e.changedNode && e.changedNode.test(P)) {
246
 
                                p = e.changedNode;
247
 
                            }
248
 
                            if (!p && host._lastPara && host._lastPara.inDoc()) {
249
 
                                p = host._lastPara;
250
 
                            }
251
 
                            if (p && !p.test(P)) {
252
 
                                p = p.ancestor(P);
253
 
                            }
254
 
                            if (p) {
255
 
                                if (!p.previous() && p.get(PARENT_NODE) && p.get(PARENT_NODE).test(BODY)) {
256
 
                                    Y.log('Stopping the backspace event', 'warn', 'editor-para');
257
 
                                    e.changedEvent.frameEvent.halt();
258
 
                                }
259
 
                            }
260
 
                        }
261
 
                        if (Y.UA.webkit) {
262
 
                            if (e.changedNode) {
263
 
                                item = e.changedNode;
264
 
                                if (item.test('li') && (!item.previous() && !item.next())) {
265
 
                                    html = item.get('innerHTML').replace(BR, '');
266
 
                                    if (html === '') {
267
 
                                        if (item.get(PARENT_NODE)) {
268
 
                                            item.get(PARENT_NODE).replace(inst.Node.create(BR));
269
 
                                            e.changedEvent.frameEvent.halt();
270
 
                                            e.preventDefault();
271
 
                                            inst.Selection.filterBlocks();
272
 
                                        }
273
 
                                    }
274
 
                                }
275
 
                            }
276
 
                        }
277
 
                    }
278
 
                    if (Y.UA.gecko) {
279
 
                        /*
280
 
                        * This forced FF to redraw the content on backspace.
281
 
                        * On some occasions FF will leave a cursor residue after content has been deleted.
282
 
                        * Dropping in the empty textnode and then removing it causes FF to redraw and
283
 
                        * remove the "ghost cursors"
284
 
                        */
285
 
                        d = e.changedNode;
286
 
                        t = inst.config.doc.createTextNode(' ');
287
 
                        d.appendChild(t);
288
 
                        d.removeChild(t);
289
 
                    }
290
 
                    break;
291
 
            }
292
 
            if (Y.UA.gecko) {
293
 
                if (e.changedNode && !e.changedNode.test(btag)) {
294
 
                    p = e.changedNode.ancestor(btag);
295
 
                    if (p) {
296
 
                        this._lastPara = p;
297
 
                    }
298
 
                }
299
 
            }
300
 
            
301
 
        },
302
 
        /**
303
 
        * Performs a block element filter when the Editor is first ready
304
 
        * @private
305
 
        * @method _afterEditorReady
306
 
        */
307
 
        _afterEditorReady: function() {
308
 
            var host = this.get(HOST), inst = host.getInstance(), btag;
309
 
            if (inst) {
310
 
                inst.Selection.filterBlocks();
311
 
                btag = inst.Selection.DEFAULT_BLOCK_TAG;
312
 
                FIRST_P = BODY + ' > ' + btag;
313
 
                P = btag;
314
 
            }
315
 
        },
316
 
        /**
317
 
        * Performs a block element filter when the Editor after an content change
318
 
        * @private
319
 
        * @method _afterContentChange
320
 
        */
321
 
        _afterContentChange: function() {
322
 
            var host = this.get(HOST), inst = host.getInstance();
323
 
            if (inst && inst.Selection) {
324
 
                inst.Selection.filterBlocks();
325
 
            }
326
 
        },
327
 
        /**
328
 
        * Performs block/paste filtering after paste.
329
 
        * @private
330
 
        * @method _afterPaste
331
 
        */
332
 
        _afterPaste: function() {
333
 
            var host = this.get(HOST), inst = host.getInstance(),
334
 
                sel = new inst.Selection();
335
 
 
336
 
            Y.later(50, host, function() {
337
 
                inst.Selection.filterBlocks();
338
 
            });
339
 
            
340
 
        },
341
 
        initializer: function() {
342
 
            var host = this.get(HOST);
343
 
            if (host.editorBR) {
344
 
                Y.error('Can not plug EditorPara and EditorBR at the same time.');
345
 
                return;
346
 
            }
347
 
 
348
 
            host.on(NODE_CHANGE, Y.bind(this._onNodeChange, this));
349
 
            host.after('ready', Y.bind(this._afterEditorReady, this));
350
 
            host.after('contentChange', Y.bind(this._afterContentChange, this));
351
 
            if (Y.Env.webkit) {
352
 
                host.after('dom:paste', Y.bind(this._afterPaste, this));
353
 
            }
354
 
        }
355
 
    }, {
356
 
        /**
357
 
        * editorPara
358
 
        * @static
359
 
        * @property NAME
360
 
        */
361
 
        NAME: 'editorPara',
362
 
        /**
363
 
        * editorPara
364
 
        * @static
365
 
        * @property NS
366
 
        */
367
 
        NS: 'editorPara',
368
 
        ATTRS: {
369
 
            host: {
370
 
                value: false
371
 
            }
372
 
        }
373
 
    });
374
 
    
375
 
    Y.namespace('Plugin');
376
 
    
377
 
    Y.Plugin.EditorPara = EditorPara;
378
 
 
379
 
 
380
 
 
381
 
}, '3.4.1' ,{skinnable:false, requires:['editor-base']});