Gib*_*boK 3 javascript ckeditor ckfinder
我正在使用CkFinder 3,在成功上传图像后,我需要能够在用户点击"选择"按钮后检测到:
目前我正在使用files:choose但我无法在cb事件中找到此信息.
知道怎么解决吗?代码示例将非常感谢.
CKFinder.modal( {
connectorPath: 'https://api.mysite.com/lib/ckfinder/core/connector/php/connector.php',
resizeImages: false,
startupFolderExpanded: true,
chooseFiles: true,
width: 1000,
height: 800,
language: 'en',
onInit: function( finder ) {
finder.on( 'files:choose', function( evt ) {
} );
}
} );
Run Code Online (Sandbox Code Playgroud)
以files:choose事件描述为例.您可以获得用户选择Backbone.Collection的文件evt.data.files.
棘手的部分是从ImageInfo服务器(使用command:send请求)获取图像维度,因为它需要使用promises处理异步代码.
假设您只允许上传图像,示例代码如下:
// Listen to event.
finder.on( 'files:choose', function( evt ) {
// Iterate over the files collection.
evt.data.files.forEach( function( file ) {
// Send command to the server.
finder.request( 'command:send', {
name: 'ImageInfo',
folder: file.get( 'folder' ),
params: { fileName: file.get( 'name' ) }
} ).done( function( response ) {
// Process server response.
if ( response.error ) {
// Some error handling.
return;
}
// Log image data:
console.log( '-------------------' );
console.log( 'Name:', file.get( 'name' ) );
console.log( 'URL:', file.getUrl() );
console.log( 'Dimensions:', response.width + 'x' + response.height );
console.log( 'Size:', response.size + 'B' );
} );
} );
} )
Run Code Online (Sandbox Code Playgroud)
如果您使用任何远程后端,例如Dropbox,您可能需要使用该file:getUrl请求来获取文件的URL.
| 归档时间: |
|
| 查看次数: |
841 次 |
| 最近记录: |