Browse Source

Started JSLint compliance and cleanup

pull/177/head
Zach Wise 13 years ago
parent
commit
b316235a0d
  1. 31
      source/js/Core/VMM.Browser.js
  2. 110
      source/js/Core/VMM.Date.js
  3. 18
      source/js/Core/VMM.FileExtention.js
  4. 2
      source/js/Core/VMM.Library.js
  5. 30
      source/js/Core/VMM.LoadLib.js
  6. 56
      source/js/Core/VMM.Util.js
  7. 1
      source/js/Slider/VMM.Slider.js

31
source/js/Core/VMM.Browser.js

@ -1,4 +1,4 @@
/* DEVICE AND BROWSER DETECTION /* * DEVICE AND BROWSER DETECTION
================================================== */ ================================================== */
if(typeof VMM != 'undefined' && typeof VMM.Browser == 'undefined') { if(typeof VMM != 'undefined' && typeof VMM.Browser == 'undefined') {
@ -13,37 +13,44 @@ if(typeof VMM != 'undefined' && typeof VMM.Browser == 'undefined') {
this.orientation = this.searchOrientation(window.orientation); this.orientation = this.searchOrientation(window.orientation);
}, },
searchOrientation: function(orientation) { searchOrientation: function(orientation) {
var orient = "";
if ( orientation == 0 || orientation == 180) { if ( orientation == 0 || orientation == 180) {
return "portrait"; orient = "portrait";
} else if ( orientation == 90 || orientation == -90) { } else if ( orientation == 90 || orientation == -90) {
return "landscape"; orient = "landscape";
} else { } else {
return "normal"; orient = "normal";
} }
return orient;
}, },
searchDevice: function(d) { searchDevice: function(d) {
var device = "";
if (d.match(/Android/i) || d.match(/iPhone|iPod/i)) { if (d.match(/Android/i) || d.match(/iPhone|iPod/i)) {
return "mobile"; device = "mobile";
} else if (d.match(/iPad/i)) { } else if (d.match(/iPad/i)) {
return "tablet"; device = "tablet";
} else if (d.match(/BlackBerry/i) || d.match(/IEMobile/i)) { } else if (d.match(/BlackBerry/i) || d.match(/IEMobile/i)) {
return "other mobile"; device = "other mobile";
} else { } else {
return "desktop"; device = "desktop";
} }
return device;
}, },
searchString: function (data) { searchString: function (data) {
for (var i=0;i<data.length;i++) { for (var i=0;i<data.length;i++) {
var dataString = data[i].string; var dataString = data[i].string,
var dataProp = data[i].prop; dataProp = data[i].prop;
this.versionSearchString = data[i].versionSearch || data[i].identity; this.versionSearchString = data[i].versionSearch || data[i].identity;
if (dataString) { if (dataString) {
if (dataString.indexOf(data[i].subString) != -1) if (dataString.indexOf(data[i].subString) != -1) {
return data[i].identity; return data[i].identity;
} }
else if (dataProp) } else if (dataProp) {
return data[i].identity; return data[i].identity;
} }
}
}, },
searchVersion: function (dataString) { searchVersion: function (dataString) {
var index = dataString.indexOf(this.versionSearchString); var index = dataString.indexOf(this.versionSearchString);

110
source/js/Core/VMM.Date.js

@ -1,10 +1,11 @@
/* Utilities and Useful Functions /* * Utilities and Useful Functions
================================================== */ ================================================== */
if(typeof VMM != 'undefined' && typeof VMM.Date == 'undefined') { if(typeof VMM != 'undefined' && typeof VMM.Date == 'undefined') {
VMM.Date = ({ VMM.Date = ({
init: function() { init: function() {
"use strict";
return this; return this;
}, },
@ -41,6 +42,7 @@ if(typeof VMM != 'undefined' && typeof VMM.Date == 'undefined') {
}, },
setLanguage: function(lang) { setLanguage: function(lang) {
"use strict";
trace("SET DATE LANGUAGE"); trace("SET DATE LANGUAGE");
VMM.Date.dateformats = lang.dateformats; VMM.Date.dateformats = lang.dateformats;
VMM.Date.month = lang.date.month; VMM.Date.month = lang.date.month;
@ -52,72 +54,75 @@ if(typeof VMM != 'undefined' && typeof VMM.Date == 'undefined') {
}, },
parse: function(d) { parse: function(d) {
"use strict";
var date,
date_array,
time_array,
time_parse;
if (type.of(d) == "date") { if (type.of(d) == "date") {
return d; date = d;
} else { } else {
var _date = new Date(0, 0, 1, 0, 0, 0, 0); date = new Date(0, 0, 1, 0, 0, 0, 0);
//var _date = new Date("January 1, 0000 00:00:00")
var _d_array, _t_array;
var _time_parse, _times;
if ( d.match(/,/gi) ) { if ( d.match(/,/gi) ) {
_d_array = d.split(","); date_array = d.split(",");
for(var i = 0; i < _d_array.length; i++) { for(var i = 0; i < date_array.length; i++) {
_d_array[i] = parseInt(_d_array[i]); date_array[i] = parseInt(date_array[i]);
} }
if ( _d_array[0] ) { _date.setFullYear( _d_array[0]); } if ( date_array[0] ) { date.setFullYear( date_array[0]); }
if ( _d_array[1] > 1 ) { _date.setMonth( _d_array[1] - 1); } if ( date_array[1] > 1 ) { date.setMonth( date_array[1] - 1); }
if ( _d_array[2] > 1 ) { _date.setDate( _d_array[2]); } if ( date_array[2] > 1 ) { date.setDate( date_array[2]); }
if ( _d_array[3] > 1 ) { _date.setHours( _d_array[3]); } if ( date_array[3] > 1 ) { date.setHours( date_array[3]); }
if ( _d_array[4] > 1 ) { _date.setMinutes( _d_array[4]); } if ( date_array[4] > 1 ) { date.setMinutes( date_array[4]); }
if ( _d_array[5] > 1 ) { _date.setSeconds( _d_array[5]); } if ( date_array[5] > 1 ) { date.setSeconds( date_array[5]); }
if ( _d_array[6] > 1 ) { _date.setMilliseconds( _d_array[6]); } if ( date_array[6] > 1 ) { date.setMilliseconds( date_array[6]); }
} else if (d.match("/")) { } else if (d.match("/")) {
if (d.match(" ")) { if (d.match(" ")) {
_time_parse = d.split(" "); time_parse = d.split(" ");
if (d.match(":")) { if (d.match(":")) {
_t_array = _time_parse[1].split(":"); time_array = time_parse[1].split(":");
if ( _t_array[0] >= 1 ) { _date.setHours( _t_array[0]); } if ( time_array[0] >= 1 ) { date.setHours( time_array[0]); }
if ( _t_array[1] >= 1 ) { _date.setMinutes( _t_array[1]); } if ( time_array[1] >= 1 ) { date.setMinutes( time_array[1]); }
if ( _t_array[2] >= 1 ) { _date.setSeconds( _t_array[2]); } if ( time_array[2] >= 1 ) { date.setSeconds( time_array[2]); }
if ( _t_array[3] >= 1 ) { _date.setMilliseconds( _t_array[3]); } if ( time_array[3] >= 1 ) { date.setMilliseconds( time_array[3]); }
} }
_d_array = _time_parse[0].split("/"); date_array = time_parse[0].split("/");
} else { } else {
_d_array = d.split("/"); date_array = d.split("/");
} }
if ( _d_array[2] ) { _date.setFullYear( _d_array[2]); } if ( date_array[2] ) { date.setFullYear( date_array[2]); }
if ( _d_array[0] > 1 ) { _date.setMonth( _d_array[0] - 1); } if ( date_array[0] > 1 ) { date.setMonth( date_array[0] - 1); }
if ( _d_array[1] > 1 ) { _date.setDate( _d_array[1]); } if ( date_array[1] > 1 ) { date.setDate( date_array[1]); }
} else if (d.length <= 5) { } else if (d.length <= 5) {
_date.setFullYear(parseInt(d)); date.setFullYear(parseInt(d));
_date.setMonth(0); date.setMonth(0);
_date.setDate(1); date.setDate(1);
_date.setHours(0); date.setHours(0);
_date.setMinutes(0); date.setMinutes(0);
_date.setSeconds(0); date.setSeconds(0);
_date.setMilliseconds(0); date.setMilliseconds(0);
} else if (d.match("T")) { } else if (d.match("T")) {
if (navigator.userAgent.match(/MSIE\s(?!9.0)/)) { if (navigator.userAgent.match(/MSIE\s(?!9.0)/)) {
// IE 8 < Won't accept dates with a "-" in them. // IE 8 < Won't accept dates with a "-" in them.
_time_parse = d.split("T"); time_parse = d.split("T");
if (d.match(":")) { if (d.match(":")) {
_t_array = _time_parse[1].split(":"); time_array = _time_parse[1].split(":");
if ( _t_array[0] >= 1 ) { _date.setHours( _t_array[0]); } if ( time_array[0] >= 1 ) { date.setHours( time_array[0]); }
if ( _t_array[1] >= 1 ) { _date.setMinutes( _t_array[1]); } if ( time_array[1] >= 1 ) { date.setMinutes( time_array[1]); }
if ( _t_array[2] >= 1 ) { _date.setSeconds( _t_array[2]); } if ( time_array[2] >= 1 ) { date.setSeconds( time_array[2]); }
if ( _t_array[3] >= 1 ) { _date.setMilliseconds( _t_array[3]); } if ( time_array[3] >= 1 ) { date.setMilliseconds( time_array[3]); }
} }
_d_array = _time_parse[0].split("-"); _d_array = time_parse[0].split("-");
if ( _d_array[0] ) { _date.setFullYear( _d_array[0]); } if ( date_array[0] ) { date.setFullYear( date_array[0]); }
if ( _d_array[1] > 1 ) { _date.setMonth( _d_array[1] - 1); } if ( date_array[1] > 1 ) { date.setMonth( date_array[1] - 1); }
if ( _d_array[2] > 1 ) { _date.setDate( _d_array[2]); } if ( date_array[2] > 1 ) { date.setDate( date_array[2]); }
} else { } else {
_date = new Date(Date.parse(d)); date = new Date(Date.parse(d));
} }
} else { } else {
_date = new Date( date = new Date(
parseInt(d.slice(0,4)), parseInt(d.slice(0,4)),
parseInt(d.slice(4,6)) - 1, parseInt(d.slice(4,6)) - 1,
parseInt(d.slice(6,8)), parseInt(d.slice(6,8)),
@ -125,16 +130,17 @@ if(typeof VMM != 'undefined' && typeof VMM.Date == 'undefined') {
parseInt(d.slice(10,12)) parseInt(d.slice(10,12))
); );
} }
return _date;
} }
return date;
}, },
prettyDate: function(d, is_abbr, d2) { prettyDate: function(d, is_abbr, d2) {
var _date; var _date,
var _date2; _date2,
var format; format,
var bc_check; bc_check,
var is_pair = false; is_pair = false;
if (d2 != null) { if (d2 != null) {
is_pair = true; is_pair = true;

18
source/js/Core/VMM.FileExtention.js

@ -1,27 +1,21 @@
/* File Extention /* * File Extention
================================================== */ ================================================== */
if(typeof VMM != 'undefined' && typeof VMM.FileExtention == 'undefined') { if(typeof VMM != 'undefined' && typeof VMM.FileExtention == 'undefined') {
//VMM.FileExtention.googleDocType(url);
VMM.FileExtention = { VMM.FileExtention = {
googleDocType: function(url) { googleDocType: function(url) {
var fileName = url; var fileName = url,
var fileExtension = ""; fileExtension = "",
//fileExtension = fileName.substr(5); validFileExtensions = ["DOC","DOCX","XLS","XLSX","PPT","PPTX","PDF","PAGES","AI","PSD","TIFF","DXF","SVG","EPS","PS","TTF","XPS","ZIP","RAR"],
flag = false;
fileExtension = fileName.substr(fileName.length - 5, 5); fileExtension = fileName.substr(fileName.length - 5, 5);
var validFileExtensions = ["DOC","DOCX","XLS","XLSX","PPT","PPTX","PDF","PAGES","AI","PSD","TIFF","DXF","SVG","EPS","PS","TTF","XPS","ZIP","RAR"];
var flag = false;
for (var i = 0; i < validFileExtensions.length; i++) { for (var i = 0; i < validFileExtensions.length; i++) {
if (fileExtension.toLowerCase().match(validFileExtensions[i].toString().toLowerCase()) || fileName.match("docs.google.com") ) { if (fileExtension.toLowerCase().match(validFileExtensions[i].toString().toLowerCase()) || fileName.match("docs.google.com") ) {
flag = true; flag = true;
} }
} }
return flag; return flag;
} }
} }
} }

2
source/js/Core/VMM.Library.js

@ -1,4 +1,4 @@
/* LIBRARY ABSTRACTION /* * LIBRARY ABSTRACTION
================================================== */ ================================================== */
if(typeof VMM != 'undefined') { if(typeof VMM != 'undefined') {

30
source/js/Core/VMM.LoadLib.js

@ -1,19 +1,17 @@
/* /* * LoadLib Based on LazyLoad by Ryan Grove
LoadLib * https://github.com/rgrove/lazyload/
Based on LazyLoad by Ryan Grove * Copyright (c) 2011 Ryan Grove <ryan@wonko.com>
https://github.com/rgrove/lazyload/ * All rights reserved.
Copyright (c) 2011 Ryan Grove <ryan@wonko.com>
All rights reserved. * Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the 'Software'), to deal in
Permission is hereby granted, free of charge, to any person obtaining a copy of * the Software without restriction, including without limitation the rights to
this software and associated documentation files (the 'Software'), to deal in * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software without restriction, including without limitation the rights to * the Software, and to permit persons to whom the Software is furnished to do so,
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of * subject to the following conditions:
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions: * The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
================================================== */ ================================================== */
window.loadedJS = []; window.loadedJS = [];

56
source/js/Core/VMM.Util.js

@ -1,4 +1,4 @@
/* Utilities and Useful Functions /* * Utilities and Useful Functions
================================================== */ ================================================== */
if(typeof VMM != 'undefined' && typeof VMM.Util == 'undefined') { if(typeof VMM != 'undefined' && typeof VMM.Util == 'undefined') {
@ -8,12 +8,12 @@ if(typeof VMM != 'undefined' && typeof VMM.Util == 'undefined') {
return this; return this;
}, },
/* CORRECT PROTOCOL (DOES NOT WORK) /* * CORRECT PROTOCOL (DOES NOT WORK)
================================================== */ ================================================== */
correctProtocol: function(url) { correctProtocol: function(url) {
var loc = (window.parent.location.protocol).toString(); var loc = (window.parent.location.protocol).toString(),
var prefix = ""; prefix = "",
var _url = url.split("://", 2); the_url = url.split("://", 2);
if (loc.match("http")) { if (loc.match("http")) {
prefix = loc; prefix = loc;
@ -21,11 +21,11 @@ if(typeof VMM != 'undefined' && typeof VMM.Util == 'undefined') {
prefix = "https"; prefix = "https";
} }
return prefix + "://" + _url[1]; return prefix + "://" + the_url[1];
}, },
/* GET OBJECT ATTRIBUTE BY INDEX /* * GET OBJECT ATTRIBUTE BY INDEX
================================================== */ ================================================== */
getObjectAttributeByIndex: function(obj, index) { getObjectAttributeByIndex: function(obj, index) {
if(typeof obj != 'undefined') { if(typeof obj != 'undefined') {
@ -42,17 +42,17 @@ if(typeof VMM != 'undefined' && typeof VMM.Util == 'undefined') {
} }
}, },
/* RANDOM BETWEEN /* * RANDOM BETWEEN
================================================== */ ================================================== */
//VMM.Util.randomBetween(1, 3) //VMM.Util.randomBetween(1, 3)
randomBetween: function(min, max) { randomBetween: function(min, max) {
return Math.floor(Math.random() * (max - min + 1) + min); return Math.floor(Math.random() * (max - min + 1) + min);
}, },
/* AVERAGE /* * AVERAGE
http://jsfromhell.com/array/average * http://jsfromhell.com/array/average
var x = VMM.Util.average([2, 3, 4]); * var x = VMM.Util.average([2, 3, 4]);
VMM.Util.average([2, 3, 4]).mean * VMM.Util.average([2, 3, 4]).mean
================================================== */ ================================================== */
average: function(a) { average: function(a) {
var r = {mean: 0, variance: 0, deviation: 0}, t = a.length; var r = {mean: 0, variance: 0, deviation: 0}, t = a.length;
@ -61,7 +61,7 @@ if(typeof VMM != 'undefined' && typeof VMM.Util == 'undefined') {
return r.deviation = Math.sqrt(r.variance = s / t), r; return r.deviation = Math.sqrt(r.variance = s / t), r;
}, },
/* CUSTOM SORT /* * CUSTOM SORT
================================================== */ ================================================== */
customSort: function(a, b) { customSort: function(a, b) {
var a1= a, b1= b; var a1= a, b1= b;
@ -69,7 +69,7 @@ if(typeof VMM != 'undefined' && typeof VMM.Util == 'undefined') {
return a1> b1? 1: -1; return a1> b1? 1: -1;
}, },
/* Remove Duplicates from Array /* * Remove Duplicates from Array
================================================== */ ================================================== */
deDupeArray: function(arr) { deDupeArray: function(arr) {
var i, var i,
@ -86,7 +86,7 @@ if(typeof VMM != 'undefined' && typeof VMM.Util == 'undefined') {
return out; return out;
}, },
/* Given an int or decimal, turn that into string in $xxx,xxx.xx format. /* * Given an int or decimal, turn that into string in $xxx,xxx.xx format.
================================================== */ ================================================== */
number2money: function(n, symbol, padding) { number2money: function(n, symbol, padding) {
var symbol = (symbol !== null) ? symbol : true; // add $ var symbol = (symbol !== null) ? symbol : true; // add $
@ -100,7 +100,7 @@ if(typeof VMM != 'undefined' && typeof VMM.Util == 'undefined') {
return formatted; return formatted;
}, },
/* Returns a word count number /* * Returns a word count number
================================================== */ ================================================== */
wordCount: function(s) { wordCount: function(s) {
var fullStr = s + " "; var fullStr = s + " ";
@ -158,7 +158,7 @@ if(typeof VMM != 'undefined' && typeof VMM.Util == 'undefined') {
return (n < 10 ? '0' : '') + n; return (n < 10 ? '0' : '') + n;
}, },
/* Returns a truncated segement of a long string of between min and max words. If possible, ends on a period (otherwise goes to max). /* * Returns a truncated segement of a long string of between min and max words. If possible, ends on a period (otherwise goes to max).
================================================== */ ================================================== */
truncateWords: function(s, min, max) { truncateWords: function(s, min, max) {
@ -191,7 +191,7 @@ if(typeof VMM != 'undefined' && typeof VMM.Util == 'undefined') {
return (result.join(' ')); return (result.join(' '));
}, },
/* Turns plain text links into real links /* * Turns plain text links into real links
================================================== */ ================================================== */
linkify: function(text,targets,is_touch) { linkify: function(text,targets,is_touch) {
@ -251,7 +251,7 @@ if(typeof VMM != 'undefined' && typeof VMM.Util == 'undefined') {
.replace(/<\/b>/gim, ""); .replace(/<\/b>/gim, "");
}, },
/* Turns plain text links into real links /* * Turns plain text links into real links
================================================== */ ================================================== */
// VMM.Util.unlinkify(); // VMM.Util.unlinkify();
unlinkify: function(text) { unlinkify: function(text) {
@ -269,13 +269,13 @@ if(typeof VMM != 'undefined' && typeof VMM.Util == 'undefined') {
return text; return text;
}, },
/* TK /* * TK
================================================== */ ================================================== */
nl2br: function(text) { nl2br: function(text) {
return text.replace(/(\r\n|[\r\n]|\\n|\\r)/g,"<br/>"); return text.replace(/(\r\n|[\r\n]|\\n|\\r)/g,"<br/>");
}, },
/* Generate a Unique ID /* * Generate a Unique ID
================================================== */ ================================================== */
// VMM.Util.unique_ID(size); // VMM.Util.unique_ID(size);
unique_ID: function(size) { unique_ID: function(size) {
@ -299,13 +299,13 @@ if(typeof VMM != 'undefined' && typeof VMM.Util == 'undefined') {
return randomID(size); return randomID(size);
}, },
/* Tells you if a number is even or not /* * Tells you if a number is even or not
================================================== */ ================================================== */
// VMM.Util.isEven(n) // VMM.Util.isEven(n)
isEven: function(n){ isEven: function(n){
return (n%2 === 0) ? true : false; return (n%2 === 0) ? true : false;
}, },
/* Get URL Variables /* * Get URL Variables
================================================== */ ================================================== */
// var somestring = VMM.Util.getUrlVars(str_url)["varname"]; // var somestring = VMM.Util.getUrlVars(str_url)["varname"];
getUrlVars: function(string) { getUrlVars: function(string) {
@ -332,7 +332,7 @@ if(typeof VMM != 'undefined' && typeof VMM.Util == 'undefined') {
return vars; return vars;
}, },
/* Cleans up strings to become real HTML /* * Cleans up strings to become real HTML
================================================== */ ================================================== */
toHTML: function(text) { toHTML: function(text) {
@ -342,7 +342,7 @@ if(typeof VMM != 'undefined' && typeof VMM.Util == 'undefined') {
return text.replace(/\s\s/g,"&nbsp;&nbsp;"); return text.replace(/\s\s/g,"&nbsp;&nbsp;");
}, },
/* Returns text strings as CamelCase /* * Returns text strings as CamelCase
================================================== */ ================================================== */
toCamelCase: function(s,forceLowerCase) { toCamelCase: function(s,forceLowerCase) {
@ -358,12 +358,12 @@ if(typeof VMM != 'undefined' && typeof VMM.Util == 'undefined') {
return sps.join(" "); return sps.join(" ");
}, },
/* Replaces dumb quote marks with smart ones /* * Replaces dumb quote marks with smart ones
================================================== */ ================================================== */
properQuotes: function(str) { properQuotes: function(str) {
return str.replace(/\"([^\"]*)\"/gi,"&#8220;$1&#8221;"); return str.replace(/\"([^\"]*)\"/gi,"&#8220;$1&#8221;");
}, },
/* Given an int or decimal, return a string with pretty commas in the correct spot. /* * Given an int or decimal, return a string with pretty commas in the correct spot.
================================================== */ ================================================== */
niceNumber: function(n){ niceNumber: function(n){
@ -391,7 +391,7 @@ if(typeof VMM != 'undefined' && typeof VMM.Util == 'undefined') {
} }
}, },
/* Transform text to Title Case /* * Transform text to Title Case
================================================== */ ================================================== */
toTitleCase: function(t){ toTitleCase: function(t){
if ( VMM.Browser.browser == "Explorer" && parseInt(VMM.Browser.version, 10) >= 7) { if ( VMM.Browser.browser == "Explorer" && parseInt(VMM.Browser.version, 10) >= 7) {

1
source/js/Slider/VMM.Slider.js

@ -611,6 +611,7 @@ if(typeof VMM != 'undefined' && typeof VMM.Slider == 'undefined') {
VMM.bindEvent(".nav-next", onNextClick); VMM.bindEvent(".nav-next", onNextClick);
VMM.bindEvent(".nav-previous", onPrevClick); VMM.bindEvent(".nav-previous", onPrevClick);
VMM.bindEvent(window, onKeypressNav, 'keydown'); VMM.bindEvent(window, onKeypressNav, 'keydown');
} }
/* BUILD /* BUILD

Loading…
Cancel
Save