📄 simpleeditor-debug.js
字号:
} oButton.value = ev.value; this._buttonClick(ev, oButton); }, this, true); var self = this; //Hijack the mousedown event in the menu and make it fire a button click.. tmp.on('appendTo', function() { var tmp = this; if (tmp.getMenu() && tmp.getMenu().mouseDownEvent) { tmp.getMenu().mouseDownEvent.subscribe(function(ev, args) { YAHOO.log('mouseDownEvent', 'warn', 'Toolbar'); var oMenu = args[1]; YAHOO.util.Event.stopEvent(args[0]); tmp._onMenuClick(args[0], tmp); if (!oButton.menucmd) { oButton.menucmd = oButton.value; } oButton.value = ((oMenu.value) ? oMenu.value : oMenu._oText.nodeValue); self._buttonClick.call(self, args[1], oButton); tmp._hideMenu(); return false; }); tmp.getMenu().clickEvent.subscribe(function(ev, args) { YAHOO.log('clickEvent', 'warn', 'Toolbar'); YAHOO.util.Event.stopEvent(args[0]); }); tmp.getMenu().mouseUpEvent.subscribe(function(ev, args) { YAHOO.log('mouseUpEvent', 'warn', 'Toolbar'); YAHOO.util.Event.stopEvent(args[0]); }); } }); } } else { //Stop the mousedown event so we can trap the selection in the editor! tmp.on('mousedown', function(ev) { YAHOO.util.Event.stopEvent(ev); }); tmp.on('click', function(ev) { YAHOO.util.Event.stopEvent(ev); }); } if (this.browser.ie) { /* //Add a couple of new events for IE tmp.DOM_EVENTS.focusin = true; tmp.DOM_EVENTS.focusout = true; //Stop them so we don't loose focus in the Editor tmp.on('focusin', function(ev) { YAHOO.util.Event.stopEvent(ev); }, oButton, this); tmp.on('focusout', function(ev) { YAHOO.util.Event.stopEvent(ev); }, oButton, this); tmp.on('click', function(ev) { YAHOO.util.Event.stopEvent(ev); }, oButton, this); */ } if (this.browser.webkit) { //This will keep the document from gaining focus and the editor from loosing it.. //Forcefully remove the focus calls in button! tmp.hasFocus = function() { return true; }; } this._buttonList[this._buttonList.length] = tmp; if ((oButton.type == 'menu') || (oButton.type == 'split') || (oButton.type == 'select')) { if (Lang.isArray(oButton.menu)) { YAHOO.log('Button type is (' + oButton.type + '), doing extra renderer work.', 'info', 'Toolbar'); var menu = tmp.getMenu(); if (menu && menu.renderEvent) { menu.renderEvent.subscribe(this._addMenuClasses, tmp); if (oButton.renderer) { menu.renderEvent.subscribe(oButton.renderer, tmp); } } } } } return oButton; }, /** * @method addSeparator * @description Add a new button separator to the toolbar. * @param {HTMLElement} cont Optional HTML element to insert this button into. * @param {HTMLElement} after Optional HTML element to insert this button after in the DOM. */ addSeparator: function(cont, after) { if (!this.get('element')) { this._queue[this._queue.length] = ['addSeparator', arguments]; return false; } var sepCont = ((cont) ? cont : this.get('cont')); if (!this.get('element')) { this._queue[this._queue.length] = ['addSeparator', arguments]; return false; } if (this._sepCount === null) { this._sepCount = 0; } if (!this._sep) { YAHOO.log('Separator does not yet exist, creating', 'info', 'Toolbar'); this._sep = document.createElement('SPAN'); Dom.addClass(this._sep, this.CLASS_SEPARATOR); this._sep.innerHTML = '|'; } YAHOO.log('Separator does exist, cloning', 'info', 'Toolbar'); var _sep = this._sep.cloneNode(true); this._sepCount++; Dom.addClass(_sep, this.CLASS_SEPARATOR + '-' + this._sepCount); if (after) { var nextSib = null; if (after.get) { nextSib = after.get('element').nextSibling; } else if (after.nextSibling) { nextSib = after.nextSibling; } else { nextSib = after; } if (nextSib) { if (nextSib == after) { nextSib.parentNode.appendChild(_sep); } else { nextSib.parentNode.insertBefore(_sep, nextSib); } } } else { sepCont.appendChild(_sep); } return _sep; }, /** * @method _createColorPicker * @private * @description Creates the core DOM reference to the color picker menu item. * @param {String} id the id of the toolbar to prefix this DOM container with. */ _createColorPicker: function(id) { if (Dom.get(id + '_colors')) { Dom.get(id + '_colors').parentNode.removeChild(Dom.get(id + '_colors')); } var picker = document.createElement('div'); picker.className = 'yui-toolbar-colors'; picker.id = id + '_colors'; picker.style.display = 'none'; Event.on(window, 'load', function() { document.body.appendChild(picker); }, this, true); this._colorPicker = picker; var html = ''; for (var i in this._colorData) { if (Lang.hasOwnProperty(this._colorData, i)) { html += '<a style="background-color: ' + i + '" href="#">' + i.replace('#', '') + '</a>'; } } html += '<span><em>X</em><strong></strong></span>'; window.setTimeout(function() { picker.innerHTML = html; }, 0); Event.on(picker, 'mouseover', function(ev) { var picker = this._colorPicker; var em = picker.getElementsByTagName('em')[0]; var strong = picker.getElementsByTagName('strong')[0]; var tar = Event.getTarget(ev); if (tar.tagName.toLowerCase() == 'a') { em.style.backgroundColor = tar.style.backgroundColor; strong.innerHTML = this._colorData['#' + tar.innerHTML] + '<br>' + tar.innerHTML; } }, this, true); Event.on(picker, 'focus', function(ev) { Event.stopEvent(ev); }); Event.on(picker, 'click', function(ev) { Event.stopEvent(ev); }); Event.on(picker, 'mousedown', function(ev) { Event.stopEvent(ev); var tar = Event.getTarget(ev); if (tar.tagName.toLowerCase() == 'a') { var retVal = this.fireEvent('colorPickerClicked', { type: 'colorPickerClicked', target: this, button: this._colorPicker._button, color: tar.innerHTML, colorName: this._colorData['#' + tar.innerHTML] } ); if (retVal !== false) { var info = { color: tar.innerHTML, colorName: this._colorData['#' + tar.innerHTML], value: this._colorPicker._button }; this.fireEvent('buttonClick', { type: 'buttonClick', target: this.get('element'), button: info }); } this.getButtonByValue(this._colorPicker._button).getMenu().hide(); } }, this, true); }, /** * @method _resetColorPicker * @private * @description Clears the currently selected color or mouseover color in the color picker. */ _resetColorPicker: function() { var em = this._colorPicker.getElementsByTagName('em')[0]; var strong = this._colorPicker.getElementsByTagName('strong')[0]; em.style.backgroundColor = 'transparent'; strong.innerHTML = ''; }, /** * @method _makeColorButton * @private * @description Called to turn a "color" button into a menu button with an Overlay for the menu. * @param {Object} _oButton <a href="YAHOO.widget.ToolbarButton.html">YAHOO.widget.ToolbarButton</a> reference */ _makeColorButton: function(_oButton) { if (!this._colorPicker) { this._createColorPicker(this.get('id')); } _oButton.type = 'color'; _oButton.menu = new YAHOO.widget.Overlay(this.get('id') + '_' + _oButton.value + '_menu', { visible: false, position: 'absolute', iframe: true }); _oButton.menu.setBody(''); _oButton.menu.render(this.get('cont')); Dom.addClass(_oButton.menu.element, 'yui-button-menu'); Dom.addClass(_oButton.menu.element, 'yui-color-button-menu'); _oButton.menu.beforeShowEvent.subscribe(function() { _oButton.menu.cfg.setProperty('zindex', 5); //Re Adjust the overlays zIndex.. not sure why. _oButton.menu.cfg.setProperty('context', [this.getButtonById(_oButton.id).get('element'), 'tl', 'bl']); //Re Adjust the overlay.. not sure why. //Move the DOM reference of the color picker to the Overlay that we are about to show. this._resetColorPicker(); var _p = this._colorPicker; if (_p.parentNode) { _p.parentNode.removeChild(_p); } _oButton.menu.setBody(''); _oButton.menu.appendToBody(_p); this._colorPicker.style.display = 'block'; }, this, true); return _oButton; }, /** * @private * @method _makeSpinButton * @description Create a button similar to an OS Spin button.. It has an up/down arrow combo to scroll through a range of int values. * @param {Object} _button <a href="YAHOO.widget.ToolbarButton.html">YAHOO.widget.ToolbarButton</a> reference * @param {Object} oButton Object literal containing the buttons initial config */ _makeSpinButton: function(_button, oButton) { _button.addClass(this.CLASS_PREFIX + '-spinbutton'); var self = this, _par = _button._button.parentNode.parentNode, //parentNode of Button Element for appending child range = oButton.range, _b1 = document.createElement('a'), _b2 = document.createElement('a'); _b1.href = '#'; _b2.href = '#'; _b1.tabIndex = '-1'; _b2.tabIndex = '-1'; //Setup the up and down arrows _b1.className = 'up'; _b1.title = this.STR_SPIN_UP; _b1.innerHTML = this.STR_SPIN_UP; _b2.className = 'down'; _b2.title = this.STR_SPIN_DOWN; _b2.innerHTML = this.STR_SPIN_DOWN; //Append them to the container _par.appendChild(_b1); _par.appendChild(_b2); var label = YAHOO.lang.substitute(this.STR_SPIN_LABEL, { VALUE: _button.get('label') }); _button.set('title', label); var cleanVal = function(value) { value = ((value < range[0]) ? range[0] : value); value = ((value > range[1]) ? range[1] : value); return value; }; var br = this.browser; var tbar = false; var strLabel = this.STR_SPIN_LABEL; if (this._titlebar && this._titlebar.firstChild) { tbar = this._titlebar.firstChild; } var _intUp = function(ev) { YAHOO.util.Event.stopEvent(ev); if (!_button.get('disabled') && (ev.keyCode != 9)) { var value = parseInt(_button.get('label'), 10); value++; value = cleanVal(value); _button.set('label', ''+value); var label = YAHOO.lang.substitute(strLabel, { VALUE: _button.get('label') }); _button.set('title', label); if (!br.webkit && tbar) { //tbar.focus(); //We do this for accessibility, on the re-focus of the element, a screen reader will re-read the title that was just changed //_button.focus(); } self._buttonClick(ev, oButton); } }; var _intDown = function(ev) { YAHOO.util.Event.stopEvent(ev); if (!_button.get('disabled') && (ev.keyCode != 9)) { var value = parseInt(_button.get('label'), 10); value--; value = cleanVal(value); _button.set('label', ''+value); var label = YAHOO.lang.substitute(strLabel, { VALUE: _button.get('label') }); _button.set('title', label); if (!br.webkit && tbar) { //tbar.focus(); //We do this for accessibility, on the re-focus of the eleme
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -