Skip to content

Commit

Permalink
Extract key cache appending logic to separate method
Browse files Browse the repository at this point in the history
  • Loading branch information
sculpt0r authored and Comandeer committed Jan 12, 2022
1 parent cc875e0 commit d452039
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
2 changes: 1 addition & 1 deletion ckeditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/* jshint ignore:start */
/* jscs:disable */
// replace_start
window.CKEDITOR||(window.CKEDITOR=function(){var o,d=/(^|.*[\\\/])ckeditor\.js(?:\?.*|;.*)?$/i,e={timestamp:"",version:"%VERSION%",revision:"%REV%",rnd:Math.floor(900*Math.random())+100,_:{pending:[],basePathSrcPattern:d},status:"unloaded",basePath:function(){var t=window.CKEDITOR_BASEPATH||"";if(!t)for(var e=document.getElementsByTagName("script"),n=0;n<e.length;n++){var a=e[n].src.match(d);if(a){t=a[1];break}}if(-1==t.indexOf(":/")&&"//"!=t.slice(0,2)&&(t=0===t.indexOf("/")?location.href.match(/^.*?:\/\/[^\/]*/)[0]+t:location.href.match(/^[^\?]*\/(?:)/)[0]+t),!t)throw'The CKEditor installation path could not be automatically detected. Please set the global variable "CKEDITOR_BASEPATH" before creating editor instances.';return t}(),getUrl:function(t){return-1==t.indexOf(":/")&&0!==t.indexOf("/")&&(t=this.basePath+t),this.timestamp&&"/"!=t.charAt(t.length-1)&&!/[&?]t=/.test(t)&&(t+=(0<=t.indexOf("?")?"&":"?")+"t="+this.timestamp),t},domReady:(o=[],function(t){if(o.push(t),"complete"===document.readyState&&setTimeout(i,1),1==o.length)if(document.addEventListener)document.addEventListener("DOMContentLoaded",i,!1),window.addEventListener("load",i,!1);else if(document.attachEvent){document.attachEvent("onreadystatechange",i),window.attachEvent("onload",i);var e=!1;try{e=!window.frameElement}catch(n){}document.documentElement.doScroll&&e&&!function a(){try{document.documentElement.doScroll("left")}catch(n){return void setTimeout(a,1)}i()}()}})};function i(){try{document.addEventListener?(document.removeEventListener("DOMContentLoaded",i,!1),window.removeEventListener("load",i,!1),n()):document.attachEvent&&"complete"===document.readyState&&(document.detachEvent("onreadystatechange",i),window.detachEvent("onload",i),n())}catch(t){}}function n(){for(var t;t=o.shift();)t()}var a,r=window.CKEDITOR_GETURL;return r&&(a=e.getUrl,e.getUrl=function(t){return r.call(e,t)||a.call(e,t)}),e}());
window.CKEDITOR||(window.CKEDITOR=function(){var o,d=/(^|.*[\\\/])ckeditor\.js(?:\?.*|;.*)?$/i,e={timestamp:"",version:"%VERSION%",revision:"%REV%",rnd:Math.floor(900*Math.random())+100,_:{pending:[],basePathSrcPattern:d},status:"unloaded",basePath:function(){var t=window.CKEDITOR_BASEPATH||"";if(!t)for(var e=document.getElementsByTagName("script"),n=0;n<e.length;n++){var a=e[n].src.match(d);if(a){t=a[1];break}}if(-1==t.indexOf(":/")&&"//"!=t.slice(0,2)&&(t=0===t.indexOf("/")?location.href.match(/^.*?:\/\/[^\/]*/)[0]+t:location.href.match(/^[^\?]*\/(?:)/)[0]+t),!t)throw'The CKEditor installation path could not be automatically detected. Please set the global variable "CKEDITOR_BASEPATH" before creating editor instances.';return t}(),getUrl:function(t){return-1==t.indexOf(":/")&&0!==t.indexOf("/")&&(t=this.basePath+t),t=this.appendTimestamp(t)},appendTimestamp:function(t){return this.timestamp&&"/"!=t.charAt(t.length-1)&&!/[&?]t=/.test(t)&&(t+=(0<=t.indexOf("?")?"&":"?")+"t="+this.timestamp),t},domReady:(o=[],function(t){if(o.push(t),"complete"===document.readyState&&setTimeout(i,1),1==o.length)if(document.addEventListener)document.addEventListener("DOMContentLoaded",i,!1),window.addEventListener("load",i,!1);else if(document.attachEvent){document.attachEvent("onreadystatechange",i),window.attachEvent("onload",i);var e=!1;try{e=!window.frameElement}catch(n){}document.documentElement.doScroll&&e&&!function a(){try{document.documentElement.doScroll("left")}catch(n){return void setTimeout(a,1)}i()}()}})};function i(){try{document.addEventListener?(document.removeEventListener("DOMContentLoaded",i,!1),window.removeEventListener("load",i,!1),n()):document.attachEvent&&"complete"===document.readyState&&(document.detachEvent("onreadystatechange",i),window.detachEvent("onload",i),n())}catch(t){}}function n(){for(var t;t=o.shift();)t()}var a,r=window.CKEDITOR_GETURL;return r&&(a=e.getUrl,e.getUrl=function(t){return r.call(e,t)||a.call(e,t)}),e}());
// replace_end
/* jscs:enable */
/* jshint ignore:end */
Expand Down
21 changes: 19 additions & 2 deletions core/ckeditor_base.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,26 @@ if ( !window.CKEDITOR ) {
if ( resource.indexOf( ':/' ) == -1 && resource.indexOf( '/' ) !== 0 )
resource = this.basePath + resource;

// Add the timestamp, except for directories.
if ( this.timestamp && resource.charAt( resource.length - 1 ) != '/' && !( /[&?]t=/ ).test( resource ) )
resource = this.appendTimestamp( resource );

return resource;
},

