Sha256: c25de06892fd5917add21148e7e8772a0d846a22ed2c6d9c2ce69da2847393a1

Contents?: true

Size: 1.61 KB

Versions: 16

Compression:

Stored size: 1.61 KB

Contents

var console = console || {log:function(){},warn:function(){},error:function(){}};

// Take a string, make an object.
$.deserialize = function(str) {
    var obj = {};
    str.split("&").forEach(
        function(p) {
            var s = p.split("=");
            obj[s[0].replace(/^\?/, '')] = decodeURIComponent(s[1]);
        }
    );
    return obj;
};
// Take a object, make an string (of parameters).
$.serialize = $.param;

// Replace values in a string, e.g. `"foo {boo}".format({boo: 'hoo'}) = 'foo hoo'`.
//
//     @param {Object} object
String.prototype.format = function(hash, translate_key) {
    translate_key = translate_key || false;
    var s = this;
    for (var key in hash) {
        if (hash.hasOwnProperty(key)) {
            var re = new RegExp('\\{' + (key) + '\\}','gm');
            s = s.replace(re, hash[key]);
        }
    }
    return s;
};

window.$id = function(id) {
    return document.getElementById(id);
};

// Capitalize the first character of a string.
String.prototype.capitalize = function() {
    return this.charAt(0).toUpperCase() + this.substr(1).toLowerCase();
};

// zepto/querySelector, understandably, can't deal with periods in the id attr.
String.prototype.dotToBar = function() {
    return this.replace(/\./g,"_");
};

window.macrojungle = function(tmpl) {
    // This is kind of stupid.
    // But at least it's only written once.
    var html = $('#tmp').empty().microjungle(tmpl).html();
    // If we don't actually want to get any html back (just a string),
    // we wrap the string in <tmp>string</tmp> and then remove
    // the tags here.
    return html.replace(/<(\/){0,1}tmp>/g, '');
};

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
sports_db-0.2.19 app/assets/javascripts/core/utilities.js
sports_db-0.2.18 app/assets/javascripts/core/utilities.js
sports_db-0.2.17 app/assets/javascripts/core/utilities.js
sports_db-0.2.16 app/assets/javascripts/core/utilities.js
sports_db-0.2.15 app/assets/javascripts/core/utilities.js
sports_db-0.2.14 app/assets/javascripts/core/utilities.js
sports_db-0.2.13 app/assets/javascripts/core/utilities.js
sports_db-0.2.12 app/assets/javascripts/core/utilities.js
sports_db-0.2.11 app/assets/javascripts/core/utilities.js
sports_db-0.2.10 app/assets/javascripts/core/utilities.js
sports_db-0.2.9 app/assets/javascripts/core/utilities.js
sports_db-0.2.8 app/assets/javascripts/core/utilities.js
sports_db-0.2.7 app/assets/javascripts/core/utilities.js
sports_db-0.2.6 app/assets/javascripts/core/utilities.js
sports_db-0.2.5 app/assets/javascripts/core/utilities.js
sports_db-0.2.4 app/assets/javascripts/core/utilities.js