import rt 3.8.7
[freeside.git] / rt / share / html / NoAuth / RichText / FCKeditor / editor / dialog / common / fck_dialog_common.js
diff --git a/rt/share/html/NoAuth/RichText/FCKeditor/editor/dialog/common/fck_dialog_common.js b/rt/share/html/NoAuth/RichText/FCKeditor/editor/dialog/common/fck_dialog_common.js
new file mode 100644 (file)
index 0000000..5536a83
--- /dev/null
@@ -0,0 +1,347 @@
+/*\r
+ * FCKeditor - The text editor for Internet - http://www.fckeditor.net\r
+ * Copyright (C) 2003-2009 Frederico Caldeira Knabben\r
+ *\r
+ * == BEGIN LICENSE ==\r
+ *\r
+ * Licensed under the terms of any of the following licenses at your\r
+ * choice:\r
+ *\r
+ *  - GNU General Public License Version 2 or later (the "GPL")\r
+ *    http://www.gnu.org/licenses/gpl.html\r
+ *\r
+ *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")\r
+ *    http://www.gnu.org/licenses/lgpl.html\r
+ *\r
+ *  - Mozilla Public License Version 1.1 or later (the "MPL")\r
+ *    http://www.mozilla.org/MPL/MPL-1.1.html\r
+ *\r
+ * == END LICENSE ==\r
+ *\r
+ * Useful functions used by almost all dialog window pages.\r
+ * Dialogs should link to this file as the very first script on the page.\r
+ */\r
+\r
+// Automatically detect the correct document.domain (#123).\r
+(function()\r
+{\r
+       var d = document.domain ;\r
+\r
+       while ( true )\r
+       {\r
+               // Test if we can access a parent property.\r
+               try\r
+               {\r
+                       var test = window.parent.document.domain ;\r
+                       break ;\r
+               }\r
+               catch( e ) {}\r
+\r
+               // Remove a domain part: www.mytest.example.com => mytest.example.com => example.com ...\r
+               d = d.replace( /.*?(?:\.|$)/, '' ) ;\r
+\r
+               if ( d.length == 0 )\r
+                       break ;         // It was not able to detect the domain.\r
+\r
+               try\r
+               {\r
+                       document.domain = d ;\r
+               }\r
+               catch (e)\r
+               {\r
+                       break ;\r
+               }\r
+       }\r
+})() ;\r
+\r
+// Attention: FCKConfig must be available in the page.\r
+function GetCommonDialogCss( prefix )\r
+{\r
+       // CSS minified by http://iceyboard.no-ip.org/projects/css_compressor (see _dev/css_compression.txt).\r
+       return FCKConfig.BasePath + 'dialog/common/' + '|.ImagePreviewArea{border:#000 1px solid;overflow:auto;width:100%;height:170px;background-color:#fff}.FlashPreviewArea{border:#000 1px solid;padding:5px;overflow:auto;width:100%;height:170px;background-color:#fff}.BtnReset{float:left;background-position:center center;background-image:url(images/reset.gif);width:16px;height:16px;background-repeat:no-repeat;border:1px none;font-size:1px}.BtnLocked,.BtnUnlocked{float:left;background-position:center center;background-image:url(images/locked.gif);width:16px;height:16px;background-repeat:no-repeat;border:none 1px;font-size:1px}.BtnUnlocked{background-image:url(images/unlocked.gif)}.BtnOver{border:outset 1px;cursor:pointer;cursor:hand}' ;\r
+}\r
+\r
+// Gets a element by its Id. Used for shorter coding.\r
+function GetE( elementId )\r
+{\r
+       return document.getElementById( elementId )  ;\r
+}\r
+\r
+function ShowE( element, isVisible )\r
+{\r
+       if ( typeof( element ) == 'string' )\r
+               element = GetE( element ) ;\r
+       element.style.display = isVisible ? '' : 'none' ;\r
+}\r
+\r
+function SetAttribute( element, attName, attValue )\r
+{\r
+       if ( attValue == null || attValue.length == 0 )\r
+               element.removeAttribute( attName, 0 ) ;                 // 0 : Case Insensitive\r
+       else\r
+               element.setAttribute( attName, attValue, 0 ) ;  // 0 : Case Insensitive\r
+}\r
+\r
+function GetAttribute( element, attName, valueIfNull )\r
+{\r
+       var oAtt = element.attributes[attName] ;\r
+\r
+       if ( oAtt == null || !oAtt.specified )\r
+               return valueIfNull ? valueIfNull : '' ;\r
+\r
+       var oValue = element.getAttribute( attName, 2 ) ;\r
+\r
+       if ( oValue == null )\r
+               oValue = oAtt.nodeValue ;\r
+\r
+       return ( oValue == null ? valueIfNull : oValue ) ;\r
+}\r
+\r
+function SelectField( elementId )\r
+{\r
+       var element = GetE( elementId ) ;\r
+       element.focus() ;\r
+\r
+       // element.select may not be available for some fields (like <select>).\r
+       if ( element.select )\r
+               element.select() ;\r
+}\r
+\r
+// Functions used by text fields to accept numbers only.\r
+var IsDigit = ( function()\r
+       {\r
+               var KeyIdentifierMap =\r
+               {\r
+                       End                     : 35,\r
+                       Home            : 36,\r
+                       Left            : 37,\r
+                       Right           : 39,\r
+                       'U+00007F'      : 46            // Delete\r
+               } ;\r
+\r
+               return function ( e )\r
+                       {\r
+                               if ( !e )\r
+                                       e = event ;\r
+\r
+                               var iCode = ( e.keyCode || e.charCode ) ;\r
+\r
+                               if ( !iCode && e.keyIdentifier && ( e.keyIdentifier in KeyIdentifierMap ) )\r
+                                               iCode = KeyIdentifierMap[ e.keyIdentifier ] ;\r
+\r
+                               return (\r
+                                               ( iCode >= 48 && iCode <= 57 )          // Numbers\r
+                                               || (iCode >= 35 && iCode <= 40)         // Arrows, Home, End\r
+                                               || iCode == 8                                           // Backspace\r
+                                               || iCode == 46                                          // Delete\r
+                                               || iCode == 9                                           // Tab\r
+                               ) ;\r
+                       }\r
+       } )() ;\r
+\r
+String.prototype.Trim = function()\r
+{\r
+       return this.replace( /(^\s*)|(\s*$)/g, '' ) ;\r
+}\r
+\r
+String.prototype.StartsWith = function( value )\r
+{\r
+       return ( this.substr( 0, value.length ) == value ) ;\r
+}\r
+\r
+String.prototype.Remove = function( start, length )\r
+{\r
+       var s = '' ;\r
+\r
+       if ( start > 0 )\r
+               s = this.substring( 0, start ) ;\r
+\r
+       if ( start + length < this.length )\r
+               s += this.substring( start + length , this.length ) ;\r
+\r
+       return s ;\r
+}\r
+\r
+String.prototype.ReplaceAll = function( searchArray, replaceArray )\r
+{\r
+       var replaced = this ;\r
+\r
+       for ( var i = 0 ; i < searchArray.length ; i++ )\r
+       {\r
+               replaced = replaced.replace( searchArray[i], replaceArray[i] ) ;\r
+       }\r
+\r
+       return replaced ;\r
+}\r
+\r
+function OpenFileBrowser( url, width, height )\r
+{\r
+       // oEditor must be defined.\r
+\r
+       var iLeft = ( oEditor.FCKConfig.ScreenWidth  - width ) / 2 ;\r
+       var iTop  = ( oEditor.FCKConfig.ScreenHeight - height ) / 2 ;\r
+\r
+       var sOptions = "toolbar=no,status=no,resizable=yes,dependent=yes,scrollbars=yes" ;\r
+       sOptions += ",width=" + width ;\r
+       sOptions += ",height=" + height ;\r
+       sOptions += ",left=" + iLeft ;\r
+       sOptions += ",top=" + iTop ;\r
+\r
+       window.open( url, 'FCKBrowseWindow', sOptions ) ;\r
+}\r
+\r
+/**\r
+ Utility function to create/update an element with a name attribute in IE, so it behaves properly when moved around\r
+ It also allows to change the name or other special attributes in an existing node\r
+       oEditor : instance of FCKeditor where the element will be created\r
+       oOriginal : current element being edited or null if it has to be created\r
+       nodeName : string with the name of the element to create\r
+       oAttributes : Hash object with the attributes that must be set at creation time in IE\r
+                                                               Those attributes will be set also after the element has been\r
+                                                               created for any other browser to avoid redudant code\r
+*/\r
+function CreateNamedElement( oEditor, oOriginal, nodeName, oAttributes )\r
+{\r
+       var oNewNode ;\r
+\r
+       // IE doesn't allow easily to change properties of an existing object,\r
+       // so remove the old and force the creation of a new one.\r
+       var oldNode = null ;\r
+       if ( oOriginal && oEditor.FCKBrowserInfo.IsIE )\r
+       {\r
+               // Force the creation only if some of the special attributes have changed:\r
+               var bChanged = false;\r
+               for( var attName in oAttributes )\r
+                       bChanged |= ( oOriginal.getAttribute( attName, 2) != oAttributes[attName] ) ;\r
+\r
+               if ( bChanged )\r
+               {\r
+                       oldNode = oOriginal ;\r
+                       oOriginal = null ;\r
+               }\r
+       }\r
+\r
+       // If the node existed (and it's not IE), then we just have to update its attributes\r
+       if ( oOriginal )\r
+       {\r
+               oNewNode = oOriginal ;\r
+       }\r
+       else\r
+       {\r
+               // #676, IE doesn't play nice with the name or type attribute\r
+               if ( oEditor.FCKBrowserInfo.IsIE )\r
+               {\r
+                       var sbHTML = [] ;\r
+                       sbHTML.push( '<' + nodeName ) ;\r
+                       for( var prop in oAttributes )\r
+                       {\r
+                               sbHTML.push( ' ' + prop + '="' + oAttributes[prop] + '"' ) ;\r
+                       }\r
+                       sbHTML.push( '>' ) ;\r
+                       if ( !oEditor.FCKListsLib.EmptyElements[nodeName.toLowerCase()] )\r
+                               sbHTML.push( '</' + nodeName + '>' ) ;\r
+\r
+                       oNewNode = oEditor.FCK.EditorDocument.createElement( sbHTML.join('') ) ;\r
+                       // Check if we are just changing the properties of an existing node: copy its properties\r
+                       if ( oldNode )\r
+                       {\r
+                               CopyAttributes( oldNode, oNewNode, oAttributes ) ;\r
+                               oEditor.FCKDomTools.MoveChildren( oldNode, oNewNode ) ;\r
+                               oldNode.parentNode.removeChild( oldNode ) ;\r
+                               oldNode = null ;\r
+\r
+                               if ( oEditor.FCK.Selection.SelectionData )\r
+                               {\r
+                                       // Trick to refresh the selection object and avoid error in\r
+                                       // fckdialog.html Selection.EnsureSelection\r
+                                       var oSel = oEditor.FCK.EditorDocument.selection ;\r
+                                       oEditor.FCK.Selection.SelectionData = oSel.createRange() ; // Now oSel.type will be 'None' reflecting the real situation\r
+                               }\r
+                       }\r
+                       oNewNode = oEditor.FCK.InsertElement( oNewNode ) ;\r
+\r
+                       // FCK.Selection.SelectionData is broken by now since we've\r
+                       // deleted the previously selected element. So we need to reassign it.\r
+                       if ( oEditor.FCK.Selection.SelectionData )\r
+                       {\r
+                               var range = oEditor.FCK.EditorDocument.body.createControlRange() ;\r
+                               range.add( oNewNode ) ;\r
+                               oEditor.FCK.Selection.SelectionData = range ;\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       oNewNode = oEditor.FCK.InsertElement( nodeName ) ;\r
+               }\r
+       }\r
+\r
+       // Set the basic attributes\r
+       for( var attName in oAttributes )\r
+               oNewNode.setAttribute( attName, oAttributes[attName], 0 ) ;     // 0 : Case Insensitive\r
+\r
+       return oNewNode ;\r
+}\r
+\r
+// Copy all the attributes from one node to the other, kinda like a clone\r
+// But oSkipAttributes is an object with the attributes that must NOT be copied\r
+function CopyAttributes( oSource, oDest, oSkipAttributes )\r
+{\r
+       var aAttributes = oSource.attributes ;\r
+\r
+       for ( var n = 0 ; n < aAttributes.length ; n++ )\r
+       {\r
+               var oAttribute = aAttributes[n] ;\r
+\r
+               if ( oAttribute.specified )\r
+               {\r
+                       var sAttName = oAttribute.nodeName ;\r
+                       // We can set the type only once, so do it with the proper value, not copying it.\r
+                       if ( sAttName in oSkipAttributes )\r
+                               continue ;\r
+\r
+                       var sAttValue = oSource.getAttribute( sAttName, 2 ) ;\r
+                       if ( sAttValue == null )\r
+                               sAttValue = oAttribute.nodeValue ;\r
+\r
+                       oDest.setAttribute( sAttName, sAttValue, 0 ) ;  // 0 : Case Insensitive\r
+               }\r
+       }\r
+       // The style:\r
+       if ( oSource.style.cssText !== '' )\r
+               oDest.style.cssText = oSource.style.cssText ;\r
+}\r
+\r
+/**\r
+* Replaces a tag with another one, keeping its contents:\r
+* for example TD --> TH, and TH --> TD.\r
+* input: the original node, and the new tag name\r
+* http://www.w3.org/TR/DOM-Level-3-Core/core.html#Document3-renameNode\r
+*/\r
+function RenameNode( oNode , newTag )\r
+{\r
+       // TODO: if the browser natively supports document.renameNode call it.\r
+       // does any browser currently support it in order to test?\r
+\r
+       // Only rename element nodes.\r
+       if ( oNode.nodeType != 1 )\r
+               return null ;\r
+\r
+       // If it's already correct exit here.\r
+       if ( oNode.nodeName == newTag )\r
+               return oNode ;\r
+\r
+       var oDoc = oNode.ownerDocument ;\r
+       // Create the new node\r
+       var newNode = oDoc.createElement( newTag ) ;\r
+\r
+       // Copy all attributes\r
+       CopyAttributes( oNode, newNode, {} ) ;\r
+\r
+       // Move children to the new node\r
+       FCKDomTools.MoveChildren( oNode, newNode ) ;\r
+\r
+       // Finally replace the node and return the new one\r
+       oNode.parentNode.replaceChild( newNode, oNode ) ;\r
+\r
+       return newNode ;\r
+}\r