-
-
Save jgphilpott/83e40b7418954766e5b994d0f85e98d6 to your computer and use it in GitHub Desktop.
A collection of jQuery method updates.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Credit: http://gist.github.com/399624 | |
# The click event will be fired with a small delay but will not fire upon a double click. | |
$.fn.clickSingleDouble = (singleClickCallback, doubleClickCallback, delay = 250) -> | |
return this.each => | |
clicks = 0 | |
$(this).click (event) => | |
clicks++ | |
if clicks is 1 | |
setTimeout => | |
if clicks is 1 | |
singleClickCallback.call this, event | |
else | |
doubleClickCallback.call this, event | |
clicks = 0 | |
, delay | |
# Credit: https://stackoverflow.com/a/15191130/1544937 | |
# Credit: https://gist.github.com/hoandang/5989980 | |
# Rotate any jQuery selected element. | |
$.fn.rotate = (degree = 0, duration = 1000) -> | |
element = $(this) | |
rotation = => | |
matrix = element.css "-webkit-transform" or | |
element.css "-moz-transform" or | |
element.css "-ms-transform" or | |
element.css "-o-transform" or | |
element.css "transform" | |
if matrix isnt "none" | |
matrix = matrix.split("(")[1].split(")")[0].split(",") | |
return Math.round Math.atan2(matrix[1], matrix[0]) * (180 / Math.PI) | |
else | |
return 0 | |
rotation = rotation() | |
if rotation isnt degree | |
$("deg": rotation).animate "deg": degree, | |
"duration": duration | |
"step": (now) => | |
element.css "transform": "rotate(" + now + "deg)" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const $ = require("jquery") | |
// Credit: http://gist.github.com/399624 | |
// The click event will be fired with a small delay but will not fire upon a double click. | |
$.fn.clickSingleDouble = function(singleClickCallback, doubleClickCallback, delay = 250) { | |
return this.each(() => { | |
var clicks; | |
clicks = 0; | |
return $(this).click((event) => { | |
clicks++; | |
if (clicks === 1) { | |
return setTimeout(() => { | |
if (clicks === 1) { | |
singleClickCallback.call(this, event); | |
} else { | |
doubleClickCallback.call(this, event); | |
} | |
return clicks = 0; | |
}, delay); | |
} | |
}); | |
}); | |
}; | |
// Credit: https://stackoverflow.com/a/15191130/1544937 | |
// Credit: https://gist.github.com/hoandang/5989980 | |
// Rotate any jQuery selected element. | |
$.fn.rotate = function(degree = 0, duration = 1000) { | |
var element, rotation; | |
element = $(this); | |
rotation = () => { | |
var matrix; | |
matrix = element.css("-webkit-transform" || element.css("-moz-transform" || element.css("-ms-transform" || element.css("-o-transform" || element.css("transform"))))); | |
if (matrix !== "none") { | |
matrix = matrix.split("(")[1].split(")")[0].split(","); | |
return Math.round(Math.atan2(matrix[1], matrix[0]) * (180 / Math.PI)); | |
} else { | |
return 0; | |
} | |
}; | |
rotation = rotation(); | |
if (rotation !== degree) { | |
return $({ | |
"deg": rotation | |
}).animate({ | |
"deg": degree | |
}, { | |
"duration": duration, | |
"step": (now) => { | |
return element.css({ | |
"transform": "rotate(" + now + "deg)" | |
}); | |
} | |
}); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment