Skip to content

Instantly share code, notes, and snippets.

View evanisnor's full-sized avatar
🇨🇦

Evan Isnor evanisnor

🇨🇦
View GitHub Profile
@evanisnor
evanisnor / ko wrapper
Last active December 19, 2015 14:49
JavaScript functions to wrap and unwrap a JSON object and its entire contents with KnockoutJS's ko.observable (and ko.observableArray). The odd nested-function layout here is a hangover from using requirejs. Cannibalize as needed.
var ko_wrapper = function(ko) {
var data = {};
data.wrap = function(obj) {
if (Object.prototype.toString.call(obj) == '[object Array]'
|| Object.prototype.toString.call(obj) == '[object Object]') {
for (var i in obj) {
obj[i] = data.wrap(obj[i]);
}
}
@mpj
mpj / example.js
Created November 17, 2012 15:29
Minimal String Template Source for Knockout
var templateEngine = createNativeStringTemplateEngine();
templateEngine.addTemplate('gigaScroll', "\
<div id=\"viewport\">\
<div id=\"gigaDiv\" data-bind=\"style: { height: gigaDivHeight() + 'px' }\">\
<ul data-bind=\"foreach: visibleItems, style: { paddingTop: offsetTop() + 'px' }\">\
<li data-bind="text: name" />
</ul>\
</div>\
</div>");