📄 simpleeditor.js
字号:
} else { this.get('cont').appendChild(this._dragHandle); } /** * @property dd * @description The DragDrop instance associated with the Toolbar * @type Object */ this.dd = new YAHOO.util.DD(this.get('id')); this.dd.setHandleElId(this._dragHandle.id); } } else { if (this._dragHandle) { this._dragHandle.parentNode.removeChild(this._dragHandle); this._dragHandle = null; this.dd = null; } } if (this._titlebar) { if (draggable) { this.dd = new YAHOO.util.DD(this.get('id')); this.dd.setHandleElId(this._titlebar); Dom.addClass(this._titlebar, 'draggable'); } else { Dom.removeClass(this._titlebar, 'draggable'); if (this.dd) { this.dd.unreg(); this.dd = null; } } } }, validator: function(value) { var ret = true; if (!YAHOO.util.DD) { ret = false; } return ret; } }); }, /** * @method addButtonGroup * @description Add a new button group to the toolbar. (uses addButton) * @param {Object} oGroup Object literal reference to the Groups Config (contains an array of button configs as well as the group label) */ addButtonGroup: function(oGroup) { if (!this.get('element')) { this._queue[this._queue.length] = ['addButtonGroup', arguments]; return false; } if (!this.hasClass(this.CLASS_PREFIX + '-grouped')) { this.addClass(this.CLASS_PREFIX + '-grouped'); } var div = document.createElement('DIV'); Dom.addClass(div, this.CLASS_PREFIX + '-group'); Dom.addClass(div, this.CLASS_PREFIX + '-group-' + oGroup.group); if (oGroup.label) { var label = document.createElement('h3'); label.innerHTML = oGroup.label; div.appendChild(label); } if (!this.get('grouplabels')) { Dom.addClass(this.get('cont'), this.CLASS_PREFIX, '-nogrouplabels'); } this.get('cont').appendChild(div); //For accessibility, let's put all of the group buttons in an Unordered List var ul = document.createElement('ul'); div.appendChild(ul); if (!this._buttonGroupList) { this._buttonGroupList = {}; } this._buttonGroupList[oGroup.group] = ul; for (var i = 0; i < oGroup.buttons.length; i++) { var li = document.createElement('li'); li.className = this.CLASS_PREFIX + '-groupitem'; ul.appendChild(li); if ((oGroup.buttons[i].type !== undefined) && oGroup.buttons[i].type == 'separator') { this.addSeparator(li); } else { oGroup.buttons[i].container = li; this.addButton(oGroup.buttons[i]); } } }, /** * @method addButtonToGroup * @description Add a new button to a toolbar group. Buttons supported: * push, split, menu, select, color, spin * @param {Object} oButton Object literal reference to the Button's Config * @param {String} group The Group identifier passed into the initial config * @param {HTMLElement} after Optional HTML element to insert this button after in the DOM. */ addButtonToGroup: function(oButton, group, after) { var groupCont = this._buttonGroupList[group]; var li = document.createElement('li'); li.className = this.CLASS_PREFIX + '-groupitem'; oButton.container = li; this.addButton(oButton, after); groupCont.appendChild(li); }, /** * @method addButton * @description Add a new button to the toolbar. Buttons supported: * push, split, menu, select, color, spin * @param {Object} oButton Object literal reference to the Button's Config * @param {HTMLElement} after Optional HTML element to insert this button after in the DOM. */ addButton: function(oButton, after) { if (!this.get('element')) { this._queue[this._queue.length] = ['addButton', arguments]; return false; } if (!this._buttonList) { this._buttonList = []; } if (!oButton.container) { oButton.container = this.get('cont'); } if ((oButton.type == 'menu') || (oButton.type == 'split') || (oButton.type == 'select')) { if (Lang.isArray(oButton.menu)) { for (var i in oButton.menu) { if (Lang.hasOwnProperty(oButton.menu, i)) { var funcObject = { fn: function(ev, x, oMenu) { if (!oButton.menucmd) { oButton.menucmd = oButton.value; } oButton.value = ((oMenu.value) ? oMenu.value : oMenu._oText.nodeValue); }, scope: this }; oButton.menu[i].onclick = funcObject; } } } } var _oButton = {}, skip = false; for (var o in oButton) { if (Lang.hasOwnProperty(oButton, o)) { if (!this._toolbarConfigs[o]) { _oButton[o] = oButton[o]; } } } if (oButton.type == 'select') { _oButton.type = 'menu'; } if (oButton.type == 'spin') { _oButton.type = 'push'; } if (_oButton.type == 'color') { if (YAHOO.widget.Overlay) { _oButton = this._makeColorButton(_oButton); } else { skip = true; } } if (_oButton.menu) { if ((YAHOO.widget.Overlay) && (oButton.menu instanceof YAHOO.widget.Overlay)) { oButton.menu.showEvent.subscribe(function() { this._button = _oButton; }); } else { for (var m = 0; m < _oButton.menu.length; m++) { if (!_oButton.menu[m].value) { _oButton.menu[m].value = _oButton.menu[m].text; } } if (this.browser.webkit) { _oButton.focusmenu = false; } } } if (skip) { oButton = false; } else { //Add to .get('buttons') manually this._configs.buttons.value[this._configs.buttons.value.length] = oButton; var tmp = new this.buttonType(_oButton); tmp.get('element').tabIndex = '-1'; tmp.get('element').setAttribute('role', 'button'); tmp._selected = true; if (this.get('disabled')) { //Toolbar is disabled, disable the new button too! tmp.set('disabled', true); } if (!oButton.id) { oButton.id = tmp.get('id'); } if (after) { var el = tmp.get('element'); var nextSib = null; if (after.get) { nextSib = after.get('element').nextSibling; } else if (after.nextSibling) { nextSib = after.nextSibling; } if (nextSib) { nextSib.parentNode.insertBefore(el, nextSib); } } tmp.addClass(this.CLASS_PREFIX + '-' + tmp.get('value')); var icon = document.createElement('span'); icon.className = this.CLASS_PREFIX + '-icon'; tmp.get('element').insertBefore(icon, tmp.get('firstChild')); if (tmp._button.tagName.toLowerCase() == 'button') { tmp.get('element').setAttribute('unselectable', 'on'); //Replace the Button HTML Element with an a href if it exists var a = document.createElement('a'); a.innerHTML = tmp._button.innerHTML; a.href = '#'; a.tabIndex = '-1'; Event.on(a, 'click', function(ev) { Event.stopEvent(ev); }); tmp._button.parentNode.replaceChild(a, tmp._button); tmp._button = a; } if (oButton.type == 'select') { if (tmp._button.tagName.toLowerCase() == 'select') { icon.parentNode.removeChild(icon); var iel = tmp._button; var parEl = tmp.get('element'); parEl.parentNode.replaceChild(iel, parEl); } else { //Don't put a class on it if it's a real select element tmp.addClass(this.CLASS_PREFIX + '-select'); } } if (oButton.type == 'spin') { if (!Lang.isArray(oButton.range)) { oButton.range = [ 10, 100 ]; } this._makeSpinButton(tmp, oButton); } tmp.get('element').setAttribute('title', tmp.get('label')); if (oButton.type != 'spin') { if ((YAHOO.widget.Overlay) && (_oButton.menu instanceof YAHOO.widget.Overlay)) { var showPicker = function(ev) { var exec = true; if (ev.keyCode && (ev.keyCode == 9)) { exec = false; } if (exec) { if (this._colorPicker) { this._colorPicker._button = oButton.value; } var menuEL = tmp.getMenu().element; if (Dom.getStyle(menuEL, 'visibility') == 'hidden') { tmp.getMenu().show(); } else { tmp.getMenu().hide(); } } YAHOO.util.Event.stopEvent(ev); }; tmp.on('mousedown', showPicker, oButton, this); tmp.on('keydown', showPicker, oButton, this); } else if ((oButton.type != 'menu') && (oButton.type != 'select')) { tmp.on('keypress', this._buttonClick, oButton, this); tmp.on('mousedown', function(ev) { YAHOO.util.Event.stopEvent(ev); this._buttonClick(ev, oButton); }, oButton, this); tmp.on('click', function(ev) { YAHOO.util.Event.stopEvent(ev); }); } 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); }); tmp.on('change', function(ev) { if (!oButton.menucmd) { oButton.menucmd = oButton.value; } 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) { 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.util.Event.stopEvent(args[0]); }); tmp.getMenu().mouseUpEvent.subscribe(function(ev, args) { YAHOO.util.Event.stopEvent(args[0]); }); } }); } } else {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -