Skip to content

Instantly share code, notes, and snippets.

Mx Corey Frang gnarf

Block or report user

Report or block gnarf

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View gist:842425
$(document).ready(function(){
function rem(e){
alert("asdfasdf");
};
$("#remove").click(rem);
});
@gnarf
gnarf / gist:951480
Created May 2, 2011
widget show/hide function
View gist:951480
$.each( { show: "fadeIn", hide: "fadeOut" }, function( method, defaultEffect ) {
$.Widget.prototype[ "_" + method ] = function( element, options, callback ) {
options = options || {};
var hasOptions = !$.isEmptyObject( options ),
effectName = options.effect || defaultEffect;
options.complete = callback;
if (options.delay) {
element.delay( options.delay );
}
if ( hasOptions && $.effects && $.effects.effect[ effectName ] ) {
@gnarf
gnarf / gist:952142
Created May 2, 2011
fn.promise() the way I saw it
View gist:952142
// Get a promise resolved when the currently queued functions complete
promise: function( type ) {
type = type || "fx";
var defer = jQuery.Deferred(),
elements = this,
count = elements.length;
function resolve( next ) {
if ( !( --count ) ) {
defer.resolveWith( elements, [ elements ] );
@gnarf
gnarf / gist:960850
Created May 7, 2011
Unit test for bug #9074
View gist:960850
test( "animate properties missing px w/ opacity as last (#9074)", 2, function() {
expect( 6 );
stop();
var div = jQuery( "<div style='position: absolute; margin-left: 0; left: 0px;'></div>" )
.appendTo( "#qunit-fixture" );
function cssInt( prop ) {
return parseInt( div.css( prop ), 10 );
}
equal( cssInt( "marginLeft" ), 0, "Margin left is 0" );
equal( cssInt( "left" ), 0, "Left is 0" );
View gist:968692
function present( value, array, message ) {
QUnit.push( jQuery.inArray( value, array ) !== -1 , value, array, message );
}
function notPresent( value, array, message ) {
QUnit.push( jQuery.inArray( value, array ) === -1 , value, array, message );
}
@gnarf
gnarf / gist:982197
Created May 20, 2011
Idea for Animate
View gist:982197
// helper function
function animate( props, opts ) {
var el = this,
anim = $.Deferred(),
propTimers = $.map( props, function( property, value ) {
// $.Timer is a deferred(progress?? jQuery.Callbacks if they make it into 1.7)
// object that is inserted into the jQuery.timers array that also
// picks up some of the properties/calcs from jQuery.fx -- "step" function
// animation data, etc...
var prop = $.Timer( el, property, duration );
@gnarf
gnarf / example.css
Created May 20, 2011
jQuery Animation Proposal Example
View example.css
#spinner {
...
-webkit-mask-image: url(../img/spinner.png);
background-color: #000;
-webkit-animation-name: spinnerRotate;
-webkit-animation-duration: 2s;
-webkit-animation-iteration-count: infinite;
-webkit-animation-timing-function: linear;
}
@-webkit-keyframes spinnerRotate {
@gnarf
gnarf / example.css
Created May 20, 2011
jQuery Animation Proposal Example 2
View example.css
@-webkit-keyframes pulse {
0% {
background-color: red;
opacity: 1.0;
-webkit-transform: scale(1.0) rotate(0deg);
}
33% {
background-color: blue;
opacity: 0.75;
-webkit-transform: scale(1.1) rotate(-5deg);
@gnarf
gnarf / example.js
Created Jun 1, 2011
$.fn.newContent
View example.js
// $.fn.newContent behaves kinda like .live(), it will act on elements that match the
// selector now, or in the future... It automatically runs on any elements immediately
// matched, and also runs once on document ready. You then call .newContent() on any
// freshly created content to trigger searching it
// It will call the given callback function in the context of a
// jQuery set that matches the selector...
$("li.test").newContent(function() {
this.css("color", "red");
@gnarf
gnarf / jQuery.ajaxQueue.min.js
Created Jun 21, 2011
jQuery.ajaxQueue - A queue for ajax requests
View jQuery.ajaxQueue.min.js
/*
* jQuery.ajaxQueue - A queue for ajax requests
*
* (c) 2011 Corey Frang
* Dual licensed under the MIT and GPL licenses.
*
* Requires jQuery 1.5+
*/
(function(a){var b=a({});a.ajaxQueue=function(c){function g(b){d=a.ajax(c).done(e.resolve).fail(e.reject).then(b,b)}var d,e=a.Deferred(),f=e.promise();b.queue(g),f.abort=function(h){if(d)return d.abort(h);var i=b.queue(),j=a.inArray(g,i);j>-1&&i.splice(j,1),e.rejectWith(c.context||c,[f,h,""]);return f};return f}})(jQuery)
You can’t perform that action at this time.