Skip to content

Instantly share code, notes, and snippets.

View gnarf's full-sized avatar

Mx Corey Frang gnarf

View GitHub Profile
@gnarf
gnarf / gist:842425
Created February 24, 2011 16:46 — forked from dtolj/gist:842417
$(document).ready(function(){
function rem(e){
alert("asdfasdf");
};
$("#remove").click(rem);
});
@gnarf
gnarf / gist:951480
Created May 2, 2011 11:37
widget show/hide function
$.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 19:00
fn.promise() the way I saw it
// 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 21:16
Unit test for bug #9074
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" );
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 01:46
Idea for Animate
// 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 23:57
jQuery Animation Proposal Example
#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 23:58
jQuery Animation Proposal Example 2
@-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 June 1, 2011 23:53
$.fn.newContent
// $.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 June 21, 2011 23:52
jQuery.ajaxQueue - A queue for ajax requests
/*
* 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)