Permalink
Browse files

Remove useless 'state' function from commands

  • Loading branch information...
1 parent 94ef126 commit 2c6dc01865c0b051e60b0565a8f2de6baa41d1c2 @tiff tiff committed Jul 16, 2012
View
@@ -78,28 +78,5 @@ wysihtml5.Commands = Base.extend(
return false;
}
}
- },
-
- /**
- * Get the current command's value
- *
- * @param {String} command The command string which to check (eg. "formatBlock")
- * @return {String} The command value
- * @example
- * var currentBlockElement = commands.value("formatBlock");
- */
- value: function(command) {
- var obj = wysihtml5.commands[command],
- method = obj && obj.value;
- if (method) {
- return method.call(obj, this.composer, command);
- } else {
- try {
- // try/catch for buggy firefox
- return this.doc.queryCommandValue(command);
- } catch(e) {
- return null;
- }
- }
}
});
View
@@ -1,23 +1,15 @@
-(function(wysihtml5) {
- var undef;
-
- wysihtml5.commands.bold = {
- exec: function(composer, command) {
- return wysihtml5.commands.formatInline.exec(composer, command, "b");
- },
+wysihtml5.commands.bold = {
+ exec: function(composer, command) {
+ return wysihtml5.commands.formatInline.exec(composer, command, "b");
+ },
- state: function(composer, command) {
- // element.ownerDocument.queryCommandState("bold") results:
- // firefox: only <b>
- // chrome: <b>, <strong>, <h1>, <h2>, ...
- // ie: <b>, <strong>
- // opera: <b>, <strong>
- return wysihtml5.commands.formatInline.state(composer, command, "b");
- },
-
- value: function() {
- return undef;
- }
- };
-})(wysihtml5);
+ state: function(composer, command) {
+ // element.ownerDocument.queryCommandState("bold") results:
+ // firefox: only <b>
+ // chrome: <b>, <strong>, <h1>, <h2>, ...
+ // ie: <b>, <strong>
+ // opera: <b>, <strong>
+ return wysihtml5.commands.formatInline.state(composer, command, "b");
+ }
+};
@@ -96,10 +96,6 @@
state: function(composer, command) {
return wysihtml5.commands.formatInline.state(composer, command, "A");
- },
-
- value: function() {
- return undef;
}
};
})(wysihtml5);
@@ -4,8 +4,7 @@
* Instead we set a css class
*/
(function(wysihtml5) {
- var undef,
- REG_EXP = /wysiwyg-color-[0-9a-z]+/g;
+ var REG_EXP = /wysiwyg-color-[0-9a-z]+/g;
wysihtml5.commands.foreColor = {
exec: function(composer, command, color) {
@@ -14,10 +13,6 @@
state: function(composer, command, color) {
return wysihtml5.commands.formatInline.state(composer, command, "span", "wysiwyg-color-" + color, REG_EXP);
- },
-
- value: function() {
- return undef;
}
};
})(wysihtml5);
@@ -1,6 +1,5 @@
(function(wysihtml5) {
- var undef,
- dom = wysihtml5.dom,
+ var dom = wysihtml5.dom,
DEFAULT_NODE_NAME = "DIV",
// Following elements are grouped
// when the caret is within a H1 and the H4 is invoked, the H1 should turn into H4
@@ -217,10 +216,6 @@
className: className,
classRegExp: classRegExp
});
- },
-
- value: function() {
- return undef;
}
};
})(wysihtml5);
@@ -32,8 +32,7 @@
* <span>ab|c</span> de|<b>fgh</b>
*/
(function(wysihtml5) {
- var undef,
- // Treat <b> as <strong> and vice versa
+ var // Treat <b> as <strong> and vice versa
ALIAS_MAPPING = {
"strong": "b",
"em": "i",
@@ -87,10 +86,6 @@
}
return _getApplier(tagName, className, classRegExp).isAppliedToRange(range);
- },
-
- value: function() {
- return undef;
}
};
})(wysihtml5);
View
@@ -1,21 +1,13 @@
-(function(wysihtml5) {
- var undef;
-
- wysihtml5.commands.insertHTML = {
- exec: function(composer, command, html) {
- if (composer.commands.support(command)) {
- composer.doc.execCommand(command, false, html);
- } else {
- composer.selection.insertHTML(html);
- }
- },
-
- state: function() {
- return false;
- },
-
- value: function() {
- return undef;
+wysihtml5.commands.insertHTML = {
+ exec: function(composer, command, html) {
+ if (composer.commands.support(command)) {
+ composer.doc.execCommand(command, false, html);
+ } else {
+ composer.selection.insertHTML(html);
}
- };
-})(wysihtml5);
+ },
+
+ state: function() {
+ return false;
+ }
+};
@@ -97,11 +97,6 @@
}
return imagesInSelection[0];
- },
-
- value: function(composer) {
- var image = this.state(composer);
- return image && image.src;
}
};
})(wysihtml5);
@@ -1,6 +1,5 @@
(function(wysihtml5) {
- var undef,
- LINE_BREAK = "<br>" + (wysihtml5.browser.needsSpaceAfterLineBreak() ? " " : "");
+ var LINE_BREAK = "<br>" + (wysihtml5.browser.needsSpaceAfterLineBreak() ? " " : "");
wysihtml5.commands.insertLineBreak = {
exec: function(composer, command) {
@@ -16,10 +15,6 @@
state: function() {
return false;
- },
-
- value: function() {
- return undef;
}
};
})(wysihtml5);
@@ -1,58 +1,50 @@
-(function(wysihtml5) {
- var undef;
-
- wysihtml5.commands.insertOrderedList = {
- exec: function(composer, command) {
- var doc = composer.doc,
- selectedNode = composer.selection.getSelectedNode(),
- list = wysihtml5.dom.getParentElement(selectedNode, { nodeName: "OL" }),
- otherList = wysihtml5.dom.getParentElement(selectedNode, { nodeName: "UL" }),
- tempClassName = "_wysihtml5-temp-" + new Date().getTime(),
- isEmpty,
- tempElement;
-
- if (composer.commands.support(command)) {
- doc.execCommand(command, false, null);
- return;
- }
-
- if (list) {
- // Unwrap list
- // <ol><li>foo</li><li>bar</li></ol>
- // becomes:
- // foo<br>bar<br>
- composer.selection.executeAndRestoreSimple(function() {
- wysihtml5.dom.resolveList(list);
- });
- } else if (otherList) {
- // Turn an unordered list into an ordered list
- // <ul><li>foo</li><li>bar</li></ul>
- // becomes:
- // <ol><li>foo</li><li>bar</li></ol>
- composer.selection.executeAndRestoreSimple(function() {
- wysihtml5.dom.renameElement(otherList, "ol");
- });
- } else {
- // Create list
- composer.commands.exec("formatBlock", "div", tempClassName);
- tempElement = doc.querySelector("." + tempClassName);
- isEmpty = tempElement.innerHTML === "" || tempElement.innerHTML === wysihtml5.INVISIBLE_SPACE;
- composer.selection.executeAndRestoreSimple(function() {
- list = wysihtml5.dom.convertToList(tempElement, "ol");
- });
- if (isEmpty) {
- composer.selection.selectNode(list.querySelector("li"));
- }
- }
- },
+wysihtml5.commands.insertOrderedList = {
+ exec: function(composer, command) {
+ var doc = composer.doc,
+ selectedNode = composer.selection.getSelectedNode(),
+ list = wysihtml5.dom.getParentElement(selectedNode, { nodeName: "OL" }),
+ otherList = wysihtml5.dom.getParentElement(selectedNode, { nodeName: "UL" }),
+ tempClassName = "_wysihtml5-temp-" + new Date().getTime(),
+ isEmpty,
+ tempElement;
- state: function(composer) {
- var selectedNode = composer.selection.getSelectedNode();
- return wysihtml5.dom.getParentElement(selectedNode, { nodeName: "OL" });
- },
-
- value: function() {
- return undef;
+ if (composer.commands.support(command)) {
+ doc.execCommand(command, false, null);
+ return;
}
- };
-})(wysihtml5);
+
+ if (list) {
+ // Unwrap list
+ // <ol><li>foo</li><li>bar</li></ol>
+ // becomes:
+ // foo<br>bar<br>
+ composer.selection.executeAndRestoreSimple(function() {
+ wysihtml5.dom.resolveList(list);
+ });
+ } else if (otherList) {
+ // Turn an unordered list into an ordered list
+ // <ul><li>foo</li><li>bar</li></ul>
+ // becomes:
+ // <ol><li>foo</li><li>bar</li></ol>
+ composer.selection.executeAndRestoreSimple(function() {
+ wysihtml5.dom.renameElement(otherList, "ol");
+ });
+ } else {
+ // Create list
+ composer.commands.exec("formatBlock", "div", tempClassName);
+ tempElement = doc.querySelector("." + tempClassName);
+ isEmpty = tempElement.innerHTML === "" || tempElement.innerHTML === wysihtml5.INVISIBLE_SPACE;
+ composer.selection.executeAndRestoreSimple(function() {
+ list = wysihtml5.dom.convertToList(tempElement, "ol");
+ });
+ if (isEmpty) {
+ composer.selection.selectNode(list.querySelector("li"));
+ }
+ }
+ },
+
+ state: function(composer) {
+ var selectedNode = composer.selection.getSelectedNode();
+ return wysihtml5.dom.getParentElement(selectedNode, { nodeName: "OL" });
+ }
+};
Oops, something went wrong.

0 comments on commit 2c6dc01

Please sign in to comment.