Skip to content

Instantly share code, notes, and snippets.

View andrewburgess's full-sized avatar

Andrew Burgess andrewburgess

View GitHub Profile
define([
'ko',
'jquery'
], function (ko, $) {
ko.bindingHandlers.notification = {
update: function (element, valueAccessor, allBindingsAccessor, viewModel) {
var rawValue = valueAccessor(),
//notification can be passed an object with properties 'message', 'duration', 'fadeoutDuration', 'hide', 'fade', and 'callback', or it can be given just a string
options = typeof rawValue == 'object' ? rawValue : { message: rawValue },
message = ko.utils.unwrapObservable(options.message),
@andrewburgess
andrewburgess / bootstrap-infiniteScroll.js
Last active January 24, 2024 23:49
Twitter Bootstrap plugin that enables infinite scrolling
/* ============================================
* bootstrap-infiniteScroll.js
* ============================================ */
!function ($) {
'use strict';
var InfiniteScroll = function (el, options) {
this.$element = $(el);
this.$data = $(el).data();
this.$options = options;
@andrewburgess
andrewburgess / jquery.mobile-carousel.js
Created June 25, 2013 13:26
jQuery plugin for creating a carousel that responds to touch events to swipe through the carousel.
@andrewburgess
andrewburgess / ko.bindings.executeOnEnter.js
Created May 21, 2013 17:50
KnockoutJS binding that enables handling enter key presses and performing an action
ko.bindingHandlers.executeOnEnter = {
init: function (element, valueAccessor, allBindingsAccessor, viewModel) {
var allBindings = allBindingsAccessor();
$(element).keypress(function (event) {
var keyCode = (event.which ? event.which : event.keyCode);
if (keyCode === 13) {
ko.utils.triggerEvent(element, 'change');
allBindings.executeOnEnter.call(viewModel, viewModel, event);
return false;
@andrewburgess
andrewburgess / ko.bindings.templateWithClear.js
Created May 21, 2013 17:48
KnockoutJS binding that clears out the initial element before applying the template. Allows for server side generation of a repeatable element, that can then be rebound with Knockout
ko.bindingHandlers.templateWithClear = {
init: function (element, valueAccessor) {
element.innerHTML = '';
return ko.bindingHandlers.template.init(element, valueAccessor);
},
update: function (element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
return ko.bindingHandlers.template.update(element, valueAccessor, allBindingsAccessor, viewModel, bindingContext);
}
}
@andrewburgess
andrewburgess / ko.bindings.modal.js
Created May 21, 2013 17:45
KnockoutJS binding with Twitter Bootstrap's modal dialog
ko.bindingHandlers.modal = {
init: function (element, valueAccessor, bindingsAccessor, viewModel, bindingContext) {
var $element = $(element);
$element.addClass('hide modal');
$element.modal({
show: false
});
var bindings = bindingsAccessor();
if (bindings.modalOptions) {