X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;ds=sidebyside;f=_source%2Fplugins%2Ffilebrowser%2Fplugin.js;h=d35432741f11d9045906d237b31e6de795fa4d5b;hb=fb481ba0a7d298e3e7b9034fcb9f2afdc6e8e796;hp=3160751085d40e7c4429d6c1352823b045fe9c6d;hpb=941b0a9ba4e673e292510d80a5a86806994b8ea6;p=ckeditor.git
diff --git a/_source/plugins/filebrowser/plugin.js b/_source/plugins/filebrowser/plugin.js
index 3160751..d354327 100644
--- a/_source/plugins/filebrowser/plugin.js
+++ b/_source/plugins/filebrowser/plugin.js
@@ -1,18 +1,18 @@
/*
-Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.
+Copyright (c) 2003-2012, CKSource - Frederico Knabben. All rights reserved.
For licensing, see LICENSE.html or http://ckeditor.com/license
*/
/**
- * @fileOverview The "filebrowser" plugin, it adds support for file uploads and
+ * @fileOverview The "filebrowser" plugin that adds support for file uploads and
* browsing.
*
- * When file is selected inside of the file browser or uploaded, its url is
- * inserted automatically to a field, which is described in the 'filebrowser'
- * attribute. To specify field that should be updated, pass the tab id and
- * element id, separated with a colon.
+ * When a file is uploaded or selected inside the file browser, its URL is
+ * inserted automatically into a field defined in the filebrowser
+ * attribute. In order to specify a field that should be updated, pass the tab ID and
+ * the element ID, separated with a colon.
*
- * Example 1: (Browse)
+ * Example 1: (Browse)
*
*
* { @@ -23,10 +23,10 @@ For licensing, see LICENSE.html or http://ckeditor.com/license * } ** - * If you set the 'filebrowser' attribute on any element other than - * 'fileButton', the 'Browse' action will be triggered. + * If you set the
filebrowser
attribute for an element other than
+ * the fileButton
, the Browse
action will be triggered.* { @@ -38,23 +38,23 @@ For licensing, see LICENSE.html or http://ckeditor.com/license * } ** - * If you set the 'filebrowser' attribute on a fileButton element, the - * 'QuickUpload' action will be executed. + * If you set the
filebrowser
attribute for a fileButton
+ * element, the QuickUpload
action will be executed.- * [action] - Browse or QuickUpload - * [target] - field to update, tabId:elementId - * [params] - additional arguments to be passed to the server connector (optional) - * [onSelect] - function to execute when file is selected/uploaded (optional) - * [url] - the URL to be called (optional) - *+ *
action
– Browse
or QuickUpload
.target
– the field to update in the tabId:elementId
format.params
– additional arguments to be passed to the server connector (optional).onSelect
– a function to execute when the file is selected/uploaded (optional).url
– the URL to be called (optional).* { @@ -63,16 +63,16 @@ For licensing, see LICENSE.html or http://ckeditor.com/license * id : 'buttonId', * filebrowser : * { - * action : 'QuickUpload', //required - * target : 'tab1:elementId', //required - * params : //optional + * action : 'QuickUpload', // required + * target : 'tab1:elementId', // required + * params : // optional * { * type : 'Files', * currentFolder : '/folder/' * }, - * onSelect : function( fileUrl, errorMessage ) //optional + * onSelect : function( fileUrl, errorMessage ) // optional * { - * // Do not call the built-in selectFuntion + * // Do not call the built-in selectFuntion. * // return false; * } * }, @@ -80,14 +80,16 @@ For licensing, see LICENSE.html or http://ckeditor.com/license * } ** - * Suppose we have a file element with id 'myFile', text field with id - * 'elementId' and a fileButton. If filebowser.url is not specified explicitly, - * form action will be set to 'filebrowser[DialogName]UploadUrl' or, if not - * specified, to 'filebrowserUploadUrl'. Additional parameters from 'params' - * object will be added to the query string. It is possible to create your own - * uploadHandler and cancel the built-in updateTargetElement command. + * Suppose you have a file element with an ID of
myFile
, a text
+ * field with an ID of elementId
and a fileButton
.
+ * If the filebowser.url
attribute is not specified explicitly,
+ * the form action will be set to filebrowser[DialogWindowName]UploadUrl
+ * or, if not specified, to filebrowserUploadUrl
. Additional parameters
+ * from the params
object will be added to the query string. It is
+ * possible to create your own uploadHandler
and cancel the built-in
+ * updateTargetElement
command.* { @@ -103,16 +105,16 @@ For licensing, see LICENSE.html or http://ckeditor.com/license * } ** - * In this example, after pressing a button, file browser will be opened in a - * popup. If we don't specify filebrowser.url attribute, - * 'filebrowser[DialogName]BrowseUrl' or 'filebrowserBrowseUrl' will be used. - * After selecting a file in a file browser, an element with id 'elementId' will - * be updated. Just like in the third example, a custom 'onSelect' function may be - * defined. + * In this example, when the button is pressed, the file browser will be opened in a + * popup window. If you do not specify the
filebrowser.url
attribute,
+ * filebrowser[DialogName]BrowseUrl
or
+ * filebrowserBrowseUrl
will be used. After selecting a file in the file
+ * browser, an element with an ID of elementId
will be updated. Just
+ * like in the third example, a custom onSelect
function may be defined.
*/
( function()
{
- /**
+ /*
* Adds (additional) arguments to given url.
*
* @param {String}
@@ -135,7 +137,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
return url + ( ( url.indexOf( "?" ) != -1 ) ? "&" : "?" ) + queryString.join( "&" );
}
- /**
+ /*
* Make a string's first character uppercase.
*
* @param {String}
@@ -148,7 +150,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
return f + str.substr( 1 );
}
- /**
+ /*
* The onlick function assigned to the 'Browse Server' button. Opens the
* file browser and updates target field when file is selected.
*
@@ -174,10 +176,11 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
params.langCode = editor.langCode;
var url = addQueryString( this.filebrowser.url, params );
- editor.popup( url, width, height );
+ // TODO: V4: Remove backward compatibility (#8163).
+ editor.popup( url, width, height, editor.config.filebrowserWindowFeatures || editor.config.fileBrowserWindowFeatures );
}
- /**
+ /*
* The onlick function assigned to the 'Upload' button. Makes the final
* decision whether form is really submitted and updates target field when
* file is uploaded.
@@ -202,7 +205,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
return true;
}
- /**
+ /*
* Setups the file element.
*
* @param {CKEDITOR.ui.dialog.file}
@@ -223,16 +226,16 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
fileInput.filebrowser = filebrowser;
}
- /**
+ /*
* Traverse through the content definition and attach filebrowser to
* elements with 'filebrowser' attribute.
*
* @param String
* dialogName Dialog name.
- * @param {CKEDITOR.dialog.dialogDefinitionObject}
+ * @param {CKEDITOR.dialog.definitionObject}
* definition Dialog definition.
* @param {Array}
- * elements Array of {@link CKEDITOR.dialog.contentDefinition}
+ * elements Array of {@link CKEDITOR.dialog.definition.content}
* objects.
*/
function attachFileBrowser( editor, dialogName, definition, elements )
@@ -243,7 +246,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
{
element = elements[ i ];
- if ( element.type == 'hbox' || element.type == 'vbox' )
+ if ( element.type == 'hbox' || element.type == 'vbox' || element.type == 'fieldset' )
attachFileBrowser( editor, dialogName, definition, element.children );
if ( !element.filebrowser )
@@ -261,8 +264,13 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
if ( element.filebrowser.action == 'Browse' )
{
- var url = element.filebrowser.url || editor.config[ 'filebrowser' + ucFirst( dialogName ) + 'BrowseUrl' ]
- || editor.config.filebrowserBrowseUrl;
+ var url = element.filebrowser.url;
+ if ( url === undefined )
+ {
+ url = editor.config[ 'filebrowser' + ucFirst( dialogName ) + 'BrowseUrl' ];
+ if ( url === undefined )
+ url = editor.config.filebrowserBrowseUrl;
+ }
if ( url )
{
@@ -273,12 +281,28 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
}
else if ( element.filebrowser.action == 'QuickUpload' && element[ 'for' ] )
{
- url = element.filebrowser.url || editor.config[ 'filebrowser' + ucFirst( dialogName ) + 'UploadUrl' ]
- || editor.config.filebrowserUploadUrl;
+ url = element.filebrowser.url;
+ if ( url === undefined )
+ {
+ url = editor.config[ 'filebrowser' + ucFirst( dialogName ) + 'UploadUrl' ];
+ if ( url === undefined )
+ url = editor.config.filebrowserUploadUrl;
+ }
if ( url )
{
- element.onClick = uploadFile;
+ var onClick = element.onClick;
+ element.onClick = function( evt )
+ {
+ // "element" here means the definition object, so we need to find the correct
+ // button to scope the event call
+ var sender = evt.sender;
+ if ( onClick && onClick.call( sender, evt ) === false )
+ return false;
+
+ return uploadFile.call( sender, evt );
+ };
+
element.filebrowser.url = url;
element.hidden = false;
setupFileElement( editor, definition.getContents( element[ 'for' ][ 0 ] ).get( element[ 'for' ][ 1 ] ), element.filebrowser );
@@ -287,7 +311,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
}
}
- /**
+ /*
* Updates the target element with the url of uploaded/selected file.
*
* @param {String}
@@ -297,7 +321,6 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
{
var dialog = sourceElement.getDialog();
var targetElement = sourceElement.filebrowser.target || null;
- url = url.replace( /#/g, '%23' );
// If there is a reference to targetElement, update it.
if ( targetElement )
@@ -312,10 +335,10 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
}
}
- /**
+ /*
* Returns true if filebrowser is configured in one of the elements.
*
- * @param {CKEDITOR.dialog.dialogDefinitionObject}
+ * @param {CKEDITOR.dialog.definitionObject}
* definition Dialog definition.
* @param String
* tabId The tab id where element(s) can be found.
@@ -329,13 +352,14 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
var ids = elementId.split( ";" );
for ( var i = 0 ; i < ids.length ; i++ )
{
- if ( isConfigured( definition, tabId, ids[i]) )
+ if ( isConfigured( definition, tabId, ids[i] ) )
return true;
}
return false;
}
- return ( definition.getContents( tabId ).get( elementId ).filebrowser && definition.getContents( tabId ).get( elementId ).filebrowser.url );
+ var elementFileBrowser = definition.getContents( tabId ).get( elementId ).filebrowser;
+ return ( elementFileBrowser && elementFileBrowser.url );
}
function setUrl( fileUrl, data )
@@ -347,6 +371,9 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
if ( targetInput )
dialog.getContentElement( targetInput[ 0 ], targetInput[ 1 ] ).reset();
+ if ( typeof data == 'function' && data.call( this._.filebrowserSe ) === false )
+ return;
+
if ( onSelect && onSelect.call( this._.filebrowserSe, fileUrl, data ) === false )
return;
@@ -363,21 +390,144 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
init : function( editor, pluginPath )
{
editor._.filebrowserFn = CKEDITOR.tools.addFunction( setUrl, editor );
+ editor.on( 'destroy', function () { CKEDITOR.tools.removeFunction( this._.filebrowserFn ); } );
+ }
+ } );
- CKEDITOR.on( 'dialogDefinition', function( evt )
+ CKEDITOR.on( 'dialogDefinition', function( evt )
+ {
+ var definition = evt.data.definition,
+ element;
+ // Associate filebrowser to elements with 'filebrowser' attribute.
+ for ( var i in definition.contents )
+ {
+ if ( ( element = definition.contents[ i ] ) )
{
- // Associate filebrowser to elements with 'filebrowser' attribute.
- for ( var i in evt.data.definition.contents )
+ attachFileBrowser( evt.editor, evt.data.name, definition, element.elements );
+ if ( element.hidden && element.filebrowser )
{
- attachFileBrowser( evt.editor, evt.data.name, evt.data.definition, evt.data.definition.contents[ i ].elements );
- if ( evt.data.definition.contents[ i ].hidden && evt.data.definition.contents[ i ].filebrowser )
- {
- evt.data.definition.contents[ i ].hidden =
- !isConfigured( evt.data.definition, evt.data.definition.contents[ i ][ 'id' ], evt.data.definition.contents[ i ].filebrowser );
- }
+ element.hidden = !isConfigured( definition, element[ 'id' ], element.filebrowser );
}
- } );
+ }
}
} );
} )();
+
+/**
+ * The location of an external file browser that should be launched when the Browse Server
+ * button is pressed. If configured, the Browse Server button will appear in the
+ * Link, Image, and Flash dialog windows.
+ * @see The File Browser/Uploader documentation.
+ * @name CKEDITOR.config.filebrowserBrowseUrl
+ * @since 3.0
+ * @type String
+ * @default ''
(empty string = disabled)
+ * @example
+ * config.filebrowserBrowseUrl = '/browser/browse.php';
+ */
+
+/**
+ * The location of the script that handles file uploads.
+ * If set, the Upload tab will appear in the Link, Image,
+ * and Flash dialog windows.
+ * @name CKEDITOR.config.filebrowserUploadUrl
+ * @see The File Browser/Uploader documentation.
+ * @since 3.0
+ * @type String
+ * @default ''
(empty string = disabled)
+ * @example
+ * config.filebrowserUploadUrl = '/uploader/upload.php';
+ */
+
+/**
+ * The location of an external file browser that should be launched when the Browse Server
+ * button is pressed in the Image dialog window.
+ * If not set, CKEditor will use {@link CKEDITOR.config.filebrowserBrowseUrl}
.
+ * @name CKEDITOR.config.filebrowserImageBrowseUrl
+ * @since 3.0
+ * @type String
+ * @default ''
(empty string = disabled)
+ * @example
+ * config.filebrowserImageBrowseUrl = '/browser/browse.php?type=Images';
+ */
+
+/**
+ * The location of an external file browser that should be launched when the Browse Server
+ * button is pressed in the Flash dialog window.
+ * If not set, CKEditor will use {@link CKEDITOR.config.filebrowserBrowseUrl}
.
+ * @name CKEDITOR.config.filebrowserFlashBrowseUrl
+ * @since 3.0
+ * @type String
+ * @default ''
(empty string = disabled)
+ * @example
+ * config.filebrowserFlashBrowseUrl = '/browser/browse.php?type=Flash';
+ */
+
+/**
+ * The location of the script that handles file uploads in the Image dialog window.
+ * If not set, CKEditor will use {@link CKEDITOR.config.filebrowserUploadUrl}
.
+ * @name CKEDITOR.config.filebrowserImageUploadUrl
+ * @since 3.0
+ * @type String
+ * @default ''
(empty string = disabled)
+ * @example
+ * config.filebrowserImageUploadUrl = '/uploader/upload.php?type=Images';
+ */
+
+/**
+ * The location of the script that handles file uploads in the Flash dialog window.
+ * If not set, CKEditor will use {@link CKEDITOR.config.filebrowserUploadUrl}
.
+ * @name CKEDITOR.config.filebrowserFlashUploadUrl
+ * @since 3.0
+ * @type String
+ * @default ''
(empty string = disabled)
+ * @example
+ * config.filebrowserFlashUploadUrl = '/uploader/upload.php?type=Flash';
+ */
+
+/**
+ * The location of an external file browser that should be launched when the Browse Server
+ * button is pressed in the Link tab of the Image dialog window.
+ * If not set, CKEditor will use {@link CKEDITOR.config.filebrowserBrowseUrl}
.
+ * @name CKEDITOR.config.filebrowserImageBrowseLinkUrl
+ * @since 3.2
+ * @type String
+ * @default ''
(empty string = disabled)
+ * @example
+ * config.filebrowserImageBrowseLinkUrl = '/browser/browse.php';
+ */
+
+/**
+ * The features to use in the file browser popup window.
+ * @name CKEDITOR.config.filebrowserWindowFeatures
+ * @since 3.4.1
+ * @type String
+ * @default 'location=no,menubar=no,toolbar=no,dependent=yes,minimizable=no,modal=yes,alwaysRaised=yes,resizable=yes,scrollbars=yes'
+ * @example
+ * config.filebrowserWindowFeatures = 'resizable=yes,scrollbars=no';
+ */
+
+/**
+ * The width of the file browser popup window. It can be a number denoting a value in
+ * pixels or a percent string.
+ * @name CKEDITOR.config.filebrowserWindowWidth
+ * @type Number|String
+ * @default '80%'
+ * @example
+ * config.filebrowserWindowWidth = 750;
+ * @example
+ * config.filebrowserWindowWidth = '50%';
+ */
+
+/**
+ * The height of the file browser popup window. It can be a number denoting a value in
+ * pixels or a percent string.
+ * @name CKEDITOR.config.filebrowserWindowHeight
+ * @type Number|String
+ * @default '70%'
+ * @example
+ * config.filebrowserWindowHeight = 580;
+ * @example
+ * config.filebrowserWindowHeight = '50%';
+ */