• Jetzt anmelden. Es dauert nur 2 Minuten und ist kostenlos!

[ERLEDIGT] Wie lädt CKEditor Scripts/Stylesheets nach?

scbawik

Senior HTML'ler
Mir ist heute beim CKEditor etwas aufgefallen, was ich sonst bei keinem Script jemals gesehen habe.

Code:
<script src="{{ asset('vendor/ckeditor/ckeditor.js') }}"></script>

Das ist alles was ich in meinem HTML-Code stehen habe.
CKEditor fügt nun automatisch alle nötigen <script src=""> und <link href="" type="text/css" rel="stylesheet"> mit den richtigen Pfaden ein:

Code:
<script src="/vendor/ckeditor/ckeditor.js"></script>
<script src="http://example.com/vendor/ckeditor/plugins/xyz.js"></script>
<link href="http://example.com/vendor/ckeditor/plugins/xyz.css" type="text/css" rel="stylesheet">
...

Meine Frage ist nun, woher kennt CKEditor diese Pfade!?
Woher weiß CKEditor, dass seine Dateien unter "vendor/ckeditor" zu finden sind?

Habe ich die letzten Jahre geschlafen und magische Konstanten wie zb __DIR__ in PHP verpasst?
 
Werbung:
Natürlich schon selbst beantwortet.
Habe im Source Code von CKEditor nachgeschaut und folgendes gesehen:

Code:
var basePathSrcPattern = /(^|.*[\\\/])ckeditor\.js(?:\?.*|;.*)?$/i;

bzw.

Code:
function() {
// Find out the editor directory path, based on its <script> tag.var path = window.CKEDITOR_BASEPATH || '';if ( !path ) {
var scripts = document.getElementsByTagName( 'script' );for ( var i = 0; i < scripts.length; i++ ) {
var match = scripts[ i ].src.match( basePathSrcPattern );if ( match ) {
path = match[ 1 ];break;}
}
}

// In IE (only) the script.src string is the raw value entered in the // HTML source. Other browsers return the full resolved URL instead.if ( path.indexOf( ':/' ) == -1 && path.slice( 0, 2 ) != '//' ) {
// Absolute path.if ( path.indexOf( '/' ) === 0 )
path = location.href.match( /^.*?:\/\/[^\/]*/ )[ 0 ] + path;// Relative path.elsepath = location.href.match( /^[^\?]*\/(?:)/ )[ 0 ] + path;}

if ( !path )
throw 'The CKEditor installation path could not be automatically detected. Please set the global variable "CKEDITOR_BASEPATH" before creating editor instances.';return path;}

Nicht das was ich erhofft hatte.
 
Zurück
Oben