Skip to content

Instantly share code, notes, and snippets.

View garystorey's full-sized avatar
:octocat:

Gary Storey garystorey

:octocat:
View GitHub Profile
@garystorey
garystorey / JSPrototypeUpdates.js
Last active December 17, 2015 01:29
JavaScript prototype updates
/* STRING */
if ( typeof String.prototype.trim !== 'function' ) {
String.prototype.trim = function () {
return this.replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1");
};
}
if (typeof String.prototype.toProperCase !== 'function' ) {
String.prototype.toProperCase = function () {
@garystorey
garystorey / ajaxsetup.js
Created May 7, 2013 15:58
Error messages for $.ajaxsetup
$.ajaxSetup({
error: function(jqXHR, exception) {
var msg='';
if (jqXHR.status === 0) {
msg='Not connected.\n Verify Network Connectivity.';
} else if (jqXHR.status == 404) {
msg='Requested page not found. [404]';
} else if (jqXHR.status == 500) {
msg='Internal Server Error [500]';
} else if (exception === 'parsererror') {
@garystorey
garystorey / iife.js
Created May 7, 2013 16:06
IIFE (Immediately Invoked Function Expression)
// IIFE (Immediately Invoked Function Expression)
(function(window, $, undefined){
// code here..
})(window, jQuery);
@garystorey
garystorey / base_plugin.js
Created May 7, 2013 16:40
A basic setup for a jQuery plugin
//PLUGINNAME === Pluginname (UpperCase first letter)
//PLUGIN === pluginname (all lowercase)
var PLUGINNAME = function( $elm, options ) {
this.debug = false;
this.$el = $elm;
this.options = jQuery.extend( true, {}, $.fn.PLUGIN.defaults, options );
this.$el.data('PLUGINNAME', this);
@garystorey
garystorey / gs.js
Created May 9, 2013 20:24
Super simple chainable JavaScript Object for events, selecting, and add/remove CSS classes and HTML elements.
var gs = {
/***********************/
/* Class Manipulation */
/***********************/
addClass : function(el, clsName) {
var tmp;
@garystorey
garystorey / SharepointXML2JSON.js
Last active December 17, 2015 04:28
Converts Sharepoint ASMX XML to JSON or filter SVC call to needed fields
function filterJSObject (obj) {
//Sharepoint SVC Call - returns JSON
return JSON.parse(JSON.stringify(obj,_filterJsObj));
function _filterJsObj (key, value) {
var badattr ='__type __metadata Attachments ContentType ContentTypeID Created CreatedBy CreatedById Id Modified ModifiedBy ModifiedById Owshiddenversion Path Version'.split(" ");
return (badattr.indexOf(key) > -1) ? undefined : value;
}
}
@garystorey
garystorey / reverese_list.js
Created May 14, 2013 15:17
reverse an unordered (or ordered list) with jQuery
var $sel = $("ul"),
list = $sel.find('li').get().reverse();
$sel.empty().append(list);
@garystorey
garystorey / crossbrowserconsole.js
Created May 14, 2013 15:46
Cross browser console.
/**
* Protect window.console method calls, e.g. console is not defined on IE
* unless dev tools are open, and IE doesn't define console.debug
*/
(function () {
if (!window.console) {
window.console = {};
}
// union of Chrome, FF, IE, and Safari console methods
var functionCall = function () {},
@garystorey
garystorey / gruntfilesample.js
Created May 16, 2013 15:45
Sample Gruntfile from Ben Alman
'use strict';
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
// Metadata.
pkg: grunt.file.readJSON('tiny-pubsub.jquery.json'),
banner: '/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - ' +
'<%= grunt.template.today("yyyy-mm-dd") %>\n' +
@garystorey
garystorey / randomcolor.js
Last active December 17, 2015 10:09
Generate Random Hex Color Example: http://codepen.io/garystorey/pen/ugtza
var randomColors = {
init : function () {
this.elems = document.querySelectorAll("div");
this.update();
document.querySelector('#updateColors').addEventListener('click', function() {
randomColors.update();
});
},