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') {
@ -13,37 +13,44 @@ if(typeof VMM != 'undefined' && typeof VMM.Browser == 'undefined') {
this.orientation = this.searchOrientation(window.orientation);
},
searchOrientation: function(orientation) {
var orient = "";
if ( orientation == 0 || orientation == 180) {
return "portrait";
orient = "portrait";
} else if ( orientation == 90 || orientation == -90) {
return "landscape";
orient = "landscape";
} else {
return "normal";
orient = "normal";
}
return orient;
},
searchDevice: function(d) {
var device = "";
if (d.match(/Android/i) || d.match(/iPhone|iPod/i)) {
return "mobile";
device = "mobile";
} else if (d.match(/iPad/i)) {
return "tablet";
device = "tablet";
} else if (d.match(/BlackBerry/i) || d.match(/IEMobile/i)) {
return "other mobile";
device = "other mobile";
} else {
return "desktop";
device = "desktop";
}
return device;
},
searchString: function (data) {
for (var i=0;i<data.length;i++) {
var dataString = data[i].string;
var dataProp = data[i].prop;
var dataString = data[i].string,
dataProp = data[i].prop;
this.versionSearchString = data[i].versionSearch || data[i].identity;
if (dataString) {
if (dataString.indexOf(data[i].subString) != -1)
if (dataString.indexOf(data[i].subString) != -1) {
return data[i].identity;
}
else if (dataProp)
} else if (dataProp) {
return data[i].identity;
}
}
},
searchVersion: function (dataString) {
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') {
VMM.Date = ({
init: function() {
"use strict";
return this;
},
@ -41,6 +42,7 @@ if(typeof VMM != 'undefined' && typeof VMM.Date == 'undefined') {
},
setLanguage: function(lang) {
"use strict";
trace("SET DATE LANGUAGE");
VMM.Date.dateformats = lang.dateformats;
VMM.Date.month = lang.date.month;
@ -52,72 +54,75 @@ if(typeof VMM != 'undefined' && typeof VMM.Date == 'undefined') {
},
parse: function(d) {
"use strict";
var date,
date_array,
time_array,
time_parse;
if (type.of(d) == "date") {
return d;
date = d;
} else {
var _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;
date = new Date(0, 0, 1, 0, 0, 0, 0);
if ( d.match(/,/gi) ) {
_d_array = d.split(",");
for(var i = 0; i < _d_array.length; i++) {
_d_array[i] = parseInt(_d_array[i]);
date_array = d.split(",");
for(var i = 0; i < date_array.length; i++) {
date_array[i] = parseInt(date_array[i]);
}
if ( _d_array[0] ) { _date.setFullYear( _d_array[0]); }
if ( _d_array[1] > 1 ) { _date.setMonth( _d_array[1] - 1); }
if ( _d_array[2] > 1 ) { _date.setDate( _d_array[2]); }
if ( _d_array[3] > 1 ) { _date.setHours( _d_array[3]); }
if ( _d_array[4] > 1 ) { _date.setMinutes( _d_array[4]); }
if ( _d_array[5] > 1 ) { _date.setSeconds( _d_array[5]); }
if ( _d_array[6] > 1 ) { _date.setMilliseconds( _d_array[6]); }
if ( date_array[0] ) { date.setFullYear( date_array[0]); }
if ( date_array[1] > 1 ) { date.setMonth( date_array[1] - 1); }
if ( date_array[2] > 1 ) { date.setDate( date_array[2]); }
if ( date_array[3] > 1 ) { date.setHours( date_array[3]); }
if ( date_array[4] > 1 ) { date.setMinutes( date_array[4]); }
if ( date_array[5] > 1 ) { date.setSeconds( date_array[5]); }
if ( date_array[6] > 1 ) { date.setMilliseconds( date_array[6]); }
} else if (d.match("/")) {
if (d.match(" ")) {
_time_parse = d.split(" ");
time_parse = d.split(" ");
if (d.match(":")) {
_t_array = _time_parse[1].split(":");
if ( _t_array[0] >= 1 ) { _date.setHours( _t_array[0]); }
if ( _t_array[1] >= 1 ) { _date.setMinutes( _t_array[1]); }
if ( _t_array[2] >= 1 ) { _date.setSeconds( _t_array[2]); }
if ( _t_array[3] >= 1 ) { _date.setMilliseconds( _t_array[3]); }
time_array = time_parse[1].split(":");
if ( time_array[0] >= 1 ) { date.setHours( time_array[0]); }
if ( time_array[1] >= 1 ) { date.setMinutes( time_array[1]); }
if ( time_array[2] >= 1 ) { date.setSeconds( time_array[2]); }
if ( time_array[3] >= 1 ) { date.setMilliseconds( time_array[3]); }
}
_d_array = _time_parse[0].split("/");
date_array = time_parse[0].split("/");
} else {
_d_array = d.split("/");
date_array = d.split("/");
}
if ( _d_array[2] ) { _date.setFullYear( _d_array[2]); }
if ( _d_array[0] > 1 ) { _date.setMonth( _d_array[0] - 1); }
if ( _d_array[1] > 1 ) { _date.setDate( _d_array[1]); }
if ( date_array[2] ) { date.setFullYear( date_array[2]); }
if ( date_array[0] > 1 ) { date.setMonth( date_array[0] - 1); }
if ( date_array[1] > 1 ) { date.setDate( date_array[1]); }
} else if (d.length <= 5) {
_date.setFullYear(parseInt(d));
_date.setMonth(0);
_date.setDate(1);
_date.setHours(0);
_date.setMinutes(0);
_date.setSeconds(0);
_date.setMilliseconds(0);
date.setFullYear(parseInt(d));
date.setMonth(0);
date.setDate(1);
date.setHours(0);
date.setMinutes(0);
date.setSeconds(0);
date.setMilliseconds(0);
} else if (d.match("T")) {
if (navigator.userAgent.match(/MSIE\s(?!9.0)/)) {
// IE 8 < Won't accept dates with a "-" in them.
_time_parse = d.split("T");
time_parse = d.split("T");
if (d.match(":")) {
_t_array = _time_parse[1].split(":");
if ( _t_array[0] >= 1 ) { _date.setHours( _t_array[0]); }
if ( _t_array[1] >= 1 ) { _date.setMinutes( _t_array[1]); }
if ( _t_array[2] >= 1 ) { _date.setSeconds( _t_array[2]); }
if ( _t_array[3] >= 1 ) { _date.setMilliseconds( _t_array[3]); }
time_array = _time_parse[1].split(":");
if ( time_array[0] >= 1 ) { date.setHours( time_array[0]); }
if ( time_array[1] >= 1 ) { date.setMinutes( time_array[1]); }
if ( time_array[2] >= 1 ) { date.setSeconds( time_array[2]); }
if ( time_array[3] >= 1 ) { date.setMilliseconds( time_array[3]); }
}
_d_array = _time_parse[0].split("-");
if ( _d_array[0] ) { _date.setFullYear( _d_array[0]); }
if ( _d_array[1] > 1 ) { _date.setMonth( _d_array[1] - 1); }
if ( _d_array[2] > 1 ) { _date.setDate( _d_array[2]); }
_d_array = time_parse[0].split("-");
if ( date_array[0] ) { date.setFullYear( date_array[0]); }
if ( date_array[1] > 1 ) { date.setMonth( date_array[1] - 1); }
if ( date_array[2] > 1 ) { date.setDate( date_array[2]); }
} else {
_date = new Date(Date.parse(d));
date = new Date(Date.parse(d));
}
} else {
_date = new Date(
date = new Date(
parseInt(d.slice(0,4)),
parseInt(d.slice(4,6)) - 1,
parseInt(d.slice(6,8)),
@ -125,16 +130,17 @@ if(typeof VMM != 'undefined' && typeof VMM.Date == 'undefined') {
parseInt(d.slice(10,12))
);
}
return _date;
}
return date;
},
prettyDate: function(d, is_abbr, d2) {
var _date;
var _date2;
var format;
var bc_check;
var is_pair = false;
var _date,
_date2,
format,
bc_check,
is_pair = false;
if (d2 != null) {
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') {
//VMM.FileExtention.googleDocType(url);
VMM.FileExtention = {
googleDocType: function(url) {
var fileName = url;
var fileExtension = "";
//fileExtension = fileName.substr(5);
var fileName = url,
fileExtension = "",
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);
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++) {
if (fileExtension.toLowerCase().match(validFileExtensions[i].toString().toLowerCase()) || fileName.match("docs.google.com") ) {
flag = true;
}
}
return flag;
}
}
}

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

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

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

@ -1,19 +1,17 @@
/*
LoadLib
Based on LazyLoad by Ryan Grove
https://github.com/rgrove/lazyload/
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
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
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.
/* * LoadLib Based on LazyLoad by Ryan Grove
* https://github.com/rgrove/lazyload/
* 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
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* 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.
================================================== */
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') {
@ -8,12 +8,12 @@ if(typeof VMM != 'undefined' && typeof VMM.Util == 'undefined') {
return this;
},
/* CORRECT PROTOCOL (DOES NOT WORK)
/* * CORRECT PROTOCOL (DOES NOT WORK)
================================================== */
correctProtocol: function(url) {
var loc = (window.parent.location.protocol).toString();
var prefix = "";
var _url = url.split("://", 2);
var loc = (window.parent.location.protocol).toString(),
prefix = "",
the_url = url.split("://", 2);
if (loc.match("http")) {
prefix = loc;
@ -21,11 +21,11 @@ if(typeof VMM != 'undefined' && typeof VMM.Util == 'undefined') {
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) {
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)
randomBetween: function(min, max) {
return Math.floor(Math.random() * (max - min + 1) + min);
},
/* AVERAGE
http://jsfromhell.com/array/average
var x = VMM.Util.average([2, 3, 4]);
VMM.Util.average([2, 3, 4]).mean
/* * AVERAGE
* http://jsfromhell.com/array/average
* var x = VMM.Util.average([2, 3, 4]);
* VMM.Util.average([2, 3, 4]).mean
================================================== */
average: function(a) {
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;
},
/* CUSTOM SORT
/* * CUSTOM SORT
================================================== */
customSort: function(a, b) {
var a1= a, b1= b;
@ -69,7 +69,7 @@ if(typeof VMM != 'undefined' && typeof VMM.Util == 'undefined') {
return a1> b1? 1: -1;
},
/* Remove Duplicates from Array
/* * Remove Duplicates from Array
================================================== */
deDupeArray: function(arr) {
var i,
@ -86,7 +86,7 @@ if(typeof VMM != 'undefined' && typeof VMM.Util == 'undefined') {
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) {
var symbol = (symbol !== null) ? symbol : true; // add $
@ -100,7 +100,7 @@ if(typeof VMM != 'undefined' && typeof VMM.Util == 'undefined') {
return formatted;
},
/* Returns a word count number
/* * Returns a word count number
================================================== */
wordCount: function(s) {
var fullStr = s + " ";
@ -158,7 +158,7 @@ if(typeof VMM != 'undefined' && typeof VMM.Util == 'undefined') {
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) {
@ -191,7 +191,7 @@ if(typeof VMM != 'undefined' && typeof VMM.Util == 'undefined') {
return (result.join(' '));
},
/* Turns plain text links into real links
/* * Turns plain text links into real links
================================================== */
linkify: function(text,targets,is_touch) {
@ -251,7 +251,7 @@ if(typeof VMM != 'undefined' && typeof VMM.Util == 'undefined') {
.replace(/<\/b>/gim, "");
},
/* Turns plain text links into real links
/* * Turns plain text links into real links
================================================== */
// VMM.Util.unlinkify();
unlinkify: function(text) {
@ -269,13 +269,13 @@ if(typeof VMM != 'undefined' && typeof VMM.Util == 'undefined') {
return text;
},
/* TK
/* * TK
================================================== */
nl2br: function(text) {
return text.replace(/(\r\n|[\r\n]|\\n|\\r)/g,"<br/>");
},
/* Generate a Unique ID
/* * Generate a Unique ID
================================================== */
// VMM.Util.unique_ID(size);
unique_ID: function(size) {
@ -299,13 +299,13 @@ if(typeof VMM != 'undefined' && typeof VMM.Util == 'undefined') {
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)
isEven: function(n){
return (n%2 === 0) ? true : false;
},
/* Get URL Variables
/* * Get URL Variables
================================================== */
// var somestring = VMM.Util.getUrlVars(str_url)["varname"];
getUrlVars: function(string) {
@ -332,7 +332,7 @@ if(typeof VMM != 'undefined' && typeof VMM.Util == 'undefined') {
return vars;
},
/* Cleans up strings to become real HTML
/* * Cleans up strings to become real HTML
================================================== */
toHTML: function(text) {
@ -342,7 +342,7 @@ if(typeof VMM != 'undefined' && typeof VMM.Util == 'undefined') {
return text.replace(/\s\s/g,"&nbsp;&nbsp;");
},
/* Returns text strings as CamelCase
/* * Returns text strings as CamelCase
================================================== */
toCamelCase: function(s,forceLowerCase) {
@ -358,12 +358,12 @@ if(typeof VMM != 'undefined' && typeof VMM.Util == 'undefined') {
return sps.join(" ");
},
/* Replaces dumb quote marks with smart ones
/* * Replaces dumb quote marks with smart ones
================================================== */
properQuotes: function(str) {
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){
@ -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){
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-previous", onPrevClick);
VMM.bindEvent(window, onKeypressNav, 'keydown');
}
/* BUILD

Loading…
Cancel
Save