mirror of
https://github.com/Studio-42/elFinder
synced 2026-06-08 12:37:09 +00:00
[js:core] fix #1791 implement JS, CSS loader and auto load of elFinder CSS
This commit is contained in:
@@ -5,14 +5,6 @@
|
||||
<title>elFinder 2.1.x source version with PHP connector</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2" />
|
||||
|
||||
<!-- Section CSS -->
|
||||
<!-- jQuery UI (REQUIRED) -->
|
||||
<link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css">
|
||||
|
||||
<!-- elFinder CSS (REQUIRED) -->
|
||||
<link rel="stylesheet" type="text/css" href="css/elfinder.min.css">
|
||||
<link rel="stylesheet" type="text/css" href="css/theme.css">
|
||||
|
||||
<!-- Require JS (REQUIRED) -->
|
||||
<!-- Rename "main.default.js" to "main.js" and edit it if you need configure elFInder options or any things -->
|
||||
<script data-main="./main.default.js" src="//cdnjs.cloudflare.com/ajax/libs/require.js/2.3.2/require.min.js"></script>
|
||||
|
||||
+104
-28
@@ -7,6 +7,35 @@
|
||||
var elFinder = function(node, opts) {
|
||||
//this.time('load');
|
||||
|
||||
// auto load required CSS
|
||||
if (opts.cssAutoLoad) {
|
||||
(function(fm) {
|
||||
var myTag = $('head > script[src$="js/elfinder.min.js"],script[src$="js/elfinder.full.js"]:first'),
|
||||
baseUrl, hide, fi;
|
||||
if (myTag.length) {
|
||||
// hide elFinder node while css loading
|
||||
hide = $('<style>.elfinder{display:none}</style>');
|
||||
|
||||
$('head').append(hide);
|
||||
baseUrl = myTag.attr('src').replace(/js\/[^\/]+$/, '');
|
||||
fm.loadCss([baseUrl+'css/elfinder.min.css', baseUrl+'css/theme.css']);
|
||||
|
||||
// additional CSS files
|
||||
if ($.isArray(opts.cssAutoLoad)) {
|
||||
fm.loadCss(opts.cssAutoLoad);
|
||||
}
|
||||
|
||||
// check css loaded and remove hide
|
||||
fi = setInterval(function() {
|
||||
if ($(node).css('display') !== 'none') {
|
||||
clearInterval(fi);
|
||||
hide.remove();
|
||||
}
|
||||
}, 10);
|
||||
}
|
||||
})(this);
|
||||
}
|
||||
|
||||
var self = this,
|
||||
|
||||
/**
|
||||
@@ -1267,34 +1296,6 @@ var elFinder = function(node, opts) {
|
||||
return this.options.url + (this.options.url.indexOf('?') === -1 ? '?' : '&') + $.param(params, true);
|
||||
};
|
||||
|
||||
/**
|
||||
* Convert from relative URL to abstract URL based on current URL
|
||||
*
|
||||
* @param String URL
|
||||
* @return String
|
||||
*/
|
||||
this.convAbsUrl = function(url) {
|
||||
if (url.match(/^http/i)) {
|
||||
return url;
|
||||
}
|
||||
if (url.substr(0,2) === '//') {
|
||||
return window.location.protocol + url;
|
||||
}
|
||||
var root = window.location.protocol + '//' + window.location.host,
|
||||
reg = /[^\/]+\/\.\.\//,
|
||||
ret;
|
||||
if (url.substr(0, 1) === '/') {
|
||||
ret = root + url;
|
||||
} else {
|
||||
ret = root + window.location.pathname.replace(/\/[^\/]+$/, '/') + url;
|
||||
}
|
||||
ret = ret.replace('/./', '/');
|
||||
while(reg.test(ret)) {
|
||||
ret = ret.replace(reg, '');
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
|
||||
/**
|
||||
* Return file url for open in elFinder
|
||||
*
|
||||
@@ -6440,6 +6441,34 @@ elFinder.prototype = {
|
||||
return newItem;
|
||||
},
|
||||
|
||||
/**
|
||||
* Convert from relative URL to abstract URL based on current URL
|
||||
*
|
||||
* @param String URL
|
||||
* @return String
|
||||
*/
|
||||
convAbsUrl : function(url) {
|
||||
if (url.match(/^http/i)) {
|
||||
return url;
|
||||
}
|
||||
if (url.substr(0,2) === '//') {
|
||||
return window.location.protocol + url;
|
||||
}
|
||||
var root = window.location.protocol + '//' + window.location.host,
|
||||
reg = /[^\/]+\/\.\.\//,
|
||||
ret;
|
||||
if (url.substr(0, 1) === '/') {
|
||||
ret = root + url;
|
||||
} else {
|
||||
ret = root + window.location.pathname.replace(/\/[^\/]+$/, '/') + url;
|
||||
}
|
||||
ret = ret.replace('/./', '/');
|
||||
while(reg.test(ret)) {
|
||||
ret = ret.replace(reg, '');
|
||||
}
|
||||
return ret;
|
||||
},
|
||||
|
||||
navHash2Id : function(hash) {
|
||||
return this.navPrefix + hash;
|
||||
},
|
||||
@@ -6468,6 +6497,53 @@ elFinder.prototype = {
|
||||
return document.elementFromPoint(rect.left, rect.top)? true : false;
|
||||
},
|
||||
|
||||
/**
|
||||
* Load JavaScript files
|
||||
*
|
||||
* @param Array to load JavaScript file URLs
|
||||
* @param Function call back function on script loaded
|
||||
* @param Object Additional options to $.ajax
|
||||
* @return elFinder
|
||||
*/
|
||||
loadScript : function(urls, callback, opts) {
|
||||
var defOpts = {
|
||||
dataType : 'script',
|
||||
cache : true
|
||||
},
|
||||
success = null;
|
||||
if ($.isFunction(callback)) {
|
||||
success = function() { callback.apply(callback.caller || window); };
|
||||
}
|
||||
opts = $.isPlainObject(opts)? $.extend(defOpts, opts) : defOpts;
|
||||
(function appendScript() {
|
||||
$.ajax($.extend(opts, {
|
||||
url: urls.shift(),
|
||||
success: urls.length? appendScript : success
|
||||
}));
|
||||
})();
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Load CSS files
|
||||
*
|
||||
* @param Array to load CSS file URLs
|
||||
* @return elFinder
|
||||
*/
|
||||
loadCss : function(urls) {
|
||||
var self = this;
|
||||
if (typeof urls === 'string') {
|
||||
urls = [ urls ];
|
||||
}
|
||||
$.each(urls, function(i, url) {
|
||||
url = self.convAbsUrl(url).replace(/^https?:/i, '');
|
||||
if (! $("head > link[href='+url+']").length) {
|
||||
$('head').append('<link rel="stylesheet" type="text/css" href="' + url + '" />');
|
||||
}
|
||||
});
|
||||
return this;
|
||||
},
|
||||
|
||||
log : function(m) { window.console && window.console.log && window.console.log(m); return this; },
|
||||
|
||||
debug : function(type, m) {
|
||||
|
||||
@@ -127,6 +127,16 @@ elFinder.prototype._options = {
|
||||
*/
|
||||
lang : 'en',
|
||||
|
||||
/**
|
||||
* Auto load required CSS
|
||||
* `false` to disable this function or
|
||||
* CSS URL Array to load additional CSS files
|
||||
*
|
||||
* @type Boolean|Array
|
||||
* @default true
|
||||
*/
|
||||
cssAutoLoad : true,
|
||||
|
||||
/**
|
||||
* Additional css class for filemanager node.
|
||||
*
|
||||
|
||||
+10
-3
@@ -6,7 +6,11 @@
|
||||
* e.g. `<script data-main="./main.js" src="./require.js"></script>`
|
||||
**/
|
||||
(function(){
|
||||
var // Detect language (optional)
|
||||
var // jQuery and jQueryUI version
|
||||
jqver = '3.1.1',
|
||||
uiver = '1.12.1',
|
||||
|
||||
// Detect language (optional)
|
||||
lang = (function() {
|
||||
var locq = window.location.search,
|
||||
fullLang, locm, lang;
|
||||
@@ -35,6 +39,9 @@
|
||||
|
||||
// Start elFinder (REQUIRED)
|
||||
start = function(elFinder) {
|
||||
// load jQueryUI CSS
|
||||
elFinder.prototype.loadCss('//cdnjs.cloudflare.com/ajax/libs/jqueryui/'+uiver+'/themes/smoothness/jquery-ui.css');
|
||||
|
||||
$(function() {
|
||||
// Optional for Japanese decoder "extras/encoding-japanese.min"
|
||||
if (window.Encoding && Encoding.convert) {
|
||||
@@ -70,8 +77,8 @@
|
||||
require.config({
|
||||
baseUrl : 'js',
|
||||
paths : {
|
||||
'jquery' : '//cdnjs.cloudflare.com/ajax/libs/jquery/'+(ie8? '1.12.4' : '3.1.1')+'/jquery.min',
|
||||
'jquery-ui': '//cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min',
|
||||
'jquery' : '//cdnjs.cloudflare.com/ajax/libs/jquery/'+(ie8? '1.12.4' : jqver)+'/jquery.min',
|
||||
'jquery-ui': '//cdnjs.cloudflare.com/ajax/libs/jqueryui/'+uiver+'/jquery-ui.min',
|
||||
'elfinder' : 'elfinder.min',
|
||||
'elfinder.lang': [
|
||||
'i18n/elfinder.'+lang,
|
||||
|
||||
Reference in New Issue
Block a user