// SCROLL TO BOTTOM!!!
// AMD support (Thanks to @FagnerMartinsBrack)
;(function(factory) {
'use strict';
if (typeof define === 'function' && define.amd) {
define(['jquery'], factory);
} else {
factory(jQuery);
}
})(function($){
'use strict';
var instances = [],
matchers = [],
defaultOptions = {
precision: 100, // 0.1 seconds, used to update the DOM
elapse: false
};
// Miliseconds
matchers.push(/^[0-9]*$/.source);
// Month/Day/Year [hours:minutes:seconds]
matchers.push(/([0-9]{1,2}\/){2}[0-9]{4}( [0-9]{1,2}(:[0-9]{2}){2})?/
.source);
// Year/Day/Month [hours:minutes:seconds] and
// Year-Day-Month [hours:minutes:seconds]
matchers.push(/[0-9]{4}([\/\-][0-9]{1,2}){2}( [0-9]{1,2}(:[0-9]{2}){2})?/
.source);
// Cast the matchers to a regular expression object
matchers = new RegExp(matchers.join('|'));
// Parse a Date formatted has String to a native object
function parseDateString(dateString) {
// Pass through when a native object is sent
if(dateString instanceof Date) {
return dateString;
}
// Caste string to date object
if(String(dateString).match(matchers)) {
// If looks like a milisecond value cast to number before
// final casting (Thanks to @msigley)
if(String(dateString).match(/^[0-9]*$/)) {
dateString = Number(dateString);
}
// Replace dashes to slashes
if(String(dateString).match(/\-/)) {
dateString = String(dateString).replace(/\-/g, '/');
}
return new Date(dateString);
} else {
throw new Error('Couldn\'t cast `' + dateString +
'` to a date object.');
}
}
// Map to convert from a directive to offset object property
var DIRECTIVE_KEY_MAP = {
'Y': 'years',
'm': 'months',
'n': 'daysToMonth',
'w': 'weeks',
'd': 'daysToWeek',
'D': 'totalDays',
'H': 'hours',
'M': 'minutes',
'S': 'seconds'
};
// Returns an escaped regexp...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Fiddle Pages
Your fiddles accessible under a custom domain and a vanity path.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!