dashboard redesign
[unfold.git] / portal / static / js / common.functions.js
index 56b02ca..a74132e 100644 (file)
@@ -1,6 +1,3 @@
-/*
- * This file is included in tophat_render.php
- */
 // Escape special characters in jQuery Selector
 function escape_id( myid ) {
     return "#" + myid.replace( /(:|\.|\[|\])/g, "\\$1" );
@@ -18,6 +15,20 @@ function getKeySplitId(id,separator){
     return key;
 }
 
+// Adding startsWith & endsWith to the string prototype
+if ( typeof String.prototype.startsWith != 'function' ) {
+  String.prototype.startsWith = function( str ) {
+    return this.substring( 0, str.length ) === str;
+  };
+};
+
+if ( typeof String.prototype.endsWith != 'function' ) {
+  String.prototype.endsWith = function( str ) {
+    return this.substring( this.length - str.length, this.length ) === str;
+  };
+};
+// http://stackoverflow.com/questions/646628/javascript-startswith
+
 function arrays_equal(a,b) { return !(a<b || b<a); }
 
 function arrayInArray(elt,tab){
@@ -47,15 +58,19 @@ jQuery.fn.spin = function(opts) {
 // FROM Triptych : http://stackoverflow.com/users/43089/triptych
 // http://stackoverflow.com/questions/979256/how-to-sort-an-array-of-javascript-objects
 // data.sort(sort_by('city', false, function(a){return a.toUpperCase()}));
-var sort_by = function(field, reverse, primer){
+var sort_by = function(field, reverse, primer) {
 
-   var key = function (x) {return primer ? primer(x[field]) : x[field]};
+   var key = function(x) { return primer ? primer(x[field]) : x[field]; };
    //var key = primer ? function (x) { return primer(x[field]); } : function (x) { return x[field]; }
    
-   return function (a,b) {
+   return function(a,b) {
        var A = key(a), B = key(b);
        return (A < B ? -1 : (A > B ? 1 : 0)) * [1,-1][+!!reverse];
        //return ((A < B) ? -1 :
        //        (A > B) ? +1 : 0)) * [-1,1][+!!reverse];                  
-   }
+   };
+};
+
+function escapeRegExp(str) {
+  return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
 }