/**
* Appends {@link CKEDITOR#timestamp} to the provided URL as querystring parameter ("t").
*
* Leaves the URL unchanged if it is a directory URL or it already contains querystring parameter.
*
* @param {String} resource The resource whose URL we want to affect with the timestamp.
* @returns The resource URL with cache key appended whenever possible.
*/
appendTimestamp: function( resource ) {
if ( this.timestamp &&
resource.charAt( resource.length - 1 ) != '/' &&
!( /[&?]t=/ ).test( resource )
) {
resource += ( resource.indexOf( '?' ) >= 0 ? '&' : '?' ) + 't=' + this.timestamp;
}

return resource;
},
Expand Down
3 changes: 1 addition & 2 deletions core/dom/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ CKEDITOR.tools.extend( CKEDITOR.dom.document.prototype, {
* @param {String} cssFileUrl The CSS file URL.
*/
appendStyleSheet: function( cssFileUrl ) {
var cacheKey = CKEDITOR.timestamp ? '?t=' + CKEDITOR.timestamp : '';
cssFileUrl += cacheKey;
cssFileUrl = CKEDITOR.appendTimestamp( cssFileUrl );

if ( this.$.createStyleSheet )
this.$.createStyleSheet( cssFileUrl );
Expand Down
3 changes: 1 addition & 2 deletions core/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,15 +420,14 @@
buildStyleHtml: function( css ) {
css = [].concat( css );
var item,
cacheKey = CKEDITOR.timestamp ? '?t=' + CKEDITOR.timestamp : '',
retval = [];
for ( var i = 0; i < css.length; i++ ) {
if ( ( item = css[ i ] ) ) {
// Is CSS style text ?
if ( /@import|[{}]/.test( item ) ) {
retval.push( '<style>' + item + '</style>' );
} else {
item = item + cacheKey;
item = CKEDITOR.appendTimestamp( item );
retval.push( '<link type="text/css" rel=stylesheet href="' + item + '">' );
}
}
Expand Down

0 comments on commit d452039

Please sign in to comment.