[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 /* 2 YUI 3.17.2 (build 9c3c78e) 3 Copyright 2014 Yahoo! Inc. All rights reserved. 4 Licensed under the BSD License. 5 http://yuilibrary.com/license/ 6 */ 7 8 YUI.add('editor-br', function (Y, NAME) { 9 10 11 12 /** 13 * Plugin for Editor to normalize BR's. 14 * @class Plugin.EditorBR 15 * @extends Base 16 * @constructor 17 * @module editor 18 * @submodule editor-br 19 */ 20 21 22 var EditorBR = function() { 23 EditorBR.superclass.constructor.apply(this, arguments); 24 }, HOST = 'host', LI = 'li'; 25 26 27 Y.extend(EditorBR, Y.Base, { 28 /** 29 * Frame keyDown handler that normalizes BR's when pressing ENTER. 30 * @private 31 * @method _onKeyDown 32 */ 33 _onKeyDown: function(e) { 34 if (e.stopped) { 35 e.halt(); 36 return; 37 } 38 if (e.keyCode === 13) { 39 var host = this.get(HOST), inst = host.getInstance(), 40 sel = new inst.EditorSelection(); 41 42 if (sel) { 43 if (Y.UA.ie) { 44 if (!sel.anchorNode || (!sel.anchorNode.test(LI) && !sel.anchorNode.ancestor(LI))) { 45 host.execCommand('inserthtml', inst.EditorSelection.CURSOR); 46 e.halt(); 47 } 48 } 49 if (Y.UA.webkit) { 50 if (!sel.anchorNode || (!sel.anchorNode.test(LI) && !sel.anchorNode.ancestor(LI))) { 51 host.frame._execCommand('insertlinebreak', null); 52 e.halt(); 53 } 54 } 55 } 56 } 57 }, 58 /** 59 * Adds listeners for keydown in IE and Webkit. Also fires insertbeonreturn for supporting browsers. 60 * @private 61 * @method _afterEditorReady 62 */ 63 _afterEditorReady: function() { 64 var inst = this.get(HOST).getInstance(), 65 container; 66 67 try { 68 inst.config.doc.execCommand('insertbronreturn', null, true); 69 } catch (bre) {} 70 71 if (Y.UA.ie || Y.UA.webkit) { 72 container = inst.EditorSelection.ROOT; 73 74 if (container.test('body')) { 75 container = inst.config.doc; 76 } 77 78 inst.on('keydown', Y.bind(this._onKeyDown, this), container); 79 } 80 }, 81 /** 82 * Adds a nodeChange listener only for FF, in the event of a backspace or delete, it creates an empy textNode 83 * inserts it into the DOM after the e.changedNode, then removes it. Causing FF to redraw the content. 84 * @private 85 * @method _onNodeChange 86 * @param {Event} e The nodeChange event. 87 */ 88 _onNodeChange: function(e) { 89 switch (e.changedType) { 90 case 'backspace-up': 91 case 'backspace-down': 92 case 'delete-up': 93 /* 94 * This forced FF to redraw the content on backspace. 95 * On some occasions FF will leave a cursor residue after content has been deleted. 96 * Dropping in the empty textnode and then removing it causes FF to redraw and 97 * remove the "ghost cursors" 98 */ 99 var inst = this.get(HOST).getInstance(), 100 d = e.changedNode, 101 t = inst.config.doc.createTextNode(' '); 102 d.appendChild(t); 103 d.removeChild(t); 104 break; 105 } 106 }, 107 initializer: function() { 108 var host = this.get(HOST); 109 if (host.editorPara) { 110 Y.error('Can not plug EditorBR and EditorPara at the same time.'); 111 return; 112 } 113 host.after('ready', Y.bind(this._afterEditorReady, this)); 114 if (Y.UA.gecko) { 115 host.on('nodeChange', Y.bind(this._onNodeChange, this)); 116 } 117 } 118 }, { 119 /** 120 * editorBR 121 * @static 122 * @property NAME 123 */ 124 NAME: 'editorBR', 125 /** 126 * editorBR 127 * @static 128 * @property NS 129 */ 130 NS: 'editorBR', 131 ATTRS: { 132 host: { 133 value: false 134 } 135 } 136 }); 137 138 Y.namespace('Plugin'); 139 140 Y.Plugin.EditorBR = EditorBR; 141 142 143 144 }, '3.17.2', {"requires": ["editor-base"]});
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |