Sha256: 5290f77f1bb0ec3a74d19e7d0054b95407c477508ce92cc75be56f9df205d7a8

Contents?: true

Size: 1.55 KB

Versions: 1

Compression:

Stored size: 1.55 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) {
        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,"_");
};

var 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

1 entries across 1 versions & 1 rubygems

Version Path
sports_db-0.2.3 app/assets/javascripts/core/utilities.js