Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 't/12614b' into major
  • Loading branch information
Reinmar committed Feb 24, 2015
2 parents 5b2c7c6 + 88def81 commit 2161beb
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
8 changes: 8 additions & 0 deletions plugins/uploadimage/plugin.js
Expand Up @@ -9,6 +9,14 @@
CKEDITOR.plugins.add( 'uploadimage', {
requires: 'uploadwidget',

onLoad: function() {
CKEDITOR.addCss(
'.cke_upload_uploading img{' +
'opacity: 0.3' +
'}'
);
},

init: function( editor ) {
// Do not execute this paste lister if it will not be possible to upload file.
if ( !CKEDITOR.plugins.clipboard.isFileApiSupported ) {
Expand Down
15 changes: 14 additions & 1 deletion plugins/uploadwidget/plugin.js
Expand Up @@ -208,9 +208,11 @@
var widget = this,
id = this.wrapper.findOne( '[data-cke-upload-id]' ).data( 'cke-upload-id' ),
loader = uploads.get( id ),
capitalize = CKEDITOR.tools.capitalize;
capitalize = CKEDITOR.tools.capitalize,
oldStyle, newStyle;

loader.on( 'update', function( evt ) {
// Abort if widget was removed.
if ( !widget.wrapper || !widget.wrapper.getParent() ) {
if ( !editor.editable().find( '[data-cke-upload-id="' + id + '"]' ).count() ) {
loader.abort();
Expand All @@ -221,6 +223,8 @@

editor.fire( 'lockSnapshot' );

// Call users method, eg. if the status is `uploaded` then
// `onUploaded` method will be called, if exists.
var methodName = 'on' + capitalize( loader.status );

if ( typeof widget[ methodName ] === 'function' ) {
Expand All @@ -230,6 +234,15 @@
}
}

// Set style to the wrapper if it still exists.
newStyle = 'cke_upload_' + loader.status;
if ( widget.wrapper && newStyle != oldStyle ) {
oldStyle && widget.wrapper.removeClass( oldStyle );
widget.wrapper.addClass( newStyle );
oldStyle = newStyle;
}

// Remove widget on error or abort.
if ( loader.status == 'error' || loader.status == 'abort' ) {
editor.widgets.del( widget );
}
Expand Down
30 changes: 30 additions & 0 deletions tests/plugins/uploadwidget/uploadwidget.js
Expand Up @@ -878,6 +878,36 @@
assert.areSame( 'abort', loader.status );
} );
} );
},

'test set Class during upload': function() {
var bot = this.editorBot,
editor = bot.editor,
uploads = editor.uploadsRepository,
loader = uploads.create( bender.tools.getTestPngFile() ),
wrapper;

loader.loadAndUpload( 'uploadUrl' );

addTestUploadWidget( editor, 'testClass' );

bot.setData( '', function() {
bot.setHtmlWithSelection( '<p>x^x</p>' );

editor.insertHtml( '<span data-cke-upload-id="' + loader.id + '" data-widget="testClass">...</span>' );

wrapper = editor.editable().findOne( 'span[data-cke-widget-wrapper="1"]' );

loader.changeStatus( 'loading' );

assert.isTrue( wrapper.hasClass( 'cke_upload_loading' ), 'Has class loading.' );
assert.isFalse( wrapper.hasClass( 'cke_upload_uploading' ), 'Has NOT class uploading.' );

loader.changeStatus( 'uploading' );

assert.isFalse( wrapper.hasClass( 'cke_upload_loading' ), 'Has NOT class loading.' );
assert.isTrue( wrapper.hasClass( 'cke_upload_uploading' ), 'Has class uploading.' );
} );
}
} );
} )();

0 comments on commit 2161beb

Please sign in to comment.