85
97
_lastBookmark: null,
99
* Resolves the e.changedNode in the nodeChange event if it comes from the document. If
100
* the event came from the document, it will get the last child of the last child of the document
101
* and return that instead.
102
* @method _resolveChangedNode
103
* @param {Node} n The node to resolve
106
_resolveChangedNode: function(n) {
107
var inst = this.getInstance(), lc, lc2, found;
108
if (inst && n && n.test('html')) {
109
lc = inst.one(BODY).one(LAST_CHILD);
112
lc2 = lc.one(LAST_CHILD);
127
lc = lc.get('parentNode');
87
139
* The default handler for the nodeChange event.
88
140
* @method _defNodeChangeFn
89
141
* @param {Event} e The event
92
144
_defNodeChangeFn: function(e) {
93
145
var startTime = (new Date()).getTime();
94
146
//Y.log('Default nodeChange function: ' + e.changedType, 'info', 'editor');
95
var inst = this.getInstance(), sel;
147
var inst = this.getInstance(), sel, cur,
148
btag = inst.Selection.DEFAULT_BLOCK_TAG;
98
sel = inst.config.doc.selection.createRange();
99
this._lastBookmark = sel.getBookmark();
152
sel = inst.config.doc.selection.createRange();
153
if (sel.getBookmark) {
154
this._lastBookmark = sel.getBookmark();
159
e.changedNode = this._resolveChangedNode(e.changedNode);
104
163
* This whole method needs to be fixed and made more dynamic.
109
168
switch (e.changedType) {
111
inst.Selection.cleanCursor();
115
//Webkit doesn't support shift+enter as a BR, this fixes that.
116
if (e.changedEvent.shiftKey) {
117
this.execCommand('insertbr');
118
e.changedEvent.preventDefault();
171
if (!EditorBase.NC_KEYS[e.changedEvent.keyCode] && !e.changedEvent.shiftKey && !e.changedEvent.ctrlKey && (e.changedEvent.keyCode !== 13)) {
172
//inst.later(100, inst, inst.Selection.cleanCursor);
123
177
if (!e.changedNode.test('li, li *') && !e.changedEvent.shiftKey) {
124
e.changedEvent.preventDefault();
178
e.changedEvent.frameEvent.preventDefault();
126
179
Y.log('Overriding TAB key to insert HTML: HALTING', 'info', 'editor');
127
var sel = new inst.Selection();
129
var cur = sel.getCursor();
130
cur.insert(EditorBase.TABKEY, 'before');
135
if (e.changedNode.test('p')) {
136
var prev = e.changedNode.previous(), lc, lc2, found = false;
138
lc = prev.one(':last-child');
141
lc2 = lc.one(':last-child');
152
this.copyStyles(lc, e.changedNode);
181
this.execCommand('inserttext', '\t');
182
} else if (Y.UA.gecko) {
183
this.frame.exec._command('inserthtml', '<span> </span>');
184
} else if (Y.UA.ie) {
185
sel = new inst.Selection();
186
sel._selection.pasteHTML(EditorBase.TABKEY);
191
if (Y.UA.webkit && e.commands && (e.commands.indent || e.commands.outdent)) {
193
* When executing execCommand 'indent or 'outdent' Webkit applies
194
* a class to the BLOCKQUOTE that adds left/right margin to it
195
* This strips that style so it is just a normal BLOCKQUOTE
197
var bq = inst.all('.webkit-indent-blockquote');
199
bq.setStyle('margin', '');
159
203
var changed = this.getDomPath(e.changedNode, false),
160
204
cmds = {}, family, fsize, classes = [],
321
372
this.frame.on('dom:mouseup', Y.bind(this._onFrameMouseUp, this));
322
373
this.frame.on('dom:mousedown', Y.bind(this._onFrameMouseDown, this));
374
this.frame.on('dom:keydown', Y.bind(this._onFrameKeyDown, this));
377
this.frame.on('dom:activate', Y.bind(this._onFrameActivate, this));
378
this.frame.on('dom:beforedeactivate', Y.bind(this._beforeFrameDeactivate, this));
324
380
this.frame.on('dom:keyup', Y.bind(this._onFrameKeyUp, this));
325
this.frame.on('dom:keydown', Y.bind(this._onFrameKeyDown, this));
326
381
this.frame.on('dom:keypress', Y.bind(this._onFrameKeyPress, this));
328
//this.frame.on('dom:keydown', Y.throttle(Y.bind(this._onFrameKeyDown, this), 500));
331
this.frame.on('dom:keydown', Y.bind(this._onFrameKeyDown, this));
334
this.frame.on('dom:activate', Y.bind(this._onFrameActivate, this));
335
this.frame.on('dom:keyup', Y.throttle(Y.bind(this._onFrameKeyUp, this), 800));
336
this.frame.on('dom:keypress', Y.throttle(Y.bind(this._onFrameKeyPress, this), 800));
338
this.frame.on('dom:keyup', Y.bind(this._onFrameKeyUp, this));
339
this.frame.on('dom:keypress', Y.bind(this._onFrameKeyPress, this));
342
383
inst.Selection.filter();
343
384
this.fire('ready');
387
* Caches the current cursor position in IE.
388
* @method _beforeFrameDeactivate
391
_beforeFrameDeactivate: function() {
392
var inst = this.getInstance(),
393
sel = inst.config.doc.selection.createRange();
395
if ((!sel.compareEndPoints('StartToEnd', sel))) {
396
sel.pasteHTML('<var id="yui-ie-cursor">');
346
400
* Moves the cached selection bookmark back so IE can place the cursor in the right place.
347
401
* @method _onFrameActivate
350
404
_onFrameActivate: function() {
351
if (this._lastBookmark) {
352
Y.log('IE Activate handler, resetting cursor position', 'info', 'editor');
353
var inst = this.getInstance(),
354
sel = inst.config.doc.selection.createRange(),
355
bk = sel.moveToBookmark(this._lastBookmark);
405
var inst = this.getInstance(),
406
sel = new inst.Selection(),
407
range = sel.createRange(),
408
cur = inst.all('#yui-ie-cursor');
359
this._lastBookmark = null;
411
cur.each(function(n) {
413
range.moveToElementText(n._node);
414
range.move('character', -1);
415
range.move('character', 1);
396
467
this._currentSelectionTimer = Y.later(850, this, function() {
397
468
this._currentSelectionClear = true;
399
var inst = this.frame.getInstance(),
400
sel = new inst.Selection(e);
471
inst = this.frame.getInstance();
472
sel = new inst.Selection(e);
402
474
this._currentSelection = sel;
404
var sel = this._currentSelection;
476
sel = this._currentSelection;
406
var inst = this.frame.getInstance(),
407
sel = new inst.Selection();
409
this._currentSelection = sel;
479
inst = this.frame.getInstance();
480
sel = new inst.Selection();
482
this._currentSelection = sel;
411
484
if (sel && sel.anchorNode) {
412
485
this.fire('nodeChange', { changedNode: sel.anchorNode, changedType: 'keydown', changedEvent: e.frameEvent });
413
486
if (EditorBase.NC_KEYS[e.keyCode]) {
628
* @method NORMALIZE_FONTSIZE
629
* @description Pulls the fontSize from a node, then checks for string values (x-large, x-small)
630
* and converts them to pixel sizes. If the parsed size is different from the original, it calls
631
* node.setStyle to update the node with a pixel size for normalization.
633
NORMALIZE_FONTSIZE: function(n) {
634
var size = n.getStyle('fontSize'), oSize = size;
637
case '-webkit-xxx-large':
659
if (oSize !== size) {
660
n.setStyle('fontSize', size);
555
666
* @property TABKEY
556
667
* @description The HTML markup to use for the tabkey