Skip to content

Instantly share code, notes, and snippets.

@sionjlewis
Created June 24, 2015 14:26
Show Gist options
  • Save sionjlewis/f6646e1825e155fe2baa to your computer and use it in GitHub Desktop.
Save sionjlewis/f6646e1825e155fe2baa to your computer and use it in GitHub Desktop.
Client-side Development Techniques with CQWP(s) and JavaScript - Part 3/5
var namespace = function (ns_string, obj) {
var parts = ns_string.split('.'),
parent = window,
pl, i;
for (i = 0, pl = parts.length; i < pl; i++) {
parent = parent[parts[i]] = parent[parts[i]] || (i == pl - 1 && obj ? (typeof obj == 'function' ? (obj() || {}) : obj) : {});
}
return parent;
};
namespace("SJLewis.ProductRelationships", function () {
var self = {};
self.productRelationship = function (id, product1, product2) {
this.id = parseInt(id);
this.product1 = parseInt(product1);
this.product2 = parseInt(product2);
}
self.productRelationships = [];
self.doSomeStuff = function () {
var content = '';
$.each(self.productRelationships, function (index, data) {
content += 'Test ' + data.product1 + ' - ' + data.product2 + '</br>';
})
$('#relationshipEditor').html(content);
}
return self;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment