0

I tried to load some scripts with jQuery, and after the download is finished I want to execute some code.

I expected to get alert(1) called but nothing happens. The scripts are correctly downloaded (checked in console).

$.when(
    $.getScript ("/framework/static/libs/ckeditor/ckeditor/ckeditor.js"),
    $.getScript ("/framework/static/libs/ckeditor/ckeditor/config.js"),
    $.getScript ("/framework/static/libs/ckeditor/ckeditor/skins/bootstrapck/editor_gecko.css"),
    $.getScript ("/framework/static/libs/ckeditor/ckeditor/lang/de.js"),
    $.getScript ("/framework/static/libs/ckeditor/ckeditor/adapters/jquery.js"),
    $.Deferred(function( deferred ){$( deferred.resolve );})
).done(function() { 
        alert (1);
});
TylerH
  • 20,799
  • 66
  • 75
  • 101
sascha2014
  • 103
  • 1
  • 12
  • 1
    [`$.getScript()`](http://api.jquery.com/jquery.getscript): "Load a **JavaScript file** from the server using a GET HTTP request, then **execute it**" - How is this supposed to work with the `editor_gecko.css`? – Andreas Nov 10 '15 at 16:09
  • you are right. I totally overlooked it's an css :-S – sascha2014 Nov 10 '15 at 16:20

1 Answers1

0

I hope the issue is in the below line.

$.getScript ("/framework/static/libs/ckeditor/ckeditor/skins/bootstrapck/editor_gecko.css")

As you can find in the documentation that it loads a JavaScript file from the server using a GET HTTP request, then executes it.

For css files you have to may use the code below.

window.getStyle = function(file) {
  var top = $('head > link[rel=stylesheet]').length ? $('head > link[rel=stylesheet]:last') : $('head > *:last');
  top.after('<link rel="stylesheet" type="text/css" href="' + file + '">');
};

$.when(
  $.getScript("/framework/static/libs/ckeditor/ckeditor/ckeditor.js"),
  $.getScript("/framework/static/libs/ckeditor/ckeditor/config.js"), window.getStyle("/framework/static/libs/ckeditor/ckeditor/skins/bootstrapck/editor_gecko.css"),
  $.getScript("/framework/static/libs/ckeditor/ckeditor/lang/de.js"),
  $.getScript("/framework/static/libs/ckeditor/ckeditor/adapters/jquery.js"),
  $.Deferred(function(deferred) {
    $(deferred.resolve);
  })
).done(function() {
  alert(1);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Kishore Sahasranaman
  • 4,013
  • 3
  • 24
  • 50