1 // Escape special characters in jQuery Selector
2 function escape_id( myid ) {
3 return "#" + myid.replace( /(:|\.|\[|\])/g, "\\$1" );
6 function getKeySplitId(id,separator){
7 // id of elements must respect this rule
8 // split_id[0] = plugin_uuid
9 // split_id[1] = element
10 // split_id[2] = field or key
12 var split_id = id.split(separator);
13 var key = split_id[2];
18 // Adding startsWith & endsWith to the string prototype
19 if ( typeof String.prototype.startsWith != 'function' ) {
20 String.prototype.startsWith = function( str ) {
21 return this.substring( 0, str.length ) === str;
25 if ( typeof String.prototype.endsWith != 'function' ) {
26 String.prototype.endsWith = function( str ) {
27 return this.substring( this.length - str.length, this.length ) === str;
30 // http://stackoverflow.com/questions/646628/javascript-startswith
32 function arrays_equal(a,b) { return !(a<b || b<a); }
34 function arrayInArray(elt,tab){
36 jQuery.each(tab, function(i,x){
37 if(arrays_equal(x,elt)){flag=true;return;}
42 jQuery.fn.spin = function(opts) {
43 this.each(function() {
44 var $this = jQuery(this),
52 data.spinner = new Spinner(jQuery.extend({color: $this.css('color')}, opts)).spin(this);
58 // FROM Triptych : http://stackoverflow.com/users/43089/triptych
59 // http://stackoverflow.com/questions/979256/how-to-sort-an-array-of-javascript-objects
60 // data.sort(sort_by('city', false, function(a){return a.toUpperCase()}));
61 var sort_by = function(field, reverse, primer) {
63 var key = function(x) { return primer ? primer(x[field]) : x[field]; };
64 //var key = primer ? function (x) { return primer(x[field]); } : function (x) { return x[field]; }
66 return function(a,b) {
67 var A = key(a), B = key(b);
68 return (A < B ? -1 : (A > B ? 1 : 0)) * [1,-1][+!!reverse];
69 //return ((A < B) ? -1 :
70 // (A > B) ? +1 : 0)) * [-1,1][+!!reverse];
74 function escapeRegExp(str) {
75 return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");