Skip to content
Permalink
Browse files

Merge branch 't/12614b' into major

  • Loading branch information...
Reinmar committed Feb 24, 2015
2 parents 5b2c7c6 + 88def81 commit 2161beb4105ed0544d193e1619db35ccadfa73e0
Showing with 52 additions and 1 deletion.
  1. +8 −0 plugins/uploadimage/plugin.js
  2. +14 −1 plugins/uploadwidget/plugin.js
  3. +30 −0 tests/plugins/uploadwidget/uploadwidget.js
@@ -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 ) {
@@ -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();
@@ -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' ) {
@@ -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 );
}
@@ -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.
You can’t perform that action at this time.