Skip to content

Commit

Permalink
Merge branch 't/9764' into major
Browse files Browse the repository at this point in the history
  • Loading branch information
Reinmar committed Sep 11, 2013
2 parents 67722f4 + dfd343a commit 22f3d33
Show file tree
Hide file tree
Showing 38 changed files with 4,846 additions and 626 deletions.
38 changes: 27 additions & 11 deletions core/command.js
Expand Up @@ -54,10 +54,11 @@ CKEDITOR.command = function( editor, commandDefinition ) {

/**
* Explicitly update the status of the command, by firing the {@link CKEDITOR.command#event-refresh} event,
* as well as invoke the {@link CKEDITOR.command#method-refresh} method if defined, this method
* as well as invoke the {@link CKEDITOR.commandDefinition#refresh} method if defined, this method
* is to allow different parts of the editor code to contribute in command status resolution.
*
* @todo
* @param {CKEDITOR.editor} editor The editor instance.
* @param {CKEDITOR.dom.elementPath} path
*/
this.refresh = function( editor, path ) {
// Do nothing is we're on read-only and this command doesn't support it.
Expand All @@ -72,8 +73,19 @@ CKEDITOR.command = function( editor, commandDefinition ) {
return true;
}

// Make the "enabled" state as basis.
this.enable();
// Disable commands that are not allowed by the active filter.
if ( !this.checkAllowed( true ) ) {
this.disable();
return true;
}

// Make the "enabled" state a default for commands enabled from start.
if ( !this.startDisabled )
this.enable();

// Disable commands which shouldn't be enabled in this mode.
if ( this.modes && !this.modes[ editor.mode ] )
this.disable();

if ( this.fire( 'refresh', { editor: editor, path: path } ) === false )
return true;
Expand All @@ -84,19 +96,20 @@ CKEDITOR.command = function( editor, commandDefinition ) {
var allowed;

/**
* Checks whether this command is allowed by the allowed
* content filter ({@link CKEDITOR.filter}). This means
* Checks whether this command is allowed by the active allowed
* content filter ({@link CKEDITOR.editor#activeFilter}). This means
* that if command implements {@link CKEDITOR.feature} interface it will be tested
* by {@link CKEDITOR.filter#checkFeature}.
* by the {@link CKEDITOR.filter#checkFeature} method.
*
* @since 4.1
* @param {Boolean} [noCache] Skip cache for example due to active filter change. Since CKEditor 4.2.
* @returns {Boolean} Whether this command is allowed.
*/
this.checkAllowed = function() {
if ( typeof allowed == 'boolean' )
this.checkAllowed = function( noCache ) {
if ( !noCache && typeof allowed == 'boolean' )
return allowed;

return allowed = editor.filter.checkFeature( this );
return allowed = editor.activeFilter.checkFeature( this );
};

CKEDITOR.tools.extend( this, commandDefinition, {
Expand Down Expand Up @@ -198,7 +211,10 @@ CKEDITOR.command.prototype = {
*/
setState: function( newState ) {
// Do nothing if there is no state change.
if ( this.state == newState || !this.checkAllowed() )
if ( this.state == newState )
return false;

if ( newState != CKEDITOR.TRISTATE_DISABLED && !this.checkAllowed() )
return false;

this.previousState = this.state;
Expand Down
47 changes: 47 additions & 0 deletions core/dom/document.js
Expand Up @@ -266,5 +266,52 @@ CKEDITOR.tools.extend( CKEDITOR.dom.document.prototype, {

this.$.write( html );
this.$.close();
},

/**
* Wrapper for `querySelectorAll`. Returns a list of elements within this document that match
* specified `selector`.
*
* **Note:** returned list is not a live collection (like a result of native `querySelectorAll`).
*
* @since 4.3
* @param {String} selector
* @returns {CKEDITOR.dom.nodeList}
*/
find: function( selector ) {
return new CKEDITOR.dom.nodeList( this.$.querySelectorAll( selector ) );
},

/**
* Wrapper for `querySelector`. Returns first element within this document that matches
* specified `selector`.
*
* @since 4.3
* @param {String} selector
* @returns {CKEDITOR.dom.element}
*/
findOne: function( selector ) {
var el = this.$.querySelector( selector );

return el ? new CKEDITOR.dom.element( el ) : null;
},

/**
* IE8 only method. It returns document fragment which has all HTML5 elements enabled.
*
* @since 4.3
* @private
* @returns DocumentFragment
*/
_getHtml5ShivFrag: function() {
var $frag = this.getCustomData( 'html5ShivFrag' );

if ( !$frag ) {
$frag = this.$.createDocumentFragment();
CKEDITOR.tools.enableHtml5Elements( $frag, true );
this.setCustomData( 'html5ShivFrag', $frag );
}

return $frag;
}
});
112 changes: 99 additions & 13 deletions core/dom/element.js
Expand Up @@ -408,33 +408,46 @@ CKEDITOR.tools.extend( CKEDITOR.dom.element.prototype, {
* @param {String} html The HTML to be set for this element.
* @returns {String} The inserted HTML.
*/
setHtml: (function() {
var standard = function( html ) {
return ( this.$.innerHTML = html );
};

if ( CKEDITOR.env.ie && CKEDITOR.env.version < 9 ) {
setHtml: ( CKEDITOR.env.ie && CKEDITOR.env.version < 9 ) ?
// old IEs throws error on HTML manipulation (through the "innerHTML" property)
// on the element which resides in an DTD invalid position, e.g. <span><div></div></span>
// fortunately it can be worked around with DOM manipulation.
return function( html ) {
try { return standard.call( this, html ); }
function( html ) {
try {
var $ = this.$;

// Fix the case when setHtml is called on detached element.
// HTML5 shiv used for document in which this element was created
// won't affect that detached element. So get document fragment with
// all HTML5 elements enabled and set innerHTML while this element is appended to it.
if ( this.getParent() )
return ( $.innerHTML = html );
else {
var $frag = this.getDocument()._getHtml5ShivFrag();
$frag.appendChild( $ );
$.innerHTML = html;
$frag.removeChild( $ );

return html;
}
}
catch ( e ) {
this.$.innerHTML = '';

var temp = new CKEDITOR.dom.element( 'body', this.getDocument() );
temp.$.innerHTML = html;

var children = temp.getChildren();
while( children.count() )
while ( children.count() )
this.append( children.getItem( 0 ) );

return html;
}
};
} else
return standard;
})(),
}
:
function( html ) {
return ( this.$.innerHTML = html );
},

/**
* Sets the element contents as plain text.
Expand Down Expand Up @@ -1800,9 +1813,82 @@ CKEDITOR.tools.extend( CKEDITOR.dom.element.prototype, {
}

return null;
},

/**
* Returns list of elements within this element that match specified `selector`.
*
* **Notes:**
*
* * Not available in IE7.
* * Returned list is not a live collection (like a result of native `querySelectorAll`).
* * Unlike native `querySelectorAll` this method ensures selector contextualization. This is:
*
* HTML: '<body><div><i>foo</i></div></body>'
* Native: div.querySelectorAll( 'body i' ) // -> [ <i>foo</i> ]
* Method: div.find( 'body i' ) // -> []
* div.find( 'i' ) // -> [ <i>foo</i> ]
*
* @since 4.3
* @param {String} selector
* @returns {CKEDITOR.dom.nodeList}
*/
find: function( selector ) {
var removeTmpId = createTmpId( this ),
list = new CKEDITOR.dom.nodeList(
this.$.querySelectorAll( getContextualizedSelector( this, selector ) )
);

removeTmpId();

return list;
},

/**
* Returns first element within this element that matches specified `selector`.
*
* **Notes:**
*
* * Not available in IE7.
* * Unlike native `querySelectorAll` this method ensures selector contextualization. This is:
*
* HTML: '<body><div><i>foo</i></div></body>'
* Native: div.querySelector( 'body i' ) // -> <i>foo</i>
* Method: div.findOne( 'body i' ) // -> null
* div.findOne( 'i' ) // -> <i>foo</i>
*
* @since 4.3
* @param {String} selector
* @returns {CKEDITOR.dom.element}
*/
findOne: function( selector ) {
var removeTmpId = createTmpId( this ),
found = this.$.querySelector( getContextualizedSelector( this, selector ) );

removeTmpId();

return found ? new CKEDITOR.dom.element( found ) : null;
}
});

function createTmpId( element ) {
var hadId = true;

if ( !element.$.id ) {
element.$.id = 'cke_tmp_' + CKEDITOR.tools.getNextNumber();
hadId = false;
}

return function() {
if ( !hadId )
element.removeAttribute( 'id' );
};
}

function getContextualizedSelector( element, selector ) {
return '#' + element.$.id + ' ' + selector.split( /,\s*/ ).join( ', #' + element.$.id + ' ' );
}

var sides = {
width: [ 'border-left-width', 'border-right-width', 'padding-left', 'padding-right' ],
height: [ 'border-top-width', 'border-bottom-width', 'padding-top', 'padding-bottom' ]
Expand Down

0 comments on commit 22f3d33

Please sign in to comment.