2012-03-05 14:07:38 +01:00
|
|
|
/**
|
|
|
|
* EGroupware clientside API object
|
|
|
|
*
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @package etemplate
|
|
|
|
* @subpackage api
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @author Andreas Stöckel (as AT stylite.de)
|
|
|
|
* @author Ralf Becker <RalfBecker@outdoor-training.de>
|
|
|
|
* @version $Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
/*egw:uses
|
|
|
|
egw_core;
|
2012-03-09 16:32:29 +01:00
|
|
|
egw_ready;
|
2012-03-05 14:07:38 +01:00
|
|
|
egw_debug;
|
|
|
|
*/
|
|
|
|
|
2013-10-08 10:55:15 +02:00
|
|
|
/**
|
|
|
|
* @augments Class
|
|
|
|
*/
|
|
|
|
egw.extend('files', egw.MODULE_WND_LOCAL, function(_app, _wnd)
|
|
|
|
{
|
2012-03-09 16:32:29 +01:00
|
|
|
var egw = this;
|
2012-03-05 14:07:38 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Array which contains all currently bound in javascript and css files.
|
|
|
|
*/
|
|
|
|
var files = {};
|
2013-02-13 17:26:42 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove optional timestamp attached directly as first query parameter, eg. /path/name.js?12345678[&other=val]
|
|
|
|
*
|
|
|
|
* Examples:
|
|
|
|
* /path/file.js --> /path/file.js
|
|
|
|
* /path/file.js?123456 --> /path/file.js
|
|
|
|
* /path/file.php?123456¶m=value --> /path/file.php?param=value
|
|
|
|
*
|
|
|
|
* @param _src url
|
|
|
|
* @return url with timestamp stripped off
|
|
|
|
*/
|
|
|
|
function removeTS(_src)
|
|
|
|
{
|
|
|
|
return _src.replace(/\?[0-9]+&?/, '?').replace(/\?$/, '');
|
|
|
|
}
|
2012-03-05 14:07:38 +01:00
|
|
|
|
|
|
|
return {
|
2013-10-08 10:55:15 +02:00
|
|
|
/**
|
|
|
|
* Load and execute javascript file(s) in order
|
|
|
|
*
|
|
|
|
* @memberOf egw
|
|
|
|
* @param string|array _jsFiles (array of) urls to include
|
|
|
|
* @param function _callback called after JS files are loaded and executed
|
|
|
|
* @param object _context
|
|
|
|
* @param string _prefix prefix for _jsFiles
|
|
|
|
*/
|
2013-02-13 17:26:42 +01:00
|
|
|
includeJS: function(_jsFiles, _callback, _context, _prefix) {
|
|
|
|
if (typeof _prefix === 'undefined')
|
|
|
|
{
|
|
|
|
_prefix = '';
|
|
|
|
}
|
2013-02-15 16:30:35 +01:00
|
|
|
// LABjs uses prefix only if url is not absolute, so removing leading / if necessary and add it to prefix
|
|
|
|
if (_prefix)
|
2012-03-05 14:07:38 +01:00
|
|
|
{
|
2013-02-15 16:30:35 +01:00
|
|
|
// Also allow including a single javascript file
|
|
|
|
if (typeof _jsFiles === 'string')
|
|
|
|
{
|
|
|
|
_jsFiles = [_jsFiles];
|
|
|
|
}
|
|
|
|
for(var i=0; i < _jsFiles.length; ++i)
|
|
|
|
{
|
|
|
|
if (_jsFiles[i].charAt(0) == '/') _jsFiles[i] = _jsFiles[i].substr(1);
|
|
|
|
}
|
|
|
|
if (_prefix.charAt(_prefix.length-1) != '/')
|
|
|
|
{
|
|
|
|
_prefix += '/';
|
|
|
|
}
|
2012-03-05 14:07:38 +01:00
|
|
|
}
|
2013-02-15 16:30:35 +01:00
|
|
|
// setting AlwaysPreserverOrder: true, 'til we have some other means of ensuring dependency resolution
|
2013-07-17 14:47:21 +02:00
|
|
|
(egw_LAB || $LAB.setOptions({AlwaysPreserveOrder:true,BasePath:_prefix})).script(_jsFiles).wait(function(){
|
2013-02-15 16:30:35 +01:00
|
|
|
_callback.call(_context);
|
|
|
|
});
|
2012-03-05 14:07:38 +01:00
|
|
|
},
|
|
|
|
|
2013-10-08 10:55:15 +02:00
|
|
|
/**
|
|
|
|
* Include a CSS file
|
|
|
|
*
|
|
|
|
* @param _cssFile full url of file to include
|
|
|
|
*/
|
2012-03-05 14:07:38 +01:00
|
|
|
includeCSS: function(_cssFile) {
|
|
|
|
//Check whether the requested file has already been included
|
2013-02-15 16:30:35 +01:00
|
|
|
var file = removeTS(_cssFile);
|
|
|
|
if (typeof files[file] === 'undefined')
|
2012-03-05 14:07:38 +01:00
|
|
|
{
|
2013-02-15 16:30:35 +01:00
|
|
|
files[file] = true;
|
2012-03-05 14:07:38 +01:00
|
|
|
|
|
|
|
// Create the node which is used to include the css fiel
|
2012-03-09 16:32:29 +01:00
|
|
|
var cssnode = _wnd.document.createElement('link');
|
2012-03-05 14:07:38 +01:00
|
|
|
cssnode.type = "text/css";
|
|
|
|
cssnode.rel = "stylesheet";
|
|
|
|
cssnode.href = _cssFile;
|
|
|
|
|
|
|
|
// Get the head node and append the newly created "link" node
|
|
|
|
// to it.
|
2012-03-09 16:32:29 +01:00
|
|
|
var head = _wnd.document.getElementsByTagName('head')[0];
|
2013-11-20 00:22:33 +01:00
|
|
|
if(jQuery('link[href="'+_cssFile+'"]',head).length == 0)
|
|
|
|
{
|
|
|
|
head.appendChild(cssnode);
|
|
|
|
}
|
2012-03-05 14:07:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|