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
jQuery('<div/>', { | |
id: 'foo', | |
href: 'http://google.com', | |
title: 'Become a Googler', | |
rel: 'external', | |
text: 'Go to Google!' | |
}).appendTo('#mySelector'); |
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
var r = (function() { | |
function sample_range(t,n) { | |
var l = [],r = []; | |
for (var i = 1; i <= t; i++) r.push(i); | |
for (var i = 0; i < n; i++) l.push(r.splice(Math.random() * r.length, 1)); | |
return l; | |
} |
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
$("img").each(function() { | |
$.ajax({ | |
url: $(this).attr('src'), | |
type: 'HEAD', | |
error: function() { | |
//image doesn't exist | |
console.log('ERROR'); | |
}, | |
success: function() { | |
//image exists |
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
$(".productBoxImage img").each(function() { | |
var _this = $(this); | |
$.ajax({ | |
url: $(this).attr('src'), | |
type: 'HEAD', | |
async: false, | |
error: function(e) { | |
if (e.status == '404') { | |
$(_this).attr('src', [replaceImageUrl]); |
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
(function($, len, createRange, duplicate){ | |
"use strict"; | |
$.fn.caret = function(options,opt2) { | |
if ( typeof this[0] === 'undefined' || this.is(':hidden') || this.css('visibility') === 'hidden' ) { return this; } | |
var n, s, start, e, end, selRange, range, stored_range, te, val, | |
selection = document.selection, t = this[0], sTop = t.scrollTop, | |
ss = typeof t.selectionStart !== 'undefined'; | |
if (typeof options === 'number' && typeof opt2 === 'number') { | |
start = options; | |
end = opt2; |
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
function getObjects(obj, key, val) { | |
var objects = []; | |
for (var i in obj) { | |
if (!obj.hasOwnProperty(i)) continue; | |
if (typeof obj[i] == 'object') { | |
objects = objects.concat(getObjects(obj[i], key, val)); | |
} else if (i == key && obj[key] == val) { | |
objects.push(obj); | |
} | |
} |
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
function toTitleCase(str){ | |
return str.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();}); | |
} |
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
// GET CURSOR POSITION | |
jQuery.fn.getCursorPosition = function() { | |
if (this.lengh == 0) return -1; | |
return $(this).getSelectionStart(); | |
} | |
//Set Text Selection | |
jQuery.fn.getSelectionStart = function() { |
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
$(document).ready(function(){ | |
$("img").error(function(){ | |
$("img").replaceWith("<p>Error loading image!</p>"); | |
}); | |
$("button").click(function(){ | |
$("img").error(); | |
}); | |
}); |
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
;var d = { | |
author: 'David', | |
//variables available to whole of namespace | |
someIds: [], | |
options: { | |
width: 400, | |
height: 300, | |
title: 'title' |