JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.4b
[ckeditor.git] / _source / plugins / wysiwygarea / plugin.js
index deff975..7e7c192 100644 (file)
@@ -18,15 +18,26 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
 \r
        var notWhitespaceEval = CKEDITOR.dom.walker.whitespaces( true );\r
 \r
+       function checkReadOnly( selection )\r
+       {\r
+               if ( selection.getType() == CKEDITOR.SELECTION_ELEMENT )\r
+                       return selection.getSelectedElement().isReadOnly();\r
+               else\r
+                       return selection.getCommonAncestor().isReadOnly();\r
+       }\r
+\r
        function onInsertHtml( evt )\r
        {\r
                if ( this.mode == 'wysiwyg' )\r
                {\r
                        this.focus();\r
-                       this.fire( 'saveSnapshot' );\r
 \r
-                       var selection = this.getSelection(),\r
-                               data = evt.data;\r
+                       var selection = this.getSelection();\r
+                       if ( checkReadOnly( selection ) )\r
+                               return;\r
+\r
+                       var data = evt.data;\r
+                       this.fire( 'saveSnapshot' );\r
 \r
                        if ( this.dataProcessor )\r
                                data = this.dataProcessor.toHtml( data );\r
@@ -39,8 +50,29 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                        selection.unlock();\r
 \r
                                var $sel = selection.getNative();\r
+\r
+                               // Delete control selections to avoid IE bugs on pasteHTML.\r
                                if ( $sel.type == 'Control' )\r
                                        $sel.clear();\r
+                               else if  ( selection.getType() == CKEDITOR.SELECTION_TEXT )\r
+                               {\r
+                                       // Due to IE bugs on handling contenteditable=false blocks\r
+                                       // (#6005), we need to make some checks and eventually\r
+                                       // delete the selection first.\r
+\r
+                                       var range = selection.getRanges()[0],\r
+                                               endContainer = range && range.endContainer;\r
+\r
+                                       if ( endContainer &&\r
+                                                endContainer.type == CKEDITOR.NODE_ELEMENT &&\r
+                                                endContainer.getAttribute( 'contenteditable' ) == 'false' &&\r
+                                                range.checkBoundaryOfElement( endContainer, CKEDITOR.END ) )\r
+                                       {\r
+                                               range.setEndAfter( range.endContainer );\r
+                                               range.deleteContents();\r
+                                       }\r
+                               }\r
+\r
                                $sel.createRange().pasteHTML( data );\r
 \r
                                if ( selIsLocked )\r
@@ -70,15 +102,18 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                if ( this.mode == 'wysiwyg' )\r
                {\r
                        this.focus();\r
+\r
+                       var selection = this.getSelection();\r
+                       if ( checkReadOnly( selection ) )\r
+                               return;\r
+\r
                        this.fire( 'saveSnapshot' );\r
 \r
-                       var element = evt.data,\r
+                       var ranges = selection.getRanges(),\r
+                               element = evt.data,\r
                                elementName = element.getName(),\r
                                isBlock = CKEDITOR.dtd.$block[ elementName ];\r
 \r
-                       var selection = this.getSelection(),\r
-                               ranges = selection.getRanges();\r
-\r
                        var selIsLocked = selection.isLocked;\r
 \r
                        if ( selIsLocked )\r
@@ -377,6 +412,10 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                        ' allowTransparency="true"' +\r
                                                        '></iframe>' );\r
 \r
+                                               // #5689 Running inside of Firefox chrome the load event doesn't bubble like in a normal page\r
+                                               if (document.location.protocol == 'chrome:')\r
+                                                       CKEDITOR.event.useCapture = true;\r
+\r
                                                // With FF, it's better to load the data on iframe.load. (#3894,#4058)\r
                                                iframe.on( 'load', function( ev )\r
                                                        {\r
@@ -391,6 +430,10 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                                doc.close();\r
                                                        });\r
 \r
+                                               // #5689 Reset adjustment back to default\r
+                                               if (document.location.protocol == 'chrome:')\r
+                                                       CKEDITOR.event.useCapture = false;\r
+\r
                                                mainElement.append( iframe );\r
                                        };\r
 \r
@@ -493,6 +536,14 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                        } );\r
                                                }\r
 \r
+                                               // Prevent the browser opening links in read-only blocks. (#6032)\r
+                                               domDocument.on( 'click', function( ev )\r
+                                                       {\r
+                                                               ev = ev.data;\r
+                                                               if ( ev.getTarget().is( 'a' ) && ev.$.button != 2 )\r
+                                                                       ev.preventDefault();\r
+                                                       });\r
+\r
                                                // Webkit: avoid from editing form control elements content.\r
                                                if ( CKEDITOR.env.webkit )\r
                                                {\r
@@ -933,7 +984,13 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                if ( element.type == CKEDITOR.NODE_ELEMENT\r
                                                && ( element.is( 'input' ) || element.is( 'textarea' ) ) )\r
                                {\r
-                                       element.setAttribute( 'contentEditable', false );\r
+                                       if ( !element.isReadOnly() )\r
+                                       {\r
+                                               element.setAttribute( 'contentEditable', false );\r
+                                               // We should flag that the element was locked by our code so\r
+                                               // it'll be editable by the editor functions (#6046).\r
+                                               element.setCustomData( '_cke_notReadOnly', 1 );\r
+                                       }\r
                                }\r
                        });\r
 \r