generators/wysihat/templates/javascripts/wysihat.js in wysihat-engine-0.1.9 vs generators/wysihat/templates/javascripts/wysihat.js in wysihat-engine-0.1.10

- old
+ new

@@ -86,46 +86,26 @@ function fontSelection(font) { this.execCommand('fontname', false, font); } - function fontSelected() { - var node = this.selection.getNode(); - return Element.getStyle(node, 'fontFamily'); - } - function fontSizeSelection(fontSize) { this.execCommand('fontsize', false, fontSize); } - function fontSizeSelected() { - var node = this.selection.getNode(); - return standardizeFontSize(Element.getStyle(node, 'fontSize')); - } - function colorSelection(color) { this.execCommand('forecolor', false, color); } - function colorSelected() { - var node = this.selection.getNode(); - return standardizeColor(Element.getStyle(node, 'color')); - } - function backgroundColorSelection(color) { if(Prototype.Browser.Gecko) { this.execCommand('hilitecolor', false, color); } else { this.execCommand('backcolor', false, color); } } - function backgroundColorSelected() { - var node = this.selection.getNode(); - return standardizeColor(Element.getStyle(node, 'backgroundColor')); - } - function alignSelection(alignment) { this.execCommand('justify' + alignment); } function alignSelected() { @@ -148,10 +128,14 @@ function linkSelected() { var node = this.selection.getNode(); return node ? node.tagName.toUpperCase() == 'A' : false; } + function formatblockSelection(element){ + this.execCommand('formatblock', false, element); + } + function insertOrderedList() { this.execCommand('insertorderedlist', false, null); } function insertUnorderedList() { @@ -176,125 +160,76 @@ function execCommand(command, ui, value) { var document = this.getDocument(); if (Prototype.Browser.IE) this.selection.restore(); - var handler = this.commands.get(command) + var handler = this.commands.get(command); if (handler) handler.bind(this)(value); else document.execCommand(command, ui, value); } function queryCommandState(state) { var document = this.getDocument(); - var handler = this.queryCommands.get(state) + var handler = this.queryCommands.get(state); if (handler) return handler.bind(this)(); else return document.queryCommandState(state); } - var fontSizeNames = $w('xxx-small xx-small x-small small medium large x-large xx-large'); - var fontSizePixels = $w('9px 10px 13px 16px 18px 24px 32px 48px'); - if (Prototype.Browser.WebKit) { - fontSizeNames.shift(); - fontSizeNames.push('-webkit-xxx-large'); - } + function getSelectedStyles() { + var styles = $H({}); + var editor = this; + editor.styleSelectors.each(function(style){ + var node = editor.selection.getNode(); + styles.set(style.first(), Element.getStyle(node, style.last())); + }); + return styles; + } - function standardizeFontSize(fontSize) { - var newSize = fontSizeNames.indexOf(fontSize); - if (newSize >= 0) return newSize; - - newSize = fontSizePixels.indexOf(fontSize); - if (newSize >= 0) return newSize; - return parseInt(fontSize); - } - - function standardizeColor(color) { - if (!color || color.match(/[0-9a-f]{6}/i)) return color; - var m = color.toLowerCase().match(/^(rgba?|hsla?)\(([\s\.\-,%0-9]+)\)/); - if(m){ - var c = m[2].split(/\s*,\s*/), l = c.length, t = m[1]; - if((t == "rgb" && l == 3) || (t == "rgba" && l == 4)){ - var r = c[0]; - if(r.charAt(r.length - 1) == "%"){ - var a = c.map(function(x){ - return parseFloat(x) * 2.56; - }); - if(l == 4){ a[3] = c[3]; } - return _colorFromArray(a); - } - return _colorFromArray(c); - } - if((t == "hsl" && l == 3) || (t == "hsla" && l == 4)){ - var H = ((parseFloat(c[0]) % 360) + 360) % 360 / 360, - S = parseFloat(c[1]) / 100, - L = parseFloat(c[2]) / 100, - m2 = L <= 0.5 ? L * (S + 1) : L + S - L * S, - m1 = 2 * L - m2, - a = [_hue2rgb(m1, m2, H + 1 / 3) * 256, - _hue2rgb(m1, m2, H) * 256, _hue2rgb(m1, m2, H - 1 / 3) * 256, 1]; - if(l == 4){ a[3] = c[3]; } - return _colorFromArray(a); - } - } - return null; // dojo.Color - } - - function _colorFromArray(a) { - var arr = a.slice(0, 3).map(function(x){ - var s = parseInt(x).toString(16); - return s.length < 2 ? "0" + s : s; - }); - return "#" + arr.join(""); // String - } - - function _hue2rgb(m1, m2, h){ - if(h < 0){ ++h; } - if(h > 1){ --h; } - var h6 = 6 * h; - if(h6 < 1){ return m1 + (m2 - m1) * h6; } - if(2 * h < 1){ return m2; } - if(3 * h < 2){ return m1 + (m2 - m1) * (2 / 3 - h) * 6; } - return m1; - } - return { boldSelection: boldSelection, boldSelected: boldSelected, underlineSelection: underlineSelection, underlineSelected: underlineSelected, italicSelection: italicSelection, italicSelected: italicSelected, strikethroughSelection: strikethroughSelection, blockquoteSelection: blockquoteSelection, fontSelection: fontSelection, - fontSelected: fontSelected, fontSizeSelection: fontSizeSelection, - fontSizeSelected: fontSizeSelected, colorSelection: colorSelection, - colorSelected: colorSelected, backgroundColorSelection: backgroundColorSelection, - backgroundColorSelected: backgroundColorSelected, alignSelection: alignSelection, alignSelected: alignSelected, linkSelection: linkSelection, unlinkSelection: unlinkSelection, linkSelected: linkSelected, + formatblockSelection: formatblockSelection, insertOrderedList: insertOrderedList, insertUnorderedList: insertUnorderedList, insertImage: insertImage, insertHTML: insertHTML, execCommand: execCommand, queryCommandState: queryCommandState, + getSelectedStyles: getSelectedStyles, commands: $H({}), queryCommands: $H({ link: linkSelected + }), + + styleSelectors: $H({ + fontname: 'fontFamily', + fontsize: 'fontSize', + forecolor: 'color', + hilitecolor: 'backgroundColor', + backcolor: 'backgroundColor' }) }; })(); WysiHat.Editor.include(WysiHat.Commands); @@ -862,11 +797,11 @@ this.START_TO_START = 0; this.START_TO_END = 1; this.END_TO_END = 2; this.END_TO_START = 3; - } + }; Range.CLONE_CONTENTS = 0; Range.DELETE_CONTENTS = 1; Range.EXTRACT_CONTENTS = 2; @@ -1517,11 +1452,11 @@ this.focusNode = null; this.focusOffset = 0; this.isCollapsed = true; this.rangeCount = 0; this.ranges = []; - } + }; Object.extend(SelectionImpl.prototype, (function() { function addRange(r) { return true; } @@ -1986,10 +1921,10 @@ var handler = this.buttonHandler(name, options); this.observeButtonClick(button, handler); var handler = this.buttonStateHandler(name, options); - this.observeStateChanges(button, name, handler) + this.observeStateChanges(button, name, handler); } function createButtonElement(toolbar, options) { var button = new Element('a', { 'class': 'button', 'href': '#'