Skip to content

Instantly share code, notes, and snippets.

Dustin Poissant dustinpoissant

  • Burlington, VT
Block or report user

Report or block dustinpoissant

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
@dustinpoissant
dustinpoissant / String.extract.func.js
Created Dec 1, 2017
Extract a substring from a string between two substrings.
View String.extract.func.js
String.prototype.extract = function(start, finish){
var s = this.indexOf(start);
if(s == -1) return "";
var e = this.indexOf(finish, s + start.length);
if(e == -1) return "";
return this.substring(s + start.length, e);
}
@dustinpoissant
dustinpoissant / animateTransform.jquery.js
Last active Jul 2, 2018
jQuery Plugin to Animate Transforms
View animateTransform.jquery.js
$.fn.animateTransform = function(/* [start,] end [, duration] [, callback] */){
var start = null, end = null, duration = 400, callback = function(){};
for(var i=0; i<arguments.length; i++){
if(typeof(arguments[i]) == "string"){
if(!start) start = arguments[i];
else end = arguments[i];
} else if(typeof(arguments[i]) == "number"){
duration = arguments[i];
} else if(typeof(arguments[i]) == "function"){
callback = arguments[i];
@dustinpoissant
dustinpoissant / selectText.jquery.js
Created Feb 7, 2017
Selects the text within an element.
View selectText.jquery.js
jQuery.fn.selectText = function(){
var doc = document;
var element = this[0];
if (doc.body.createTextRange) {
var range = document.body.createTextRange();
range.moveToElementText(element);
range.select();
} else if (window.getSelection) {
var selection = window.getSelection();
var range = document.createRange();
@dustinpoissant
dustinpoissant / attrs.jquery.js
Created Jan 31, 2017
Get all attributes of an element.
View attrs.jquery.js
$.fn.attrs = function(){
var attributes = {};
if(this.length){
$.each( this[0].attributes, function( index, attr ) {
attributes[ attr.name ] = attr.value;
});
}
return attributes;
};
@dustinpoissant
dustinpoissant / roundTo.func.js
Created Jan 24, 2017
Round a number to the nearest "X"
View roundTo.func.js
function roundTo(number, to){
return (Math.round(number * (1/to)) / (1/to));
};
@dustinpoissant
dustinpoissant / containsObject.func.min.js
Created Nov 22, 2016
A quick and dirty check to see of one object contains another.
View containsObject.func.min.js
function containsObject(a,b){for(var c in a)if(!b[c]||a[c]!=b[c])return!1;return!0}
@dustinpoissant
dustinpoissant / validCSS.func.js
Last active Nov 28, 2016
Check if a CSS property/value is valid.
View validCSS.func.js
function validCSS(property, value){
var $el = $("<div></div>");
$el.css(property, value);
return ($el.css(property) == value);
}
@dustinpoissant
dustinpoissant / betterParseFloat.func.js
Last active Dec 1, 2016
Pasrses a number better than the orginal parseFloat function
View betterParseFloat.func.js
function betterParseFloat(num){
num = (num+"").replace(new RegExp(",", 'g'), ""); // Remove commas
return (num.length==0)?0:(isNaN(parseFloat(num)))?betterParseFloat(num.substr(1)):parseFloat(num);
};
@dustinpoissant
dustinpoissant / jQuery.getFormData.func.js
Created Nov 20, 2016
A jQuery plugin that gets the forms data as an Object.
View jQuery.getFormData.func.js
$.fn.hasAttr=function(a){var b=$(this).attr(a);return void 0!==typeof b&&b!==!1};
$.fn.getFormData = function(){
var data = {};
$(this).find("input, select, textarea").each(function(i, input){
var $input = $(input);
if($input.hasAttr("name")){
if($input.attr("type") && $input.hasAttr("type") && $input.attr("type").toLowerCase() == "checkbox"){
if($input.is(":checked")){
data[$input.attr("name")] = true;
} else {
@dustinpoissant
dustinpoissant / validColor.func.js
Last active Dec 20, 2017
A function to check if a string color is valid.
View validColor.func.js
function validColor(color){
if(color=="")return false;
var $div = $("<div>");
$div.css("border", "1px solid "+color);
return ($div.css("border-color")!="")
}
You can’t perform that action at this time.