Commit e145660a authored by Craig Earley's avatar Craig Earley
Browse files

added the javascript files for jquery and bootstrap, borrowed from fieldsci viz

parent 7ca92a9e
This diff is collapsed.
This diff is collapsed.
// Converts a date into '12-Oct-1984' format
function getDateString(dt) {
return dt.getDate() + '-' +
['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'][dt.getMonth()] +
'-' + dt.getFullYear();
}
// Converts a date into 'July 2010' format
function getMonthYearString(dt) {
return ['January','February','March','April','May','June','July',
'August','September','October','November','December'][dt.getMonth()] +
' ' + dt.getFullYear();
}
// This is the function called when the user clicks any button
function chooseDate(e) {
var targ; // Crossbrowser way to find the target (http://www.quirksmode.org/js/events_properties.html)
if (!e) var e = window.event;
if (e.target) targ = e.target;
else if (e.srcElement) targ = e.srcElement;
if (targ.nodeType == 3) targ = targ.parentNode; // defeat Safari bug
var div = targ.parentNode.parentNode.parentNode.parentNode.parentNode; // Find the div
var idOfTextbox = div.getAttribute('datepickertextbox'); // Get the textbox id which was saved in the div
var textbox = document.getElementById(idOfTextbox); // Find the textbox now
if (targ.value=='<' || targ.value=='>' || targ.value=='<<' || targ.value=='>>') { // Do they want the change the month?
createCalendar(div, new Date(targ.getAttribute('date')));
return;
}
textbox.value = targ.getAttribute('date'); // Set the selected date
div.parentNode.removeChild(div); // Remove the dropdown box now
}
// Parse a date in d-MMM-yyyy format
function parseMyDate(d) {
if (d=="") return new Date('NotADate'); // For Safari
var a = d.split('-');
if (a.length!=3) return new Date(d); // Missing 2 dashes
var m = -1; // Now find the month
if (a[1]=='Jan') m=0;
if (a[1]=='Feb') m=1;
if (a[1]=='Mar') m=2;
if (a[1]=='Apr') m=3;
if (a[1]=='May') m=4;
if (a[1]=='Jun') m=5;
if (a[1]=='Jul') m=6;
if (a[1]=='Aug') m=7;
if (a[1]=='Sep') m=8;
if (a[1]=='Oct') m=9;
if (a[1]=='Nov') m=10;
if (a[1]=='Dec') m=11;
if (m<0) return new Date(d); // Couldn't find the month
return new Date(a[2],m,a[0],0,0,0,0);
}
// This creates the calendar for a given month
function createCalendar(div, month) {
var idOfTextbox = div.getAttribute('datepickertextbox'); // Get the textbox id which was saved in the div
var textbox = document.getElementById(idOfTextbox); // Find the textbox now
var tbl = document.createElement('table');
var topRow = tbl.insertRow(-1);
var td = topRow.insertCell(-1);
var lastYearBn = document.createElement('input');
lastYearBn.type='button'; // Have to immediately set the type due to IE
td.appendChild(lastYearBn);
lastYearBn.value='<<';
lastYearBn.onclick=chooseDate;
lastYearBn.setAttribute('date',new Date(month.getFullYear(),month.getMonth()-12,1,0,0,0,0).toString());
var td = topRow.insertCell(-1);
var lastMonthBn = document.createElement('input');
lastMonthBn.type='button'; // Have to immediately set the type due to IE
td.appendChild(lastMonthBn);
lastMonthBn.value='<';
lastMonthBn.onclick=chooseDate;
lastMonthBn.setAttribute('date',new Date(month.getFullYear(),month.getMonth()-1,1,0,0,0,0).toString());
var td = topRow.insertCell(-1);
td.colSpan=3;
var mon = document.createElement('input');
mon.type='text';
td.appendChild(mon);
mon.value = getMonthYearString(month);
mon.size=15;
mon.disabled='disabled';
mon.className='monthDsp';
var td = topRow.insertCell(-1);
var nextMonthBn = document.createElement('input');
nextMonthBn.type='button';
td.appendChild(nextMonthBn);
nextMonthBn.value = '>';
nextMonthBn.onclick=chooseDate;
nextMonthBn.setAttribute('date',new Date(month.getFullYear(),month.getMonth()+1,1,0,0,0,0).toString());
var td = topRow.insertCell(-1);
var nextYearBn = document.createElement('input');
nextYearBn.type='button'; // Have to immediately set the type due to IE
td.appendChild(nextYearBn);
nextYearBn.value='>>';
nextYearBn.onclick=chooseDate;
nextYearBn.setAttribute('date',new Date(month.getFullYear(),month.getMonth()+12,1,0,0,0,0).toString());
var daysRow = tbl.insertRow(-1);
daysRow.insertCell(-1).innerHTML="Mon";
daysRow.insertCell(-1).innerHTML="Tue";
daysRow.insertCell(-1).innerHTML="Wed";
daysRow.insertCell(-1).innerHTML="Thu";
daysRow.insertCell(-1).innerHTML="Fri";
daysRow.insertCell(-1).innerHTML="Sat";
daysRow.insertCell(-1).innerHTML="Sun";
daysRow.className='daysRow';
// Make the calendar
var selected = parseMyDate(textbox.value); // Try parsing the date
var today = new Date();
date = new Date(month.getFullYear(),month.getMonth(),1,0,0,0,0); // Starting at the 1st of the month
var extras = (date.getDay() + 6) % 7; // How many days of the last month do we need to include?
date.setDate(date.getDate()-extras); // Skip back to the previous monday
while (1) { // Loop for each week
var tr = tbl.insertRow(-1);
for (i=0;i<7;i++) { // Loop each day of this week
var td = tr.insertCell(-1);
var inp = document.createElement('input');
inp.type = 'button';
td.appendChild(inp);
inp.value = date.getDate();
inp.onclick = chooseDate;
inp.setAttribute('date',getDateString(date));
if (date.getMonth() != month.getMonth()) {
if (inp.className) inp.className += ' ';
inp.className+='othermonth';
}
if (date.getDate()==today.getDate() && date.getMonth()==today.getMonth() && date.getFullYear()==today.getFullYear()) {
if (inp.className) inp.className += ' ';
inp.className+='today';
}
if (!isNaN(selected) && date.getDate()==selected.getDate() && date.getMonth()==selected.getMonth() && date.getFullYear()==selected.getFullYear()) {
if (inp.className) inp.className += ' ';
inp.className+='selected';
}
date.setDate(date.getDate()+1); // Increment a day
}
// We are done if we've moved on to the next month
if (date.getMonth() != month.getMonth()) {
break;
}
}
// At the end, we do a quick insert of the newly made table, hopefully to remove any chance of screen flicker
if (div.hasChildNodes()) { // For flicking between months
div.replaceChild(tbl, div.childNodes[0]);
} else { // For creating the calendar when they first click the icon
div.appendChild(tbl);
}
}
// This is called when they click the icon next to the date inputbox
function showDatePicker(idOfTextbox) {
var textbox = document.getElementById(idOfTextbox);
// See if the date picker is already there, if so, remove it
x = textbox.parentNode.getElementsByTagName('div');
for (i=0;i<x.length;i++) {
if (x[i].getAttribute('class')=='datepickerdropdown') {
textbox.parentNode.removeChild(x[i]);
return false;
}
}
// Grab the date, or use the current date if not valid
var date = parseMyDate(textbox.value);
if (isNaN(date)) date = new Date();
// Create the box
var div = document.createElement('div');
div.className='datepickerdropdown';
div.setAttribute('datepickertextbox', idOfTextbox); // Remember the textbox id in the div
createCalendar(div, date); // Create the calendar
insertAfter(div, textbox); // Add the box to screen just after the textbox
return false;
}
// Adds an item after an existing one
function insertAfter(newItem, existingItem) {
if (existingItem.nextSibling) { // Find the next sibling, and add newItem before it
existingItem.parentNode.insertBefore(newItem, existingItem.nextSibling);
} else { // In case the existingItem has no sibling after itself, append it
existingItem.parentNode.appendChild(newItem);
}
}
/*
* onDOMReady
* Copyright (c) 2009 Ryan Morr (ryanmorr.com)
* Licensed under the MIT license.
*/
function onDOMReady(fn,ctx){var ready,timer;var onStateChange=function(e){if(e&&e.type=="DOMContentLoaded"){fireDOMReady()}else if(e&&e.type=="load"){fireDOMReady()}else if(document.readyState){if((/loaded|complete/).test(document.readyState)){fireDOMReady()}else if(!!document.documentElement.doScroll){try{ready||document.documentElement.doScroll('left')}catch(e){return}fireDOMReady()}}};var fireDOMReady=function(){if(!ready){ready=true;fn.call(ctx||window);if(document.removeEventListener)document.removeEventListener("DOMContentLoaded",onStateChange,false);document.onreadystatechange=null;window.onload=null;clearInterval(timer);timer=null}};if(document.addEventListener)document.addEventListener("DOMContentLoaded",onStateChange,false);document.onreadystatechange=onStateChange;timer=setInterval(onStateChange,5);window.onload=onStateChange};
// This is called when the page loads, it searches for inputs where the class is 'datepicker'
onDOMReady(function(){
// Search for elements by class
var allElements = document.getElementsByTagName("*");
for (i=0; i<allElements.length; i++) {
var className = allElements[i].className;
if (className=='datepicker' || className.indexOf('datepicker ') != -1 || className.indexOf(' datepicker') != -1) {
// Found one! Now lets add a datepicker next to it
var a = document.createElement('a');
a.href='#';
a.className="datepickershow";
a.setAttribute('onclick','return showDatePicker("' + allElements[i].id + '")');
var img = document.createElement('img');
img.src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAABGdBTUEAAK/INwWK6QAAABh0RVh0U29mdHdhcmUAUGFpbnQuTkVUIHYzLjM2qefiJQAAAdtJREFUOE+Vj+9PUnEUxvPvar3xja96Q1hGEKG0ubZqbfHCNqIVA4eYLAwFp0LYD4iIJEdeRGGZwDAEcUOn9oNIvPcGgjBQfHE69/YFihe1zs59du7d83nOuR0AcOq/CgEqWbaHDqaD+clF1rLAmija6MsZ5vb0s9nB1xm168s9x67y6Y7q2TaXjo8tVKjUTv7Zt61pAkwt/UA3zFwFuxysV2BKAuYeMAnBcBaGukDdCaozaLg5sUGAiQDLA3IIDIBfAfO34N118PaDRwYvRfBcCMrTaLg2liTAOEW3NjzpBZsMpqUwKQaLCMYvwGMhjArQIDfGCTDqy3EAX47lfVTnCo3qCnOzJ8IpW6pJR2IEGHn7/bBaR5MLO8y8CtPuKO2J0nMfGdKr+5uZ4kVdhAD6N99K1bo7ynB5vHpj3AZ0NxWBbs0KAbTur8VKfTbGeFcbkc1sfnBHuA1CzTIB7js/H5SPffFW3q9sau2PDdLhxkl3X+wiQCVYf4Jt3h1Itmb8iBvEusZJd2a2CuXjxXUWU5dSnAZ5/b0QkOobgMKWzh8eMcXaXr6aYSqfcuXtbAkdbS3RfSD/MGDfvGFO9ZuSfY/ilx/GLumi57Vhgfp9W597ECJA2/a/v/4ENLpYKsDo3kgAAAAASUVORK5CYII=';
img.title='Show calendar';
a.appendChild(img);
insertAfter(a, allElements[i]);
}
}
});
This diff is collapsed.
var Hashids=function(){"use strict";function Hashids(salt,minHashLength,alphabet){var uniqueAlphabet,i,j,len,sepsLength,diff,guardCount;this.version="1.0.2";this.minAlphabetLength=16;this.sepDiv=3.5;this.guardDiv=12;this.errorAlphabetLength="error: alphabet must contain at least X unique characters";this.errorAlphabetSpace="error: alphabet cannot contain spaces";this.alphabet="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";this.seps="cfhistuCFHISTU";this.minHashLength=parseInt(minHashLength,10)>0?minHashLength:0;this.salt=typeof salt==="string"?salt:"";if(typeof alphabet==="string"){this.alphabet=alphabet}for(uniqueAlphabet="",i=0,len=this.alphabet.length;i!==len;i++){if(uniqueAlphabet.indexOf(this.alphabet.charAt(i))===-1){uniqueAlphabet+=this.alphabet.charAt(i)}}this.alphabet=uniqueAlphabet;if(this.alphabet.length<this.minAlphabetLength){throw this.errorAlphabetLength.replace("X",this.minAlphabetLength)}if(this.alphabet.search(" ")!==-1){throw this.errorAlphabetSpace}for(i=0,len=this.seps.length;i!==len;i++){j=this.alphabet.indexOf(this.seps.charAt(i));if(j===-1){this.seps=this.seps.substr(0,i)+" "+this.seps.substr(i+1)}else{this.alphabet=this.alphabet.substr(0,j)+" "+this.alphabet.substr(j+1)}}this.alphabet=this.alphabet.replace(/ /g,"");this.seps=this.seps.replace(/ /g,"");this.seps=this.consistentShuffle(this.seps,this.salt);if(!this.seps.length||this.alphabet.length/this.seps.length>this.sepDiv){sepsLength=Math.ceil(this.alphabet.length/this.sepDiv);if(sepsLength===1){sepsLength++}if(sepsLength>this.seps.length){diff=sepsLength-this.seps.length;this.seps+=this.alphabet.substr(0,diff);this.alphabet=this.alphabet.substr(diff)}else{this.seps=this.seps.substr(0,sepsLength)}}this.alphabet=this.consistentShuffle(this.alphabet,this.salt);guardCount=Math.ceil(this.alphabet.length/this.guardDiv);if(this.alphabet.length<3){this.guards=this.seps.substr(0,guardCount);this.seps=this.seps.substr(guardCount)}else{this.guards=this.alphabet.substr(0,guardCount);this.alphabet=this.alphabet.substr(guardCount)}}Hashids.prototype.encode=function(){var ret="",i,len,numbers=Array.prototype.slice.call(arguments);if(!numbers.length){return ret}if(numbers[0]instanceof Array){numbers=numbers[0]}for(i=0,len=numbers.length;i!==len;i++){if(typeof numbers[i]!=="number"||numbers[i]%1!==0||numbers[i]<0){return ret}}return this._encode(numbers)};Hashids.prototype.decode=function(hash){var ret=[];if(!hash.length||typeof hash!=="string"){return ret}return this._decode(hash,this.alphabet)};Hashids.prototype.encodeHex=function(str){var i,len,numbers;str=str.toString();if(!/^[0-9a-fA-F]+$/.test(str)){return""}numbers=str.match(/[\w\W]{1,12}/g);for(i=0,len=numbers.length;i!==len;i++){numbers[i]=parseInt("1"+numbers[i],16)}return this.encode.apply(this,numbers)};Hashids.prototype.decodeHex=function(hash){var ret=[],i,len,numbers=this.decode(hash);for(i=0,len=numbers.length;i!==len;i++){ret+=numbers[i].toString(16).substr(1)}return ret};Hashids.prototype._encode=function(numbers){var ret,lottery,i,len,number,buffer,last,sepsIndex,guardIndex,guard,halfLength,excess,alphabet=this.alphabet,numbersSize=numbers.length,numbersHashInt=0;for(i=0,len=numbers.length;i!==len;i++){numbersHashInt+=numbers[i]%(i+100)}lottery=ret=alphabet.charAt(numbersHashInt%alphabet.length);for(i=0,len=numbers.length;i!==len;i++){number=numbers[i];buffer=lottery+this.salt+alphabet;alphabet=this.consistentShuffle(alphabet,buffer.substr(0,alphabet.length));last=this.hash(number,alphabet);ret+=last;if(i+1<numbersSize){number%=last.charCodeAt(0)+i;sepsIndex=number%this.seps.length;ret+=this.seps.charAt(sepsIndex)}}if(ret.length<this.minHashLength){guardIndex=(numbersHashInt+ret[0].charCodeAt(0))%this.guards.length;guard=this.guards[guardIndex];ret=guard+ret;if(ret.length<this.minHashLength){guardIndex=(numbersHashInt+ret[2].charCodeAt(0))%this.guards.length;guard=this.guards[guardIndex];ret+=guard}}halfLength=parseInt(alphabet.length/2,10);while(ret.length<this.minHashLength){alphabet=this.consistentShuffle(alphabet,alphabet);ret=alphabet.substr(halfLength)+ret+alphabet.substr(0,halfLength);excess=ret.length-this.minHashLength;if(excess>0){ret=ret.substr(excess/2,this.minHashLength)}}return ret};Hashids.prototype._decode=function(hash,alphabet){var ret=[],i=0,lottery,len,subHash,buffer,r=new RegExp("["+this.guards+"]","g"),hashBreakdown=hash.replace(r," "),hashArray=hashBreakdown.split(" ");if(hashArray.length===3||hashArray.length===2){i=1}hashBreakdown=hashArray[i];if(typeof hashBreakdown[0]!=="undefined"){lottery=hashBreakdown[0];hashBreakdown=hashBreakdown.substr(1);r=new RegExp("["+this.seps+"]","g");hashBreakdown=hashBreakdown.replace(r," ");hashArray=hashBreakdown.split(" ");for(i=0,len=hashArray.length;i!==len;i++){subHash=hashArray[i];buffer=lottery+this.salt+alphabet;alphabet=this.consistentShuffle(alphabet,buffer.substr(0,alphabet.length));ret.push(this.unhash(subHash,alphabet))}if(this._encode(ret)!==hash){ret=[]}}return ret};Hashids.prototype.consistentShuffle=function(alphabet,salt){var integer,j,temp,i,v,p;if(!salt.length){return alphabet}for(i=alphabet.length-1,v=0,p=0;i>0;i--,v++){v%=salt.length;p+=integer=salt.charAt(v).charCodeAt(0);j=(integer+v+p)%i;temp=alphabet.charAt(j);alphabet=alphabet.substr(0,j)+alphabet.charAt(i)+alphabet.substr(j+1);alphabet=alphabet.substr(0,i)+temp+alphabet.substr(i+1)}return alphabet};Hashids.prototype.hash=function(input,alphabet){var hash="",alphabetLength=alphabet.length;do{hash=alphabet.charAt(input%alphabetLength)+hash;input=parseInt(input/alphabetLength,10)}while(input);return hash};Hashids.prototype.unhash=function(input,alphabet){var number=0,pos,i;for(i=0;i<input.length;i++){pos=alphabet.indexOf(input[i]);number+=pos*Math.pow(alphabet.length,input.length-i-1)}return number};if(typeof define==="function"&&typeof define.amd==="object"&&define.amd){define(function(){return Hashids})}return Hashids}();
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
// Returns true if a string is an integer
function isInteger(s) {
for (i = 0; i < s.length; i++) {
var c = s.charAt(i);
if (c<"0" || c>"9") return false;
}
return true;
}
// Make the time into a nice format as they type eg HHMM goes to HH:MM
function timePickerKeyup(e) {
var targ; // Crossbrowser way to find the target (http://www.quirksmode.org/js/events_properties.html)
if (!e) var e = window.event;
if (e.target) targ = e.target;
else if (e.srcElement) targ = e.srcElement;
if (targ.nodeType == 3) targ = targ.parentNode; // defeat Safari bug
if (targ.value.length==4 && isInteger(targ.value)) {
targ.value = targ.value.substr(0,2) + ':' + targ.value.substr(2,2);
}
}
// Gets called if they tab out of a time picker, to neaten it up
function timePickerBlur(e) {
var targ; // Crossbrowser way to find the target (http://www.quirksmode.org/js/events_properties.html)
if (!e) var e = window.event;
if (e.target) targ = e.target;
else if (e.srcElement) targ = e.srcElement;
if (targ.nodeType == 3) targ = targ.parentNode; // defeat Safari bug
if (targ.value.length==1 && isInteger(targ.value)) {
targ.value = '0' + targ.value + ':00';
}
if (targ.value.length==2 && isInteger(targ.value)) {
targ.value = targ.value + ':00';
}
if (targ.value.length==3 && isInteger(targ.value)) {
targ.value = '0' + targ.value.substr(0,1) + ':' + targ.value.substr(1,2);
}
if (targ.value.length==4 && isInteger(targ.value)) {
targ.value = targ.value.substr(0,2) + ':' + targ.value.substr(2,2);
}
}
// This is called when the page loads, it searches for inputs where the class is 'timepicker'
function timePickerInit() {
// Search for elements by class
var allElements = document.getElementsByTagName("*");
for (i=0; i<allElements.length; i++) {
var className = allElements[i].className;
if (className=='timepicker' || className.indexOf('timepicker ') != -1 || className.indexOf(' timepicker') != -1) {
allElements[i].onkeyup = timePickerKeyup;
allElements[i].onblur = timePickerBlur;
}
}
}
// Hook myself into the page load event
if (window.addEventListener) { // W3C standard
window.addEventListener('load', timePickerInit, false);
} else if (window.attachEvent) { // Microsoft
window.attachEvent('onload', timePickerInit);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment