更新前端文件
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
/** @license
|
||||
* RequireJS plugin for async dependency load like JSONP and Google Maps
|
||||
* Author: Miller Medeiros
|
||||
* Version: 0.1.2 (2014/02/24)
|
||||
* Released under the MIT license
|
||||
*/
|
||||
define(function(){
|
||||
|
||||
var DEFAULT_PARAM_NAME = 'callback',
|
||||
_uid = 0;
|
||||
|
||||
function injectScript(src){
|
||||
var s, t;
|
||||
s = document.createElement('script'); s.type = 'text/javascript'; s.async = true; s.src = src;
|
||||
t = document.getElementsByTagName('script')[0]; t.parentNode.insertBefore(s,t);
|
||||
}
|
||||
|
||||
function formatUrl(name, id){
|
||||
var paramRegex = /!(.+)/,
|
||||
url = name.replace(paramRegex, ''),
|
||||
param = (paramRegex.test(name))? name.replace(/.+!/, '') : DEFAULT_PARAM_NAME;
|
||||
url += (url.indexOf('?') < 0)? '?' : '&';
|
||||
return url + param +'='+ id;
|
||||
}
|
||||
|
||||
function uid() {
|
||||
_uid += 1;
|
||||
return '__async_req_'+ _uid +'__';
|
||||
}
|
||||
|
||||
return{
|
||||
load : function(name, req, onLoad, config){
|
||||
if(config.isBuild){
|
||||
onLoad(null); //avoid errors on the optimizer
|
||||
}else{
|
||||
var id = uid();
|
||||
//create a global variable that stores onLoad so callback
|
||||
//function can define new module after async load
|
||||
window[id] = onLoad;
|
||||
injectScript(formatUrl(req.toUrl(name), id));
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
@@ -0,0 +1,27 @@
|
||||
/** @license
|
||||
* Plugin to load JS files that have dependencies but aren't wrapped into
|
||||
* `define` calls.
|
||||
* Author: Miller Medeiros
|
||||
* Version: 0.1.0 (2011/12/13)
|
||||
* Released under the MIT license
|
||||
*/
|
||||
define(function () {
|
||||
|
||||
var rParts = /^(.*)\[([^\]]*)\]$/;
|
||||
|
||||
return {
|
||||
|
||||
//example: depend!bar[jquery,lib/foo]
|
||||
load : function(name, req, onLoad, config){
|
||||
var parts = rParts.exec(name);
|
||||
|
||||
req(parts[2].split(','), function(){
|
||||
req([parts[1]], function(mod){
|
||||
onLoad(mod);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
});
|
||||
@@ -0,0 +1,45 @@
|
||||
/** @license
|
||||
* RequireJS plugin for loading web fonts using the WebFont Loader
|
||||
* Author: Miller Medeiros
|
||||
* Version: 0.2.0 (2011/12/06)
|
||||
* Released under the MIT license
|
||||
*/
|
||||
define(['propertyParser'], function (propertyParser) {
|
||||
|
||||
var rParts = /^([^,]+),([^\|]+)\|?/;
|
||||
|
||||
function parseName(name) {
|
||||
var data = {},
|
||||
vendors = name.split('|'),
|
||||
n = vendors.length,
|
||||
match;
|
||||
|
||||
while (n--) {
|
||||
match = rParts.exec(vendors[n]);
|
||||
data[ match[1] ] = propertyParser.parseProperties(match[2]);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
// API
|
||||
return {
|
||||
|
||||
//example: font!google,families:[Tangerine,Cantarell,Yanone Kaffeesatz:700]
|
||||
load : function(name, req, onLoad, config){
|
||||
if (config.isBuild) {
|
||||
onLoad(null); //avoid errors on the optimizer
|
||||
} else {
|
||||
var data = parseName(name);
|
||||
data.active = onLoad;
|
||||
data.inactive = function(){
|
||||
onLoad(false);
|
||||
};
|
||||
req([(document.location.protocol === 'https:'? 'https' : 'http') +'://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js'], function(){
|
||||
WebFont.load(data);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
});
|
||||
@@ -0,0 +1,38 @@
|
||||
/** @license
|
||||
* RequireJS plugin for loading Google Ajax API modules thru `google.load`
|
||||
* Author: Miller Medeiros
|
||||
* Version: 0.2.0 (2011/12/06)
|
||||
* Released under the MIT license
|
||||
*/
|
||||
define(['async', 'propertyParser'], function (async, propertyParser) {
|
||||
|
||||
var rParts = /^([^,]+)(?:,([^,]+))?(?:,(.+))?/;
|
||||
|
||||
function parseName(name){
|
||||
var match = rParts.exec(name),
|
||||
data = {
|
||||
moduleName : match[1],
|
||||
version : match[2] || '1'
|
||||
};
|
||||
data.settings = propertyParser.parseProperties(match[3]);
|
||||
return data;
|
||||
}
|
||||
|
||||
return {
|
||||
load : function(name, req, onLoad, config){
|
||||
if (config.isBuild) {
|
||||
onLoad(null); //avoid errors on the optimizer
|
||||
} else {
|
||||
var data = parseName(name),
|
||||
settings = data.settings;
|
||||
|
||||
settings.callback = onLoad;
|
||||
|
||||
req(['async!'+ (document.location.protocol === 'https:'? 'https' : 'http') +'://www.google.com/jsapi'], function(){
|
||||
google.load(data.moduleName, data.version, settings);
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
});
|
||||
@@ -0,0 +1,53 @@
|
||||
/** @license
|
||||
* RequireJS Image Plugin
|
||||
* Author: Miller Medeiros
|
||||
* Version: 0.2.2 (2013/02/08)
|
||||
* Released under the MIT license
|
||||
*/
|
||||
define(function(){
|
||||
|
||||
var CACHE_BUST_QUERY_PARAM = 'bust',
|
||||
CACHE_BUST_FLAG = '!bust',
|
||||
RELATIVE_FLAG = '!rel';
|
||||
|
||||
function noop(){}
|
||||
|
||||
function cacheBust(url){
|
||||
url = url.replace(CACHE_BUST_FLAG, '');
|
||||
url += (url.indexOf('?') < 0)? '?' : '&';
|
||||
return url + CACHE_BUST_QUERY_PARAM +'='+ Math.round(2147483647 * Math.random());
|
||||
}
|
||||
|
||||
return {
|
||||
load : function(name, req, onLoad, config){
|
||||
var img;
|
||||
if(config.isBuild){
|
||||
onLoad(null); //avoid errors on the optimizer since it can't inline image files
|
||||
}else{
|
||||
img = new Image();
|
||||
img.onerror = function (err) {
|
||||
onLoad.error(err);
|
||||
};
|
||||
img.onload = function(evt){
|
||||
onLoad(img);
|
||||
try {
|
||||
delete img.onload; //release memory - suggested by John Hann
|
||||
} catch(err) {
|
||||
img.onload = noop; // IE7 :(
|
||||
}
|
||||
};
|
||||
if (name.indexOf(RELATIVE_FLAG) !== -1) {
|
||||
//load image relative to module path / baseUrl
|
||||
img.src = req.toUrl( name.replace(RELATIVE_FLAG, '') );
|
||||
} else {
|
||||
img.src = name;
|
||||
}
|
||||
}
|
||||
},
|
||||
normalize : function (name, normalize) {
|
||||
//used normalize to avoid caching references to a "cache busted" request
|
||||
return (name.indexOf(CACHE_BUST_FLAG) === -1)? name : cacheBust(name);
|
||||
}
|
||||
};
|
||||
|
||||
});
|
||||
@@ -0,0 +1,66 @@
|
||||
/** @license
|
||||
* RequireJS plugin for loading JSON files
|
||||
* - depends on Text plugin and it was HEAVILY "inspired" by it as well.
|
||||
* Author: Miller Medeiros
|
||||
* Version: 0.4.0 (2014/04/10)
|
||||
* Released under the MIT license
|
||||
*/
|
||||
define(['text'], function(text){
|
||||
|
||||
var CACHE_BUST_QUERY_PARAM = 'bust',
|
||||
CACHE_BUST_FLAG = '!bust',
|
||||
jsonParse = (typeof JSON !== 'undefined' && typeof JSON.parse === 'function')? JSON.parse : function(val){
|
||||
return eval('('+ val +')'); //quick and dirty
|
||||
},
|
||||
buildMap = {};
|
||||
|
||||
function cacheBust(url){
|
||||
url = url.replace(CACHE_BUST_FLAG, '');
|
||||
url += (url.indexOf('?') < 0)? '?' : '&';
|
||||
return url + CACHE_BUST_QUERY_PARAM +'='+ Math.round(2147483647 * Math.random());
|
||||
}
|
||||
|
||||
//API
|
||||
return {
|
||||
|
||||
load : function(name, req, onLoad, config) {
|
||||
if (( config.isBuild && (config.inlineJSON === false || name.indexOf(CACHE_BUST_QUERY_PARAM +'=') !== -1)) || (req.toUrl(name).indexOf('empty:') === 0)) {
|
||||
//avoid inlining cache busted JSON or if inlineJSON:false
|
||||
//and don't inline files marked as empty!
|
||||
onLoad(null);
|
||||
} else {
|
||||
text.get(req.toUrl(name), function(data){
|
||||
if (config.isBuild) {
|
||||
buildMap[name] = data;
|
||||
onLoad(data);
|
||||
} else {
|
||||
onLoad(jsonParse(data));
|
||||
}
|
||||
},
|
||||
onLoad.error, {
|
||||
accept: 'application/json'
|
||||
}
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
normalize : function (name, normalize) {
|
||||
// used normalize to avoid caching references to a "cache busted" request
|
||||
if (name.indexOf(CACHE_BUST_FLAG) !== -1) {
|
||||
name = cacheBust(name);
|
||||
}
|
||||
// resolve any relative paths
|
||||
return normalize(name);
|
||||
},
|
||||
|
||||
//write method based on RequireJS official text plugin by James Burke
|
||||
//https://github.com/jrburke/requirejs/blob/master/text.js
|
||||
write : function(pluginName, moduleName, write){
|
||||
if(moduleName in buildMap){
|
||||
var content = buildMap[moduleName];
|
||||
write('define("'+ pluginName +'!'+ moduleName +'", function(){ return '+ content +';});\n');
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
});
|
||||
@@ -0,0 +1,59 @@
|
||||
/** @license
|
||||
* RequireJS plugin for loading Markdown files and converting them into HTML.
|
||||
* Author: Miller Medeiros
|
||||
* Version: 0.1.1 (2012/02/17)
|
||||
* Released under the MIT license
|
||||
*/
|
||||
|
||||
// NOTE :: if you don't need to load markdown files in production outside of
|
||||
// the build, precompile them into modules and set
|
||||
// `pragmasOnSave.excludeMdown=true`
|
||||
|
||||
define(
|
||||
[
|
||||
//>>excludeStart('excludeMdown', pragmas.excludeMdown)
|
||||
'text',
|
||||
'markdownConverter'
|
||||
//>>excludeEnd('excludeMdown')
|
||||
],
|
||||
function (
|
||||
//>>excludeStart('excludeMdown', pragmas.excludeMdown)
|
||||
text, markdownConverter
|
||||
//>>excludeEnd('excludeMdown')
|
||||
) {
|
||||
|
||||
//>>excludeStart('excludeMdown', pragmas.excludeMdown)
|
||||
var buildMap = {};
|
||||
//>>excludeEnd('excludeMdown')
|
||||
|
||||
//API
|
||||
return {
|
||||
|
||||
load : function(name, req, onLoad, config) {
|
||||
//>>excludeStart('excludeMdown', pragmas.excludeMdown)
|
||||
text.get(req.toUrl(name), function(data){
|
||||
data = markdownConverter.makeHtml(data);
|
||||
if (config.isBuild) {
|
||||
buildMap[name] = data;
|
||||
onLoad(data);
|
||||
} else {
|
||||
onLoad(data);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
//write method based on RequireJS official text plugin by James Burke
|
||||
//https://github.com/jrburke/requirejs/blob/master/text.js
|
||||
write : function(pluginName, moduleName, write){
|
||||
if(moduleName in buildMap){
|
||||
var content = text.jsEscape(buildMap[moduleName]);
|
||||
write.asModule(pluginName + "!" + moduleName,
|
||||
"define(function () { return '" +
|
||||
content +
|
||||
"';});\n");
|
||||
}
|
||||
//>>excludeEnd('excludeMdown')
|
||||
}
|
||||
|
||||
};
|
||||
});
|
||||
@@ -0,0 +1,28 @@
|
||||
/** @license
|
||||
* RequireJS plugin for loading files without adding the JS extension, useful for
|
||||
* JSONP services and any other kind of resource that already contain a file
|
||||
* extension or that shouldn't have one (like dynamic scripts).
|
||||
* Author: Miller Medeiros
|
||||
* Version: 0.3.1 (2011/12/07)
|
||||
* Released under the MIT license
|
||||
*/
|
||||
define(function(){
|
||||
|
||||
var QUERY_PARAM = 'noext';
|
||||
|
||||
//API
|
||||
return {
|
||||
load : function(name, req, onLoad, config){
|
||||
req([req.toUrl(name)], function(mod){
|
||||
onLoad(mod);
|
||||
});
|
||||
},
|
||||
normalize : function(name, norm){
|
||||
//append query string to avoid adding .js extension
|
||||
//needs to be on normalize otherwise it won't work after build
|
||||
name += (name.indexOf('?') < 0)? '?' : '&';
|
||||
return name + QUERY_PARAM +'=1';
|
||||
}
|
||||
|
||||
};
|
||||
});
|
||||
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* Basic parser for URL properties
|
||||
* @author Miller Medeiros
|
||||
* @version 0.1.0 (2011/12/06)
|
||||
* MIT license
|
||||
*/
|
||||
define(function(){
|
||||
|
||||
var rProps = /([\w-]+)\s*:\s*(?:(\[[^\]]+\])|([^,]+)),?/g, //match "foo:bar" and "lorem:[ipsum,dolor]" capturing name as $1 and val as $2 or $3
|
||||
rArr = /^\[([^\]]+)\]$/; //match "[foo,bar]" capturing "foo,bar"
|
||||
|
||||
function parseProperties(str){
|
||||
var match, obj = {};
|
||||
while (match = rProps.exec(str)) {
|
||||
obj[ match[1] ] = typecastVal(match[2] || match[3]);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
function typecastVal(val){
|
||||
if (rArr.test(val)){
|
||||
val = val.replace(rArr, '$1').split(',');
|
||||
} else if (val === 'null'){
|
||||
val = null;
|
||||
} else if (val === 'false'){
|
||||
val = false;
|
||||
} else if (val === 'true'){
|
||||
val = true;
|
||||
} else if (val === '' || val === "''" || val === '""'){
|
||||
val = '';
|
||||
} else if (! isNaN(val)) {
|
||||
//isNaN('') == false
|
||||
val = +val;
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
//API
|
||||
return {
|
||||
parseProperties : parseProperties,
|
||||
typecastVal : typecastVal
|
||||
};
|
||||
});
|
||||
Reference in New Issue
Block a user