From af9c68a2c3634a115d0cb94c2698b39a6dcbb60a Mon Sep 17 00:00:00 2001 From: Matthew Borden Date: Tue, 8 Jul 2014 23:43:58 +1000 Subject: [PATCH] Working: Non solution to fuproblem --- ui/Squire-UI.js | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/ui/Squire-UI.js b/ui/Squire-UI.js index f6f7f53..01add0f 100644 --- a/ui/Squire-UI.js +++ b/ui/Squire-UI.js @@ -29,11 +29,17 @@ $(document).ready(function () { $(div).load(buildPath + 'Squire-UI.html', function() { $('.item').click(function() { - var me = $(this); - var iFrame = me.parents('.Squire-UI').next('iframe').first()[0]; - var editor = iFrame.contentWindow.editor; - console.log(SquireUI.isBold(editor)); - + var me = $(this); + var s = SquireUI; + var iFrame = me.parents('.Squire-UI').next('iframe').first()[0]; + var editor = iFrame.contentWindow.editor; + var test = (me.data('action') == ('bold' | 'italic' | 'underline' | 'link')); + + if (test && s.isBold(editor)) { editor.removeBold() }; + me.data('action') == 'italic' && s.isItalic(editor)) editor.removeItalic(); + me.data('action') == 'underline' && s.isUnderlined(editor)) editor.removeUnderline(); + me.data('action') == 'link' && s.isLink(editor)) editor.removeLink(); + editor[me.data('action')](me.data('value')); }); }); @@ -45,13 +51,13 @@ $(document).ready(function () { return iframe.contentWindow.editor; }; - SquireUI.isBold = function (editor) { return this.isPresent( 'B', ( />B\b/ ), editor ); }; - SquireUI.isItalic = function (editor) { return isPresent( 'I', ( />I\b/ ), editor ); }; - SquireUI.isUnderlined = function (editor) { return isPresent( 'U', ( />U\b/ ), editor); }; - SquireUI.isStriked = function (editor) { return isPresent( 'S', ( />S\b/ ), editor ); }; - SquireUI.isLink = function (editor) { return isPresent( 'A', ( />A\b/ ), editor ); }; - SquireUI.isPresent = function (format, validation, editor) { + SquireUI.isBold = function (editor) { return (this.isPresent( 'B', ( />B\b/ ), editor )); }; + SquireUI.isItalic = function (editor) { return (isPresent( 'I', ( />I\b/ ), editor )); }; + SquireUI.isUnderlined = function (editor) { return (isPresent( 'U', ( />U\b/ ), editor)); }; + SquireUI.isStriked = function (editor) { return (isPresent( 'S', ( />S\b/ ), editor )); }; + SquireUI.isLink = function (editor) { return (isPresent( 'A', ( />A\b/ ), editor )); }; + SquireUI.isPresent = function (format, validation, editor) { var path = editor.getPath(); - return validation.test(path); + return validation.test(path) | editor.hasFormat(format); }; }); \ No newline at end of file