JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.6.3
[ckeditor.git] / _source / plugins / justify / plugin.js
index 82c1fcc..1b3aaa5 100644 (file)
@@ -1,5 +1,5 @@
 /*\r
-Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.\r
+Copyright (c) 2003-2012, CKSource - Frederico Knabben. All rights reserved.\r
 For licensing, see LICENSE.html or http://ckeditor.com/license\r
 */\r
 \r
@@ -9,18 +9,6 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
 \r
 (function()\r
 {\r
-       function getState( editor, path )\r
-       {\r
-               var firstBlock = path.block || path.blockLimit;\r
-\r
-               if ( !firstBlock || firstBlock.getName() == 'body' )\r
-                       return CKEDITOR.TRISTATE_OFF;\r
-\r
-               return ( getAlignment( firstBlock, editor.config.useComputedState ) == this.value ) ?\r
-                       CKEDITOR.TRISTATE_ON :\r
-                       CKEDITOR.TRISTATE_OFF;\r
-       }\r
-\r
        function getAlignment( element, useComputedState )\r
        {\r
                useComputedState = useComputedState === undefined || useComputedState;\r
@@ -40,7 +28,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                        align = element.getStyle( 'text-align' ) || element.getAttribute( 'align' ) || '';\r
                }\r
 \r
-               align && ( align = align.replace( /-moz-|-webkit-|start|auto/i, '' ) );\r
+               // Sometimes computed values doesn't tell.\r
+               align && ( align = align.replace( /(?:-(?:moz|webkit)-)?(?:start|auto)/i, '' ) );\r
 \r
                !align && useComputedState && ( align = element.getComputedStyle( 'direction' ) == 'rtl' ? 'right' : 'left' );\r
 \r
@@ -52,13 +41,12 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                if ( evt.editor.readOnly )\r
                        return;\r
 \r
-               var command = evt.editor.getCommand( this.name );\r
-               command.state = getState.call( this, evt.editor, evt.data.path );\r
-               command.fire( 'state' );\r
+               evt.editor.getCommand( this.name ).refresh( evt.data.path );\r
        }\r
 \r
        function justifyCommand( editor, name, value )\r
        {\r
+               this.editor = editor;\r
                this.name = name;\r
                this.value = value;\r
 \r
@@ -192,6 +180,16 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                        editor.focus();\r
                        editor.forceNextSelectionCheck();\r
                        selection.selectBookmarks( bookmarks );\r
+               },\r
+\r
+               refresh : function( path )\r
+               {\r
+                       var firstBlock = path.block || path.blockLimit;\r
+\r
+                       this.setState( firstBlock.getName() != 'body' &&\r
+                               getAlignment( firstBlock, this.editor.config.useComputedState ) == this.value ?\r
+                               CKEDITOR.TRISTATE_ON :\r
+                               CKEDITOR.TRISTATE_OFF );\r
                }\r
        };\r
 \r