Skip to content

Instantly share code, notes, and snippets.

@malsup
malsup / st2-build-on-save
Created July 30, 2012 02:39
Build-on-Save SublimeText2 plugin
import sublime, sublime_plugin
class AutoBuild(sublime_plugin.EventListener):
def on_post_save(self, view):
view.window().run_command("build")
@malsup
malsup / gist:3138779
Created July 18, 2012 20:46
scrollLeft transition effect for cycle lite
$.fn.cycle.transitions.scrollLeft = function($cont, $slides, opts) {
$cont.css('overflow','hidden');
var w = $cont.width();
opts.cssBefore.left = w;
opts.cssBefore.top = 0;
opts.animIn.left = 0;
opts.animOut.left = 0-w;
};
@malsup
malsup / gist:2961651
Created June 20, 2012 19:16
form spinner example
$('form').submit(e) {
e.preventDefault();
$(this).ajaxSubmit({
beforeSubmit: function() {
// code to show spinner
},
complete: function() {
// code to hide spinner
}
});
@malsup
malsup / sort-tabs (sublime)
Created April 23, 2012 03:58
Additional functionality for Sublime Text "SortTabs" plugin
import sublime, sublime_plugin
# additional functionality for SortTabs plugin
# https://github.com/bizoo/SortTabs
# trigger SortTabs when a file is activated
class SortTabsListener(sublime_plugin.EventListener):
def on_activated(self, view):
w = view.window()
if w != None:
@malsup
malsup / refreshBackgrounds.js
Created February 17, 2012 22:28 — forked from mavenlink/refreshBackgrounds.js
Fix Chrome background refresh bug
// might as well make it a plugin
$.fn.fixChromeBg = function() {
if (! /chrome/i.test(navigator.userAgent) )
return this;
return this.each(function() {
var el = $(this), bi = el.css( 'background-image' );
if (bi) {
setTimeout(function() {
@malsup
malsup / turnHorz.js
Created May 31, 2011 01:17
turnHorz cycle plugin transition
;(function($) {
$.fn.cycle.transitions.turnHorz = function($cont, $slides, opts) {
opts.before.push(function(curr, next, opts, fwd) {
$.fn.cycle.commonReset(curr,next,opts,false,true);
if (fwd) {
opts.cssBefore.left = next.cycleW;
opts.animIn.width = next.cycleW;
}
else {
@malsup
malsup / gist:657972
Created November 1, 2010 10:43
jQuery.post duckpunched for error callback
jQuery.post = function( url, data, callback, type, onError ) {
// shift arguments if data argument was omited
if ( jQuery.isFunction( data ) ) {
onError = type;
type = callback;
callback = data;
data = {};
}
return jQuery.ajax({
@malsup
malsup / jQuery Plugin Template
Created March 20, 2009 03:16
jQuery Plugin Template
// don't declare anything out here in the global namespace
(function($) { // create private scope (inside you can use $ instead of jQuery)
// functions and vars declared here are effectively 'singletons'. there will be only a single
// instance of them and they are not publicly accessible. so this is a good place to declare
// any immutable items or stateless functions. for example:
function myPrivateHelper() {
// some helper fn
@malsup
malsup / jsonp
Created March 20, 2009 02:58
$.getJSONP
// fn to handle jsonp with timeouts and errors
// hat tip to Ricardo Tomasi for the timeout logic
$.getJSONP = function(s) {
s.dataType = 'jsonp';
$.ajax(s);
// figure out what the callback fn is
var $script = $(document.getElementsByTagName('head')[0].firstChild);
var url = $script.attr('src') || '';
var cb = (url.match(/callback=(\w+)/)||[])[1];