initial commit of poker game
This commit is contained in:
2
web-server/public/js/libs/backbone-min.js
vendored
Normal file
2
web-server/public/js/libs/backbone-min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
6
web-server/public/js/libs/bootstrap.min.js
vendored
Normal file
6
web-server/public/js/libs/bootstrap.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
4
web-server/public/js/libs/jquery.js
vendored
Normal file
4
web-server/public/js/libs/jquery.js
vendored
Normal file
File diff suppressed because one or more lines are too long
456
web-server/public/js/libs/pomeloclient.js
Normal file
456
web-server/public/js/libs/pomeloclient.js
Normal file
@@ -0,0 +1,456 @@
|
||||
(function() {
|
||||
var isArray = Array.isArray;
|
||||
|
||||
var root = this;
|
||||
|
||||
function EventEmitter() {
|
||||
}
|
||||
|
||||
|
||||
if (typeof module !== 'undefined' && module.exports) {
|
||||
module.exports.EventEmitter = EventEmitter;
|
||||
}
|
||||
else {
|
||||
root = window;
|
||||
root.EventEmitter = EventEmitter;
|
||||
}
|
||||
|
||||
// By default EventEmitters will print a warning if more than
|
||||
// 10 listeners are added to it. This is a useful default which
|
||||
// helps finding memory leaks.
|
||||
//
|
||||
// Obviously not all Emitters should be limited to 10. This function allows
|
||||
// that to be increased. Set to zero for unlimited.
|
||||
var defaultMaxListeners = 10;
|
||||
EventEmitter.prototype.setMaxListeners = function(n) {
|
||||
if (!this._events) this._events = {};
|
||||
this._maxListeners = n;
|
||||
};
|
||||
|
||||
|
||||
EventEmitter.prototype.emit = function() {
|
||||
var type = arguments[0];
|
||||
// If there is no 'error' event listener then throw.
|
||||
if (type === 'error') {
|
||||
if (!this._events || !this._events.error ||
|
||||
(isArray(this._events.error) && !this._events.error.length))
|
||||
{
|
||||
if (this.domain) {
|
||||
var er = arguments[1];
|
||||
er.domain_emitter = this;
|
||||
er.domain = this.domain;
|
||||
er.domain_thrown = false;
|
||||
this.domain.emit('error', er);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (arguments[1] instanceof Error) {
|
||||
throw arguments[1]; // Unhandled 'error' event
|
||||
} else {
|
||||
throw new Error("Uncaught, unspecified 'error' event.");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!this._events) return false;
|
||||
var handler = this._events[type];
|
||||
if (!handler) return false;
|
||||
|
||||
if (typeof handler == 'function') {
|
||||
if (this.domain) {
|
||||
this.domain.enter();
|
||||
}
|
||||
switch (arguments.length) {
|
||||
// fast cases
|
||||
case 1:
|
||||
handler.call(this);
|
||||
break;
|
||||
case 2:
|
||||
handler.call(this, arguments[1]);
|
||||
break;
|
||||
case 3:
|
||||
handler.call(this, arguments[1], arguments[2]);
|
||||
break;
|
||||
// slower
|
||||
default:
|
||||
var l = arguments.length;
|
||||
var args = new Array(l - 1);
|
||||
for (var i = 1; i < l; i++) args[i - 1] = arguments[i];
|
||||
handler.apply(this, args);
|
||||
}
|
||||
if (this.domain) {
|
||||
this.domain.exit();
|
||||
}
|
||||
return true;
|
||||
|
||||
} else if (isArray(handler)) {
|
||||
if (this.domain) {
|
||||
this.domain.enter();
|
||||
}
|
||||
var l = arguments.length;
|
||||
var args = new Array(l - 1);
|
||||
for (var i = 1; i < l; i++) args[i - 1] = arguments[i];
|
||||
|
||||
var listeners = handler.slice();
|
||||
for (var i = 0, l = listeners.length; i < l; i++) {
|
||||
listeners[i].apply(this, args);
|
||||
}
|
||||
if (this.domain) {
|
||||
this.domain.exit();
|
||||
}
|
||||
return true;
|
||||
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
EventEmitter.prototype.addListener = function(type, listener) {
|
||||
if ('function' !== typeof listener) {
|
||||
throw new Error('addListener only takes instances of Function');
|
||||
}
|
||||
|
||||
if (!this._events) this._events = {};
|
||||
|
||||
// To avoid recursion in the case that type == "newListeners"! Before
|
||||
// adding it to the listeners, first emit "newListeners".
|
||||
this.emit('newListener', type, typeof listener.listener === 'function' ?
|
||||
listener.listener : listener);
|
||||
|
||||
if (!this._events[type]) {
|
||||
// Optimize the case of one listener. Don't need the extra array object.
|
||||
this._events[type] = listener;
|
||||
} else if (isArray(this._events[type])) {
|
||||
|
||||
// If we've already got an array, just append.
|
||||
this._events[type].push(listener);
|
||||
|
||||
} else {
|
||||
// Adding the second element, need to change to array.
|
||||
this._events[type] = [this._events[type], listener];
|
||||
|
||||
}
|
||||
|
||||
// Check for listener leak
|
||||
if (isArray(this._events[type]) && !this._events[type].warned) {
|
||||
var m;
|
||||
if (this._maxListeners !== undefined) {
|
||||
m = this._maxListeners;
|
||||
} else {
|
||||
m = defaultMaxListeners;
|
||||
}
|
||||
|
||||
if (m && m > 0 && this._events[type].length > m) {
|
||||
this._events[type].warned = true;
|
||||
console.error('(node) warning: possible EventEmitter memory ' +
|
||||
'leak detected. %d listeners added. ' +
|
||||
'Use emitter.setMaxListeners() to increase limit.',
|
||||
this._events[type].length);
|
||||
console.trace();
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
EventEmitter.prototype.on = EventEmitter.prototype.addListener;
|
||||
|
||||
EventEmitter.prototype.once = function(type, listener) {
|
||||
if ('function' !== typeof listener) {
|
||||
throw new Error('.once only takes instances of Function');
|
||||
}
|
||||
|
||||
var self = this;
|
||||
function g() {
|
||||
self.removeListener(type, g);
|
||||
listener.apply(this, arguments);
|
||||
};
|
||||
|
||||
g.listener = listener;
|
||||
self.on(type, g);
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
EventEmitter.prototype.removeListener = function(type, listener) {
|
||||
if ('function' !== typeof listener) {
|
||||
throw new Error('removeListener only takes instances of Function');
|
||||
}
|
||||
|
||||
// does not use listeners(), so no side effect of creating _events[type]
|
||||
if (!this._events || !this._events[type]) return this;
|
||||
|
||||
var list = this._events[type];
|
||||
|
||||
if (isArray(list)) {
|
||||
var position = -1;
|
||||
for (var i = 0, length = list.length; i < length; i++) {
|
||||
if (list[i] === listener ||
|
||||
(list[i].listener && list[i].listener === listener))
|
||||
{
|
||||
position = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (position < 0) return this;
|
||||
list.splice(position, 1);
|
||||
} else if (list === listener ||
|
||||
(list.listener && list.listener === listener))
|
||||
{
|
||||
delete this._events[type];
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
EventEmitter.prototype.removeAllListeners = function(type) {
|
||||
if (arguments.length === 0) {
|
||||
this._events = {};
|
||||
return this;
|
||||
}
|
||||
|
||||
var events = this._events && this._events[type];
|
||||
if (!events) return this;
|
||||
|
||||
if (isArray(events)) {
|
||||
events.splice(0);
|
||||
} else {
|
||||
this._events[type] = null;
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
EventEmitter.prototype.listeners = function(type) {
|
||||
if (!this._events) this._events = {};
|
||||
if (!this._events[type]) this._events[type] = [];
|
||||
if (!isArray(this._events[type])) {
|
||||
this._events[type] = [this._events[type]];
|
||||
}
|
||||
return this._events[type];
|
||||
}
|
||||
})();
|
||||
|
||||
(function (exports, global) {
|
||||
|
||||
var Protocol = exports;
|
||||
|
||||
var HEADER = 5;
|
||||
|
||||
var Message = function(id,route,body){
|
||||
this.id = id;
|
||||
this.route = route;
|
||||
this.body = body;
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
*pomele client encode
|
||||
* id message id;
|
||||
* route message route
|
||||
* msg message body
|
||||
* socketio current support string
|
||||
*
|
||||
*/
|
||||
Protocol.encode = function(id,route,msg){
|
||||
var msgStr = JSON.stringify(msg);
|
||||
if (route.length>255) { throw new Error('route maxlength is overflow'); }
|
||||
var byteArray = new Uint16Array(HEADER + route.length + msgStr.length);
|
||||
var index = 0;
|
||||
byteArray[index++] = (id>>24) & 0xFF;
|
||||
byteArray[index++] = (id>>16) & 0xFF;
|
||||
byteArray[index++] = (id>>8) & 0xFF;
|
||||
byteArray[index++] = id & 0xFF;
|
||||
byteArray[index++] = route.length & 0xFF;
|
||||
for(var i = 0;i<route.length;i++){
|
||||
byteArray[index++] = route.charCodeAt(i);
|
||||
}
|
||||
for (var i = 0; i < msgStr.length; i++) {
|
||||
byteArray[index++] = msgStr.charCodeAt(i);
|
||||
}
|
||||
return bt2Str(byteArray,0,byteArray.length);
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*client decode
|
||||
*msg String data
|
||||
*return Message Object
|
||||
*/
|
||||
Protocol.decode = function(msg){
|
||||
var idx, len = msg.length, arr = new Array( len );
|
||||
for ( idx = 0 ; idx < len ; ++idx ) {
|
||||
arr[idx] = msg.charCodeAt(idx);
|
||||
}
|
||||
var index = 0;
|
||||
var buf = new Uint16Array(arr);
|
||||
var id = ((buf[index++] <<24) | (buf[index++]) << 16 | (buf[index++]) << 8 | buf[index++]) >>>0;
|
||||
var routeLen = buf[HEADER-1];
|
||||
var route = bt2Str(buf,HEADER, routeLen+HEADER);
|
||||
var body = bt2Str(buf,routeLen+HEADER,buf.length);
|
||||
return new Message(id,route,body);
|
||||
};
|
||||
|
||||
var bt2Str = function(byteArray,start,end) {
|
||||
var result = "";
|
||||
for(var i = start; i < byteArray.length && i<end; i++) {
|
||||
result = result + String.fromCharCode(byteArray[i]);
|
||||
};
|
||||
return result;
|
||||
}
|
||||
|
||||
})('object' === typeof module ? module.exports : (this.Protocol = {}), this);
|
||||
|
||||
(function() {
|
||||
if (typeof Object.create !== 'function') {
|
||||
Object.create = function (o) {
|
||||
function F() {}
|
||||
F.prototype = o;
|
||||
return new F();
|
||||
};
|
||||
}
|
||||
|
||||
var root = window;
|
||||
var pomelo = Object.create(EventEmitter.prototype); // object extend from object
|
||||
root.pomelo = pomelo;
|
||||
var socket = null;
|
||||
var id = 1;
|
||||
var callbacks = {};
|
||||
|
||||
pomelo.init = function(params, cb){
|
||||
pomelo.params = params;
|
||||
params.debug = true;
|
||||
var host = params.host;
|
||||
var port = params.port;
|
||||
|
||||
var url = 'ws://' + host;
|
||||
if(port) {
|
||||
url += ':' + port;
|
||||
}
|
||||
|
||||
socket = io.connect(url, {'force new connection': true, reconnect: false});
|
||||
|
||||
socket.on('connect', function(){
|
||||
console.log('[pomeloclient.init] websocket connected!');
|
||||
if (cb) {
|
||||
cb(socket);
|
||||
}
|
||||
});
|
||||
|
||||
socket.on('reconnect', function() {
|
||||
console.log('reconnect');
|
||||
});
|
||||
|
||||
socket.on('message', function(data){
|
||||
if(typeof data === 'string') {
|
||||
data = JSON.parse(data);
|
||||
}
|
||||
if(data instanceof Array) {
|
||||
processMessageBatch(pomelo, data);
|
||||
} else {
|
||||
processMessage(pomelo, data);
|
||||
}
|
||||
});
|
||||
|
||||
socket.on('error', function(err) {
|
||||
console.log(err);
|
||||
});
|
||||
|
||||
socket.on('disconnect', function(reason) {
|
||||
pomelo.emit('disconnect', reason);
|
||||
});
|
||||
};
|
||||
|
||||
pomelo.disconnect = function() {
|
||||
if(socket) {
|
||||
socket.disconnect();
|
||||
socket = null;
|
||||
}
|
||||
};
|
||||
|
||||
pomelo.request = function(route) {
|
||||
if(!route) {
|
||||
return;
|
||||
}
|
||||
var msg = {};
|
||||
var cb;
|
||||
arguments = Array.prototype.slice.apply(arguments);
|
||||
if(arguments.length === 2){
|
||||
if(typeof arguments[1] === 'function'){
|
||||
cb = arguments[1];
|
||||
}else if(typeof arguments[1] === 'object'){
|
||||
msg = arguments[1];
|
||||
}
|
||||
}else if(arguments.length === 3){
|
||||
msg = arguments[1];
|
||||
cb = arguments[2];
|
||||
}
|
||||
msg = filter(msg,route);
|
||||
id++;
|
||||
callbacks[id] = cb;
|
||||
var sg = Protocol.encode(id,route,msg);
|
||||
socket.send(sg);
|
||||
};
|
||||
|
||||
pomelo.notify = function(route,msg) {
|
||||
this.request(route, msg);
|
||||
};
|
||||
|
||||
var processMessage = function(pomelo, msg) {
|
||||
var route;
|
||||
if(msg.id) {
|
||||
//if have a id then find the callback function with the request
|
||||
var cb = callbacks[msg.id];
|
||||
|
||||
delete callbacks[msg.id];
|
||||
if(typeof cb !== 'function') {
|
||||
console.log('[pomeloclient.processMessage] cb is not a function for request ' + msg.id);
|
||||
return;
|
||||
}
|
||||
|
||||
cb(msg.body);
|
||||
return;
|
||||
}
|
||||
|
||||
// server push message or old format message
|
||||
processCall(msg);
|
||||
|
||||
//if no id then it should be a server push message
|
||||
function processCall(msg) {
|
||||
var route = msg.route;
|
||||
if(!!route) {
|
||||
if (!!msg.body) {
|
||||
var body = msg.body.body;
|
||||
if (!body) {body = msg.body;}
|
||||
pomelo.emit(route, body);
|
||||
} else {
|
||||
pomelo.emit(route,msg);
|
||||
}
|
||||
} else {
|
||||
pomelo.emit(msg.body.route,msg.body);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var processMessageBatch = function(pomelo, msgs) {
|
||||
for(var i=0, l=msgs.length; i<l; i++) {
|
||||
processMessage(pomelo, msgs[i]);
|
||||
}
|
||||
};
|
||||
|
||||
function filter(msg,route){
|
||||
if(route.indexOf('area.') === 0){
|
||||
msg.areaId = pomelo.areaId;
|
||||
}
|
||||
|
||||
msg.timestamp = Date.now();
|
||||
return msg;
|
||||
}
|
||||
|
||||
|
||||
})();
|
36
web-server/public/js/libs/require.js
Normal file
36
web-server/public/js/libs/require.js
Normal file
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
RequireJS 2.1.14 Copyright (c) 2010-2014, The Dojo Foundation All Rights Reserved.
|
||||
Available via the MIT or new BSD license.
|
||||
see: http://github.com/jrburke/requirejs for details
|
||||
*/
|
||||
var requirejs,require,define;
|
||||
(function(ba){function G(b){return"[object Function]"===K.call(b)}function H(b){return"[object Array]"===K.call(b)}function v(b,c){if(b){var d;for(d=0;d<b.length&&(!b[d]||!c(b[d],d,b));d+=1);}}function T(b,c){if(b){var d;for(d=b.length-1;-1<d&&(!b[d]||!c(b[d],d,b));d-=1);}}function t(b,c){return fa.call(b,c)}function m(b,c){return t(b,c)&&b[c]}function B(b,c){for(var d in b)if(t(b,d)&&c(b[d],d))break}function U(b,c,d,e){c&&B(c,function(c,g){if(d||!t(b,g))e&&"object"===typeof c&&c&&!H(c)&&!G(c)&&!(c instanceof
|
||||
RegExp)?(b[g]||(b[g]={}),U(b[g],c,d,e)):b[g]=c});return b}function u(b,c){return function(){return c.apply(b,arguments)}}function ca(b){throw b;}function da(b){if(!b)return b;var c=ba;v(b.split("."),function(b){c=c[b]});return c}function C(b,c,d,e){c=Error(c+"\nhttp://requirejs.org/docs/errors.html#"+b);c.requireType=b;c.requireModules=e;d&&(c.originalError=d);return c}function ga(b){function c(a,k,b){var f,l,c,d,e,g,i,p,k=k&&k.split("/"),h=j.map,n=h&&h["*"];if(a){a=a.split("/");l=a.length-1;j.nodeIdCompat&&
|
||||
Q.test(a[l])&&(a[l]=a[l].replace(Q,""));"."===a[0].charAt(0)&&k&&(l=k.slice(0,k.length-1),a=l.concat(a));l=a;for(c=0;c<l.length;c++)if(d=l[c],"."===d)l.splice(c,1),c-=1;else if(".."===d&&!(0===c||1==c&&".."===l[2]||".."===l[c-1])&&0<c)l.splice(c-1,2),c-=2;a=a.join("/")}if(b&&h&&(k||n)){l=a.split("/");c=l.length;a:for(;0<c;c-=1){e=l.slice(0,c).join("/");if(k)for(d=k.length;0<d;d-=1)if(b=m(h,k.slice(0,d).join("/")))if(b=m(b,e)){f=b;g=c;break a}!i&&(n&&m(n,e))&&(i=m(n,e),p=c)}!f&&i&&(f=i,g=p);f&&(l.splice(0,
|
||||
g,f),a=l.join("/"))}return(f=m(j.pkgs,a))?f:a}function d(a){z&&v(document.getElementsByTagName("script"),function(k){if(k.getAttribute("data-requiremodule")===a&&k.getAttribute("data-requirecontext")===i.contextName)return k.parentNode.removeChild(k),!0})}function e(a){var k=m(j.paths,a);if(k&&H(k)&&1<k.length)return k.shift(),i.require.undef(a),i.makeRequire(null,{skipMap:!0})([a]),!0}function n(a){var k,c=a?a.indexOf("!"):-1;-1<c&&(k=a.substring(0,c),a=a.substring(c+1,a.length));return[k,a]}function p(a,
|
||||
k,b,f){var l,d,e=null,g=k?k.name:null,j=a,p=!0,h="";a||(p=!1,a="_@r"+(K+=1));a=n(a);e=a[0];a=a[1];e&&(e=c(e,g,f),d=m(r,e));a&&(e?h=d&&d.normalize?d.normalize(a,function(a){return c(a,g,f)}):-1===a.indexOf("!")?c(a,g,f):a:(h=c(a,g,f),a=n(h),e=a[0],h=a[1],b=!0,l=i.nameToUrl(h)));b=e&&!d&&!b?"_unnormalized"+(O+=1):"";return{prefix:e,name:h,parentMap:k,unnormalized:!!b,url:l,originalName:j,isDefine:p,id:(e?e+"!"+h:h)+b}}function s(a){var k=a.id,b=m(h,k);b||(b=h[k]=new i.Module(a));return b}function q(a,
|
||||
k,b){var f=a.id,c=m(h,f);if(t(r,f)&&(!c||c.defineEmitComplete))"defined"===k&&b(r[f]);else if(c=s(a),c.error&&"error"===k)b(c.error);else c.on(k,b)}function w(a,b){var c=a.requireModules,f=!1;if(b)b(a);else if(v(c,function(b){if(b=m(h,b))b.error=a,b.events.error&&(f=!0,b.emit("error",a))}),!f)g.onError(a)}function x(){R.length&&(ha.apply(A,[A.length,0].concat(R)),R=[])}function y(a){delete h[a];delete V[a]}function F(a,b,c){var f=a.map.id;a.error?a.emit("error",a.error):(b[f]=!0,v(a.depMaps,function(f,
|
||||
d){var e=f.id,g=m(h,e);g&&(!a.depMatched[d]&&!c[e])&&(m(b,e)?(a.defineDep(d,r[e]),a.check()):F(g,b,c))}),c[f]=!0)}function D(){var a,b,c=(a=1E3*j.waitSeconds)&&i.startTime+a<(new Date).getTime(),f=[],l=[],g=!1,h=!0;if(!W){W=!0;B(V,function(a){var i=a.map,j=i.id;if(a.enabled&&(i.isDefine||l.push(a),!a.error))if(!a.inited&&c)e(j)?g=b=!0:(f.push(j),d(j));else if(!a.inited&&(a.fetched&&i.isDefine)&&(g=!0,!i.prefix))return h=!1});if(c&&f.length)return a=C("timeout","Load timeout for modules: "+f,null,
|
||||
f),a.contextName=i.contextName,w(a);h&&v(l,function(a){F(a,{},{})});if((!c||b)&&g)if((z||ea)&&!X)X=setTimeout(function(){X=0;D()},50);W=!1}}function E(a){t(r,a[0])||s(p(a[0],null,!0)).init(a[1],a[2])}function I(a){var a=a.currentTarget||a.srcElement,b=i.onScriptLoad;a.detachEvent&&!Y?a.detachEvent("onreadystatechange",b):a.removeEventListener("load",b,!1);b=i.onScriptError;(!a.detachEvent||Y)&&a.removeEventListener("error",b,!1);return{node:a,id:a&&a.getAttribute("data-requiremodule")}}function J(){var a;
|
||||
for(x();A.length;){a=A.shift();if(null===a[0])return w(C("mismatch","Mismatched anonymous define() module: "+a[a.length-1]));E(a)}}var W,Z,i,L,X,j={waitSeconds:7,baseUrl:"./",paths:{},bundles:{},pkgs:{},shim:{},config:{}},h={},V={},$={},A=[],r={},S={},aa={},K=1,O=1;L={require:function(a){return a.require?a.require:a.require=i.makeRequire(a.map)},exports:function(a){a.usingExports=!0;if(a.map.isDefine)return a.exports?r[a.map.id]=a.exports:a.exports=r[a.map.id]={}},module:function(a){return a.module?
|
||||
a.module:a.module={id:a.map.id,uri:a.map.url,config:function(){return m(j.config,a.map.id)||{}},exports:a.exports||(a.exports={})}}};Z=function(a){this.events=m($,a.id)||{};this.map=a;this.shim=m(j.shim,a.id);this.depExports=[];this.depMaps=[];this.depMatched=[];this.pluginMaps={};this.depCount=0};Z.prototype={init:function(a,b,c,f){f=f||{};if(!this.inited){this.factory=b;if(c)this.on("error",c);else this.events.error&&(c=u(this,function(a){this.emit("error",a)}));this.depMaps=a&&a.slice(0);this.errback=
|
||||
c;this.inited=!0;this.ignore=f.ignore;f.enabled||this.enabled?this.enable():this.check()}},defineDep:function(a,b){this.depMatched[a]||(this.depMatched[a]=!0,this.depCount-=1,this.depExports[a]=b)},fetch:function(){if(!this.fetched){this.fetched=!0;i.startTime=(new Date).getTime();var a=this.map;if(this.shim)i.makeRequire(this.map,{enableBuildCallback:!0})(this.shim.deps||[],u(this,function(){return a.prefix?this.callPlugin():this.load()}));else return a.prefix?this.callPlugin():this.load()}},load:function(){var a=
|
||||
this.map.url;S[a]||(S[a]=!0,i.load(this.map.id,a))},check:function(){if(this.enabled&&!this.enabling){var a,b,c=this.map.id;b=this.depExports;var f=this.exports,l=this.factory;if(this.inited)if(this.error)this.emit("error",this.error);else{if(!this.defining){this.defining=!0;if(1>this.depCount&&!this.defined){if(G(l)){if(this.events.error&&this.map.isDefine||g.onError!==ca)try{f=i.execCb(c,l,b,f)}catch(d){a=d}else f=i.execCb(c,l,b,f);this.map.isDefine&&void 0===f&&((b=this.module)?f=b.exports:this.usingExports&&
|
||||
(f=this.exports));if(a)return a.requireMap=this.map,a.requireModules=this.map.isDefine?[this.map.id]:null,a.requireType=this.map.isDefine?"define":"require",w(this.error=a)}else f=l;this.exports=f;if(this.map.isDefine&&!this.ignore&&(r[c]=f,g.onResourceLoad))g.onResourceLoad(i,this.map,this.depMaps);y(c);this.defined=!0}this.defining=!1;this.defined&&!this.defineEmitted&&(this.defineEmitted=!0,this.emit("defined",this.exports),this.defineEmitComplete=!0)}}else this.fetch()}},callPlugin:function(){var a=
|
||||
this.map,b=a.id,d=p(a.prefix);this.depMaps.push(d);q(d,"defined",u(this,function(f){var l,d;d=m(aa,this.map.id);var e=this.map.name,P=this.map.parentMap?this.map.parentMap.name:null,n=i.makeRequire(a.parentMap,{enableBuildCallback:!0});if(this.map.unnormalized){if(f.normalize&&(e=f.normalize(e,function(a){return c(a,P,!0)})||""),f=p(a.prefix+"!"+e,this.map.parentMap),q(f,"defined",u(this,function(a){this.init([],function(){return a},null,{enabled:!0,ignore:!0})})),d=m(h,f.id)){this.depMaps.push(f);
|
||||
if(this.events.error)d.on("error",u(this,function(a){this.emit("error",a)}));d.enable()}}else d?(this.map.url=i.nameToUrl(d),this.load()):(l=u(this,function(a){this.init([],function(){return a},null,{enabled:!0})}),l.error=u(this,function(a){this.inited=!0;this.error=a;a.requireModules=[b];B(h,function(a){0===a.map.id.indexOf(b+"_unnormalized")&&y(a.map.id)});w(a)}),l.fromText=u(this,function(f,c){var d=a.name,e=p(d),P=M;c&&(f=c);P&&(M=!1);s(e);t(j.config,b)&&(j.config[d]=j.config[b]);try{g.exec(f)}catch(h){return w(C("fromtexteval",
|
||||
"fromText eval for "+b+" failed: "+h,h,[b]))}P&&(M=!0);this.depMaps.push(e);i.completeLoad(d);n([d],l)}),f.load(a.name,n,l,j))}));i.enable(d,this);this.pluginMaps[d.id]=d},enable:function(){V[this.map.id]=this;this.enabling=this.enabled=!0;v(this.depMaps,u(this,function(a,b){var c,f;if("string"===typeof a){a=p(a,this.map.isDefine?this.map:this.map.parentMap,!1,!this.skipMap);this.depMaps[b]=a;if(c=m(L,a.id)){this.depExports[b]=c(this);return}this.depCount+=1;q(a,"defined",u(this,function(a){this.defineDep(b,
|
||||
a);this.check()}));this.errback&&q(a,"error",u(this,this.errback))}c=a.id;f=h[c];!t(L,c)&&(f&&!f.enabled)&&i.enable(a,this)}));B(this.pluginMaps,u(this,function(a){var b=m(h,a.id);b&&!b.enabled&&i.enable(a,this)}));this.enabling=!1;this.check()},on:function(a,b){var c=this.events[a];c||(c=this.events[a]=[]);c.push(b)},emit:function(a,b){v(this.events[a],function(a){a(b)});"error"===a&&delete this.events[a]}};i={config:j,contextName:b,registry:h,defined:r,urlFetched:S,defQueue:A,Module:Z,makeModuleMap:p,
|
||||
nextTick:g.nextTick,onError:w,configure:function(a){a.baseUrl&&"/"!==a.baseUrl.charAt(a.baseUrl.length-1)&&(a.baseUrl+="/");var b=j.shim,c={paths:!0,bundles:!0,config:!0,map:!0};B(a,function(a,b){c[b]?(j[b]||(j[b]={}),U(j[b],a,!0,!0)):j[b]=a});a.bundles&&B(a.bundles,function(a,b){v(a,function(a){a!==b&&(aa[a]=b)})});a.shim&&(B(a.shim,function(a,c){H(a)&&(a={deps:a});if((a.exports||a.init)&&!a.exportsFn)a.exportsFn=i.makeShimExports(a);b[c]=a}),j.shim=b);a.packages&&v(a.packages,function(a){var b,
|
||||
a="string"===typeof a?{name:a}:a;b=a.name;a.location&&(j.paths[b]=a.location);j.pkgs[b]=a.name+"/"+(a.main||"main").replace(ia,"").replace(Q,"")});B(h,function(a,b){!a.inited&&!a.map.unnormalized&&(a.map=p(b))});if(a.deps||a.callback)i.require(a.deps||[],a.callback)},makeShimExports:function(a){return function(){var b;a.init&&(b=a.init.apply(ba,arguments));return b||a.exports&&da(a.exports)}},makeRequire:function(a,e){function j(c,d,m){var n,q;e.enableBuildCallback&&(d&&G(d))&&(d.__requireJsBuild=
|
||||
!0);if("string"===typeof c){if(G(d))return w(C("requireargs","Invalid require call"),m);if(a&&t(L,c))return L[c](h[a.id]);if(g.get)return g.get(i,c,a,j);n=p(c,a,!1,!0);n=n.id;return!t(r,n)?w(C("notloaded",'Module name "'+n+'" has not been loaded yet for context: '+b+(a?"":". Use require([])"))):r[n]}J();i.nextTick(function(){J();q=s(p(null,a));q.skipMap=e.skipMap;q.init(c,d,m,{enabled:!0});D()});return j}e=e||{};U(j,{isBrowser:z,toUrl:function(b){var d,e=b.lastIndexOf("."),k=b.split("/")[0];if(-1!==
|
||||
e&&(!("."===k||".."===k)||1<e))d=b.substring(e,b.length),b=b.substring(0,e);return i.nameToUrl(c(b,a&&a.id,!0),d,!0)},defined:function(b){return t(r,p(b,a,!1,!0).id)},specified:function(b){b=p(b,a,!1,!0).id;return t(r,b)||t(h,b)}});a||(j.undef=function(b){x();var c=p(b,a,!0),e=m(h,b);d(b);delete r[b];delete S[c.url];delete $[b];T(A,function(a,c){a[0]===b&&A.splice(c,1)});e&&(e.events.defined&&($[b]=e.events),y(b))});return j},enable:function(a){m(h,a.id)&&s(a).enable()},completeLoad:function(a){var b,
|
||||
c,d=m(j.shim,a)||{},g=d.exports;for(x();A.length;){c=A.shift();if(null===c[0]){c[0]=a;if(b)break;b=!0}else c[0]===a&&(b=!0);E(c)}c=m(h,a);if(!b&&!t(r,a)&&c&&!c.inited){if(j.enforceDefine&&(!g||!da(g)))return e(a)?void 0:w(C("nodefine","No define call for "+a,null,[a]));E([a,d.deps||[],d.exportsFn])}D()},nameToUrl:function(a,b,c){var d,e,h;(d=m(j.pkgs,a))&&(a=d);if(d=m(aa,a))return i.nameToUrl(d,b,c);if(g.jsExtRegExp.test(a))d=a+(b||"");else{d=j.paths;a=a.split("/");for(e=a.length;0<e;e-=1)if(h=a.slice(0,
|
||||
e).join("/"),h=m(d,h)){H(h)&&(h=h[0]);a.splice(0,e,h);break}d=a.join("/");d+=b||(/^data\:|\?/.test(d)||c?"":".js");d=("/"===d.charAt(0)||d.match(/^[\w\+\.\-]+:/)?"":j.baseUrl)+d}return j.urlArgs?d+((-1===d.indexOf("?")?"?":"&")+j.urlArgs):d},load:function(a,b){g.load(i,a,b)},execCb:function(a,b,c,d){return b.apply(d,c)},onScriptLoad:function(a){if("load"===a.type||ja.test((a.currentTarget||a.srcElement).readyState))N=null,a=I(a),i.completeLoad(a.id)},onScriptError:function(a){var b=I(a);if(!e(b.id))return w(C("scripterror",
|
||||
"Script error for: "+b.id,a,[b.id]))}};i.require=i.makeRequire();return i}var g,x,y,D,I,E,N,J,s,O,ka=/(\/\*([\s\S]*?)\*\/|([^:]|^)\/\/(.*)$)/mg,la=/[^.]\s*require\s*\(\s*["']([^'"\s]+)["']\s*\)/g,Q=/\.js$/,ia=/^\.\//;x=Object.prototype;var K=x.toString,fa=x.hasOwnProperty,ha=Array.prototype.splice,z=!!("undefined"!==typeof window&&"undefined"!==typeof navigator&&window.document),ea=!z&&"undefined"!==typeof importScripts,ja=z&&"PLAYSTATION 3"===navigator.platform?/^complete$/:/^(complete|loaded)$/,
|
||||
Y="undefined"!==typeof opera&&"[object Opera]"===opera.toString(),F={},q={},R=[],M=!1;if("undefined"===typeof define){if("undefined"!==typeof requirejs){if(G(requirejs))return;q=requirejs;requirejs=void 0}"undefined"!==typeof require&&!G(require)&&(q=require,require=void 0);g=requirejs=function(b,c,d,e){var n,p="_";!H(b)&&"string"!==typeof b&&(n=b,H(c)?(b=c,c=d,d=e):b=[]);n&&n.context&&(p=n.context);(e=m(F,p))||(e=F[p]=g.s.newContext(p));n&&e.configure(n);return e.require(b,c,d)};g.config=function(b){return g(b)};
|
||||
g.nextTick="undefined"!==typeof setTimeout?function(b){setTimeout(b,4)}:function(b){b()};require||(require=g);g.version="2.1.14";g.jsExtRegExp=/^\/|:|\?|\.js$/;g.isBrowser=z;x=g.s={contexts:F,newContext:ga};g({});v(["toUrl","undef","defined","specified"],function(b){g[b]=function(){var c=F._;return c.require[b].apply(c,arguments)}});if(z&&(y=x.head=document.getElementsByTagName("head")[0],D=document.getElementsByTagName("base")[0]))y=x.head=D.parentNode;g.onError=ca;g.createNode=function(b){var c=
|
||||
b.xhtml?document.createElementNS("http://www.w3.org/1999/xhtml","html:script"):document.createElement("script");c.type=b.scriptType||"text/javascript";c.charset="utf-8";c.async=!0;return c};g.load=function(b,c,d){var e=b&&b.config||{};if(z)return e=g.createNode(e,c,d),e.setAttribute("data-requirecontext",b.contextName),e.setAttribute("data-requiremodule",c),e.attachEvent&&!(e.attachEvent.toString&&0>e.attachEvent.toString().indexOf("[native code"))&&!Y?(M=!0,e.attachEvent("onreadystatechange",b.onScriptLoad)):
|
||||
(e.addEventListener("load",b.onScriptLoad,!1),e.addEventListener("error",b.onScriptError,!1)),e.src=d,J=e,D?y.insertBefore(e,D):y.appendChild(e),J=null,e;if(ea)try{importScripts(d),b.completeLoad(c)}catch(m){b.onError(C("importscripts","importScripts failed for "+c+" at "+d,m,[c]))}};z&&!q.skipDataMain&&T(document.getElementsByTagName("script"),function(b){y||(y=b.parentNode);if(I=b.getAttribute("data-main"))return s=I,q.baseUrl||(E=s.split("/"),s=E.pop(),O=E.length?E.join("/")+"/":"./",q.baseUrl=
|
||||
O),s=s.replace(Q,""),g.jsExtRegExp.test(s)&&(s=I),q.deps=q.deps?q.deps.concat(s):[s],!0});define=function(b,c,d){var e,g;"string"!==typeof b&&(d=c,c=b,b=null);H(c)||(d=c,c=null);!c&&G(d)&&(c=[],d.length&&(d.toString().replace(ka,"").replace(la,function(b,d){c.push(d)}),c=(1===d.length?["require"]:["require","exports","module"]).concat(c)));if(M){if(!(e=J))N&&"interactive"===N.readyState||T(document.getElementsByTagName("script"),function(b){if("interactive"===b.readyState)return N=b}),e=N;e&&(b||
|
||||
(b=e.getAttribute("data-requiremodule")),g=F[e.getAttribute("data-requirecontext")])}(g?g.defQueue:R).push([b,c,d])};define.amd={jQuery:!0};g.exec=function(b){return eval(b)};g(q)}})(this);
|
445
web-server/public/js/libs/resources.js
Normal file
445
web-server/public/js/libs/resources.js
Normal file
@@ -0,0 +1,445 @@
|
||||
|
||||
/* HELPERS */
|
||||
|
||||
// wrap jquery ajax function to reduce redundant code
|
||||
var AJAX = function(loc, method, contentType, data, callback, failback, headers){
|
||||
var me = this;
|
||||
var dataStr = null;
|
||||
if(!$.isEmptyObject(data) && (contentType == 'application/json' || contentType == 'text/uri-list')){
|
||||
dataStr = JSON.stringify(data);
|
||||
}else{
|
||||
dataStr = data;
|
||||
}
|
||||
$.ajax({
|
||||
type : method,
|
||||
url : loc.charAt(0) == '/' ? loc : '/rest/'+loc,
|
||||
//dataType : dataType,
|
||||
contentType : contentType,
|
||||
data : dataStr,
|
||||
beforeSend : function(xhr){
|
||||
if(headers){
|
||||
$.each(headers, function(i , header){
|
||||
xhr.setRequestHeader(header.name, header.val);
|
||||
});
|
||||
}
|
||||
}
|
||||
}).done(function(result, status, xhr){
|
||||
if(typeof callback === typeof Function){
|
||||
callback(result, status, xhr);
|
||||
}
|
||||
}).fail(function(xhr, status, thrownError){
|
||||
// handle not authorized status codes to redirect to login page
|
||||
if(xhr.status == 403 || xhr.status == 401){
|
||||
|
||||
failback(xhr, status, thrownError);
|
||||
// me.cookies.remove('magnet_auth');
|
||||
// window.location.replace('/login/');
|
||||
}else if(typeof failback === typeof Function){
|
||||
failback(xhr, status, thrownError);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// basic HTML5 upload component - Firefox, Google Chrome and Safari ONLY
|
||||
function uploader(id, url, property, type){
|
||||
var file = document.getElementById(id).files[0];
|
||||
uploadFile(file);
|
||||
function uploadFile(file){
|
||||
var reader = new FileReader();
|
||||
reader.onload = (function(theFile){
|
||||
return function(evt){
|
||||
AJAX(evt, file);
|
||||
};
|
||||
}(file));
|
||||
reader.readAsArrayBuffer(file);
|
||||
}
|
||||
function AJAX(evt, file){
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open("put", url+'/'+property, true);
|
||||
if(file.type != ''){
|
||||
type = file.type;
|
||||
}
|
||||
xhr.setRequestHeader("Content-Type", type);
|
||||
xhr.send(evt.target.result);
|
||||
}
|
||||
}
|
||||
// cookies
|
||||
function Cookie(){}
|
||||
Cookie.prototype.create = function(name, val, days){
|
||||
if(days){
|
||||
var date = new Date();
|
||||
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
|
||||
var expires = '; expires=' + date.toGMTString();
|
||||
}else{
|
||||
var expires = '';
|
||||
}
|
||||
document.cookie = encodeURIComponent(name) + '=' + encodeURIComponent(val) + expires + '; path=/';
|
||||
}
|
||||
Cookie.prototype.get = function(name){
|
||||
var nameEQ = encodeURIComponent(name) + '=';
|
||||
var ca = document.cookie.split(';');
|
||||
for(var i=0;i<ca.length;i++){
|
||||
var c = ca[i];
|
||||
while(c.charAt(0) == ' '){
|
||||
c = c.substring(1, c.length)
|
||||
};
|
||||
if(c.indexOf(nameEQ) == 0){
|
||||
return decodeURIComponent(c.substring(nameEQ.length, c.length))
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
Cookie.prototype.remove = function(name){
|
||||
this.create(name, "", -1);
|
||||
}
|
||||
function startLoading(id){
|
||||
$('#'+id+' .modal-footer').hide();
|
||||
$('#'+id+' .loading.modal-footer').show();
|
||||
}
|
||||
function endLoading(id, params){
|
||||
$('#'+id+' .modal-footer').show();
|
||||
$('#'+id+' .loading.modal-footer').hide();
|
||||
if(params){
|
||||
$('#'+id+' h4').html(params.title);
|
||||
$('#'+id+' .form-horizontal').hide();
|
||||
$('#'+id+' .subheading').html(params.text);
|
||||
}
|
||||
}
|
||||
|
||||
// utility functions
|
||||
timer = {
|
||||
loops : {},
|
||||
poll : function(action, delay, id){
|
||||
var me = this;
|
||||
//$(id).show();
|
||||
me.loops[id] = me.loops[id] || {};
|
||||
me.interval(action, delay, id);
|
||||
me.loops[id].timer = setInterval(function(){
|
||||
if(!me.loops[id].paused){
|
||||
me.interval(action, delay, id);
|
||||
}
|
||||
}, delay+1000);
|
||||
},
|
||||
interval : function(action, delay, id){
|
||||
var me = this;
|
||||
var cls = id.replace('#', '');
|
||||
ctr = (delay/1000) - 1;
|
||||
clearInterval(me.loops[id].ctr);
|
||||
me.loops[id].paused = true;
|
||||
action(me.loops[id]);
|
||||
me.loops[id].ctr = setInterval(function(){
|
||||
var html = 'refreshing content in ';
|
||||
var min = Math.floor(ctr/60);
|
||||
var sec = ctr-min*60;
|
||||
if(min > 0){
|
||||
html += min+' minutes and ';
|
||||
}
|
||||
html = 'Processing...';
|
||||
$(id).html(html);
|
||||
ctr -= 1;
|
||||
if(ctr < 0){
|
||||
$(id).html('Processing... <img src="/images/ajax-loader-sm.gif" />');
|
||||
}
|
||||
}, 1000);
|
||||
},
|
||||
stop : function(id){
|
||||
if(!id){
|
||||
$.each(this.loops, function(i, loop){
|
||||
clearInterval(loop.timer);
|
||||
clearInterval(loop.ctr);
|
||||
});
|
||||
}else{
|
||||
if(this.loops[id]){
|
||||
clearInterval(this.loops[id].timer);
|
||||
clearInterval(this.loops[id].ctr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
utils = {
|
||||
isCanvasSupported : function(){
|
||||
var elem = document.createElement('canvas');
|
||||
return !!(elem.getContext && elem.getContext('2d'));
|
||||
},
|
||||
magnetId : function(str){
|
||||
return str.slice(str.lastIndexOf('/')+1);
|
||||
},
|
||||
cleanName : function(str){
|
||||
return str.replace(new RegExp(' ', 'g'), '').replace(new RegExp('-', 'g'), '').replace(new RegExp('_', 'g'), '');
|
||||
},
|
||||
baseUrl : window.location.href.replace(window.location.hash, '').substr(0, window.location.href.replace(window.location.hash, '').lastIndexOf('/')),
|
||||
txtDefaults : function(sel){
|
||||
$(sel).focus(function(){
|
||||
if(this.value == this.defaultValue){
|
||||
this.value = '';
|
||||
$(this).css('color', '#000');
|
||||
}
|
||||
}).blur(function(){
|
||||
if(this.value == ''){
|
||||
this.value = this.defaultValue;
|
||||
$(this).css('color', '#555');
|
||||
}
|
||||
})
|
||||
},
|
||||
setIndexOf : function(){
|
||||
if(!Array.prototype.indexOf){
|
||||
Array.prototype.indexOf = function(elt /*, from*/){
|
||||
var len = this.length >>> 0;
|
||||
var from = Number(arguments[1]) || 0;
|
||||
from = (from < 0) ? Math.ceil(from) : Math.floor(from);
|
||||
if(from < 0){
|
||||
from += len;
|
||||
}
|
||||
for(; from < len; from++){
|
||||
if(from in this && this[from] === elt){
|
||||
return from;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
};
|
||||
}
|
||||
},
|
||||
getValidJSON : function(str){
|
||||
try{
|
||||
return JSON.parse(str);
|
||||
}catch(e){
|
||||
return false;
|
||||
}
|
||||
},
|
||||
convertHeaderStrToObj : function(xhr){
|
||||
var dataObj = {};
|
||||
$.each(xhr, function(i, val){
|
||||
if(($.type(val) == 'string' || $.type(val) == 'number') && i != 'responseText'){
|
||||
dataObj[i] = val;
|
||||
}
|
||||
});
|
||||
$.each(xhr.getAllResponseHeaders().split('\n'), function(i, line){
|
||||
var ary = $.trim(line).split(': ');
|
||||
if(ary.length > 1){
|
||||
dataObj[ary[0]] = ary[1];
|
||||
}
|
||||
});
|
||||
return dataObj;
|
||||
},
|
||||
hasAllOptionalProperties : function(properties, prefix, total){
|
||||
var ctr = 0;
|
||||
$.each(properties, function(prop, val){
|
||||
if(prop.indexOf(prefix) != -1 && val != ''){
|
||||
++ctr;
|
||||
}
|
||||
});
|
||||
return ctr == total;
|
||||
},
|
||||
cleanJavaKeywords: function(str){
|
||||
var renamed = str.toLowerCase();
|
||||
var keywords = ['abstract','assert','boolean','break','byte','case','catch','char','class','const','continue','default','do','double','else','enum','extends','final','finally','float','for','goto','if','implements','import','instanceof','int','interface','long','native','new','package','private','protected','public','return','short','static ','strictfp','super','switch','synchronized','this','throw','throws','transient','try','void','volatile','while'];
|
||||
for(var i=keywords.length;i--;){
|
||||
if(keywords[i] == renamed){
|
||||
str += ' project';
|
||||
}
|
||||
}
|
||||
return str;
|
||||
},
|
||||
// collect project details from form fields into data object
|
||||
collect : function(dom){
|
||||
var obj = {}, me = this;
|
||||
dom.find('.btn-group:not(.disabled)').each(function(){
|
||||
obj[$(this).attr('did')] = $(this).find('button.btn-primary').attr('did');
|
||||
});
|
||||
dom.find('input[type="radio"]:checked').each(function(){
|
||||
var name = $(this).attr('name');
|
||||
if(name.indexOf('authMethod') != -1){
|
||||
name = name.substr(0, name.indexOf('-'));
|
||||
}
|
||||
obj[name] = $(this).val();
|
||||
});
|
||||
dom.find('input[type="text"], select, input[type="password"], textarea').each(function(){
|
||||
var val = $(this).val();
|
||||
if(typeof $(this).attr('name') != 'undefined'){
|
||||
if($(this).attr('name') && $(this).attr('name').indexOf('Port') != -1 && $.trim(val).length == 0){
|
||||
val = 0;
|
||||
}
|
||||
obj[$(this).attr('name')] = val;
|
||||
}
|
||||
});
|
||||
dom.find('.pill-group > .pill > span:first-child').each(function(){
|
||||
var did = $(this).closest('.pillbox').attr('name');
|
||||
obj[did] = obj[did] || [];
|
||||
obj[did].push($(this).text());
|
||||
});
|
||||
$.each(obj, function(name, val){
|
||||
if(val === 'true'){
|
||||
obj[name] = true;
|
||||
}
|
||||
if(val === 'false'){
|
||||
obj[name] = false;
|
||||
}
|
||||
});
|
||||
return obj;
|
||||
},
|
||||
// remove an item from associative array given a property name
|
||||
removeByProp : function(ary, prop, val){
|
||||
for(var i=ary.length;i--;){
|
||||
if(ary[i][prop] == val){
|
||||
ary.splice(i, 1);
|
||||
}
|
||||
}
|
||||
},
|
||||
ISO8601ToDT: function(str, isNow){
|
||||
try{
|
||||
var date = isNow ? new Date() : new Date(str);
|
||||
if(isNaN(date)){
|
||||
date = this.fromISO8601(str);
|
||||
}
|
||||
var yyyy = date.getFullYear();
|
||||
var mm = this.formatDT(date.getMonth()+1);
|
||||
var dd = this.formatDT(date.getDate());
|
||||
var hh = this.formatDT(date.getHours());
|
||||
var m = this.formatDT(date.getMinutes());
|
||||
var ss = this.formatDT(date.getSeconds());
|
||||
return mm+'-'+dd+'-'+yyyy+' '+hh+':'+m+':'+ss;
|
||||
}catch(e){
|
||||
return '';
|
||||
}
|
||||
},
|
||||
formatDT: function(str){
|
||||
return str < 10 ? '0'+str : str;
|
||||
},
|
||||
fromISO8601: function(s){
|
||||
var re = /(\d{4})-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)(\.\d+)?(Z|([+-])(\d\d):(\d\d))/;
|
||||
var d = [];
|
||||
d = s.match(re);
|
||||
if(!d){
|
||||
throw "Couldn't parse ISO 8601 date string '" + s + "'";
|
||||
}
|
||||
var a = [1,2,3,4,5,6,10,11];
|
||||
for(var i in a){
|
||||
d[a[i]] = parseInt(d[a[i]], 10);
|
||||
}
|
||||
d[7] = parseFloat(d[7]);
|
||||
var ms = Date.UTC(d[1], d[2] - 1, d[3], d[4], d[5], d[6]);
|
||||
if(d[7] > 0){
|
||||
ms += Math.round(d[7] * 1000);
|
||||
}
|
||||
if(d[8] != "Z" && d[10]){
|
||||
var offset = d[10] * 60 * 60 * 1000;
|
||||
if(d[11]){
|
||||
offset += d[11] * 60 * 1000;
|
||||
}
|
||||
if(d[9] == "-"){
|
||||
ms -= offset;
|
||||
}else{
|
||||
ms += offset;
|
||||
}
|
||||
}
|
||||
return new Date(ms);
|
||||
},
|
||||
toISO8601 : function(d){
|
||||
function pad(n){return n<10 ? '0'+n : n}
|
||||
return d.getUTCFullYear()+'-'
|
||||
+ pad(d.getUTCMonth()+1)+'-'
|
||||
+ pad(d.getUTCDate())+'T'
|
||||
+ pad(d.getUTCHours())+':'
|
||||
+ pad(d.getUTCMinutes())+':'
|
||||
+ pad(d.getUTCSeconds())+'Z';
|
||||
},
|
||||
isNumeric : function(n){
|
||||
return !isNaN(parseFloat(n)) && isFinite(n);
|
||||
},
|
||||
// returns whether current browser is an iOS device
|
||||
isIOS : function(){
|
||||
return /iPhone|iPad|iPod/i.test(navigator.userAgent);
|
||||
},
|
||||
urlRE: /https?:\/\/([-\w\.]+)+(:\d+)?(\/([^\s]*(\?\S+)?)?)?/g,
|
||||
toStaticHTML: function(inputHtml) {
|
||||
inputHtml = inputHtml.toString();
|
||||
return inputHtml.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
||||
},
|
||||
zeroPad: function(digits, n) {
|
||||
n = n.toString();
|
||||
while(n.length < digits)
|
||||
n = '0' + n;
|
||||
return n;
|
||||
},
|
||||
timeString: function(date) {
|
||||
var minutes = date.getMinutes().toString();
|
||||
var hours = date.getHours().toString();
|
||||
return this.zeroPad(2, hours) + ":" + this.zeroPad(2, minutes);
|
||||
},
|
||||
isBlank: function(text) {
|
||||
var blank = /^\s*$/;
|
||||
return(text.match(blank) !== null);
|
||||
},
|
||||
getGUID : function(){
|
||||
var d = new Date().getTime();
|
||||
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c){
|
||||
var r = (d + Math.random()*16)%16 | 0;
|
||||
d = Math.floor(d/16);
|
||||
return (c=='x' ? r : (r&0x7|0x8)).toString(16);
|
||||
});
|
||||
},
|
||||
getPlural : function(str){
|
||||
var lastChar = str.slice(-1);
|
||||
if(lastChar === 'y')
|
||||
if(['a', 'e', 'i', 'o', 'u'].indexOf(str.charAt(str.length - 2)) != -1)
|
||||
return str + 's';
|
||||
else
|
||||
return str.slice(0, -1) + 'ies';
|
||||
else if(str.substring(str.length - 2) === 'us')
|
||||
return str.slice(0, -2) + 'i';
|
||||
else if (['ch', 'sh'].indexOf(str.substring(str.length - 2)) !== -1 || ['x','s'].indexOf(lastChar) !== -1)
|
||||
return str + 'es';
|
||||
else
|
||||
return str + 's';
|
||||
}
|
||||
};
|
||||
|
||||
var RegexValidation = {
|
||||
validate : function(input, type){
|
||||
if(!input) return false;
|
||||
if(type == 'url' && input.indexOf('https://') == -1 && input.indexOf('http://') == -1 && input.indexOf('ftp://') == -1){
|
||||
input = 'http://'+input;
|
||||
}
|
||||
return typeof input == 'string' ? this.validators[type].test(input) : false;
|
||||
},
|
||||
validators : {
|
||||
url : new RegExp(
|
||||
"^" +
|
||||
// protocol identifier
|
||||
"(?:(?:https?|ftp)://)" +
|
||||
// user:pass authentication
|
||||
"(?:\\S+(?::\\S*)?@)?" +
|
||||
"(?:" +
|
||||
// IP address exclusion
|
||||
// private & local networks
|
||||
"(?!10(?:\\.\\d{1,3}){3})" +
|
||||
"(?!127(?:\\.\\d{1,3}){3})" +
|
||||
"(?!169\\.254(?:\\.\\d{1,3}){2})" +
|
||||
"(?!192\\.168(?:\\.\\d{1,3}){2})" +
|
||||
"(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})" +
|
||||
// IP address dotted notation octets
|
||||
// excludes loopback network 0.0.0.0
|
||||
// excludes reserved space >= 224.0.0.0
|
||||
// excludes network & broacast addresses
|
||||
// (first & last IP address of each class)
|
||||
"(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])" +
|
||||
"(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}" +
|
||||
"(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))" +
|
||||
"|" +
|
||||
// host name
|
||||
"(?:(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)" +
|
||||
// domain name
|
||||
"(?:\\.(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)*" +
|
||||
// TLD identifier
|
||||
"(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))" +
|
||||
")" +
|
||||
// port number
|
||||
"(?::\\d{2,5})?" +
|
||||
// resource path
|
||||
"(?:/[^\\s]*)?" +
|
||||
"$", "i"
|
||||
),
|
||||
email : new RegExp("^[-a-z0-9~!$%^&*_=+}{\'?]+(\.[-a-z0-9~!$%^&*_=+}{\'?]+)*@([a-z0-9_][-a-z0-9_]*(\.[-a-z0-9_]+)*\.(aero|arpa|biz|com|coop|edu|gov|info|int|mil|museum|name|net|org|pro|travel|mobi|[a-z][a-z])|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,5})?$", "i")
|
||||
}
|
||||
}
|
3788
web-server/public/js/libs/socket.io.js
Normal file
3788
web-server/public/js/libs/socket.io.js
Normal file
File diff suppressed because one or more lines are too long
6
web-server/public/js/libs/underscore.js
Normal file
6
web-server/public/js/libs/underscore.js
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user