|
@@ -19,7 +19,7 @@ function fadeIns(el){
|
|
|
var val = parseFloat(el.style.opacity);
|
|
|
if (((val += 0.03) > 1) !== true) {
|
|
|
el.style.opacity = val;
|
|
|
- var request = requestFrame('request');
|
|
|
+ var request = window.requestFrame('request');
|
|
|
request(fade);
|
|
|
}
|
|
|
})();
|
|
@@ -92,9 +92,9 @@ function checkState() {
|
|
|
|
|
|
rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
|
|
|
function hex(x) {
|
|
|
- return ("0" + parseInt(x).toString(16)).slice(-2);
|
|
|
+ return ('0' + parseInt(x).toString(16)).slice(-2);
|
|
|
}
|
|
|
- return "#" + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]);
|
|
|
+ return '#' + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -112,18 +112,18 @@ function HTMLcreate(htmlStr) {
|
|
|
return frag;
|
|
|
}
|
|
|
// fade out animation
|
|
|
-function fadeOut(el){
|
|
|
- el.style.opacity = 1;
|
|
|
-
|
|
|
- (function fade() {
|
|
|
- if ((val -= 0.05) < 0) {
|
|
|
- el.style.display = "none";
|
|
|
- } else {
|
|
|
- var request = requestFrame('request');
|
|
|
- request(fade);
|
|
|
- }
|
|
|
- })();
|
|
|
-}
|
|
|
+// function fadeOut(el){
|
|
|
+// el.style.opacity = 1;
|
|
|
+
|
|
|
+// (function fade() {
|
|
|
+// if ((val -= 0.05) < 0) {
|
|
|
+// el.style.display = 'none';
|
|
|
+// } else {
|
|
|
+// var request = window.requestFrame('request');
|
|
|
+// request(fade);
|
|
|
+// }
|
|
|
+// })();
|
|
|
+// }
|
|
|
// fade in animation
|
|
|
function fadeIn(el, display){
|
|
|
el.style.opacity = 0;
|
|
@@ -133,7 +133,7 @@ function fadeIn(el, display){
|
|
|
var val = parseFloat(el.style.opacity);
|
|
|
if (((val += 0.05) > 1) !== true) {
|
|
|
el.style.opacity = val;
|
|
|
- var request = requestFrame('request');
|
|
|
+ var request = window.requestFrame('request');
|
|
|
request(fade);
|
|
|
}
|
|
|
})();
|
|
@@ -162,17 +162,19 @@ setInterval(netsettings_changedCheck, 100);
|
|
|
//########## Settings Form ############
|
|
|
|
|
|
function formValidation(){
|
|
|
- var read_community = $('read_community'),
|
|
|
- write_community = $('write_community'),
|
|
|
- managerIP = $('managerIP'),
|
|
|
- managerIP2 = $('managerIP2'),
|
|
|
- managerIP3 = $('managerIP3'),
|
|
|
- managerIP4 = $('managerIP4'),
|
|
|
- managerIP5 = $('managerIP5'),
|
|
|
- ipaddr = $('ipaddr'),
|
|
|
- gw = $('gw'),
|
|
|
- mask = $('mask'),
|
|
|
- ntpservip = $('ntpservip');
|
|
|
+ var read_community, write_community,managerIP,managerIP2,managerIP3,managerIP4,managerIP5,ipaddr,gw,mask/*, ntpservip*/;
|
|
|
+
|
|
|
+ read_community = $('read_community'),
|
|
|
+ write_community = $('write_community'),
|
|
|
+ managerIP = $('managerIP'),
|
|
|
+ managerIP2 = $('managerIP2'),
|
|
|
+ managerIP3 = $('managerIP3'),
|
|
|
+ managerIP4 = $('managerIP4'),
|
|
|
+ managerIP5 = $('managerIP5'),
|
|
|
+ ipaddr = $('ipaddr'),
|
|
|
+ gw = $('gw'),
|
|
|
+ mask = $('mask');
|
|
|
+ // ntpservip = $('ntpservip');
|
|
|
|
|
|
var flag = true;
|
|
|
if (!$('dhcp').checked) {
|
|
@@ -240,7 +242,7 @@ function ValidateAlphanumeric(uadd, z) {
|
|
|
}
|
|
|
|
|
|
function submitForms() {
|
|
|
- if (confirm("Вы уверены что хотите применить настройки?")) {
|
|
|
+ if (confirm('Вы уверены что хотите применить настройки?')) {
|
|
|
if ($('ntp-inp')) {
|
|
|
$('ntpservip').options[3].value = $('ntp-inp').value;
|
|
|
}
|
|
@@ -306,7 +308,7 @@ function loadXMLDoc(url, method, callback) {
|
|
|
// }
|
|
|
function checkPWD(){
|
|
|
// $('checkUpdatePass').style.display = 'none';
|
|
|
- $('count-wrap').style.display = 'block';
|
|
|
+ $('count-wrap').style.display = 'block';
|
|
|
$('countdown').style.display = 'block';
|
|
|
countdown();
|
|
|
}
|
|
@@ -379,9 +381,11 @@ function dhcpState() {
|
|
|
//########## Info Form Validation ############
|
|
|
|
|
|
function infoValidation(){
|
|
|
- var owner = $('owner').value,
|
|
|
- location = $('location').value,
|
|
|
- comment = $('comment').value;
|
|
|
+ var owner, location,comment;
|
|
|
+ owner = $('owner').value,
|
|
|
+ location = $('location').value,
|
|
|
+ comment = $('comment').value;
|
|
|
+
|
|
|
var flag = true;
|
|
|
if(!ValidateAlphanumeric2(owner, 'Владелец')){flag = false;}
|
|
|
if(!ValidateAlphanumeric2(location, 'Местоположение')){flag = false;}
|
|
@@ -403,7 +407,7 @@ function ValidateAlphanumeric2(uadd, z) {
|
|
|
}
|
|
|
|
|
|
function submitInfo() {
|
|
|
- if (confirm("Вы уверены что хотите применить изменения?")) {
|
|
|
+ if (confirm('Вы уверены что хотите применить изменения?')) {
|
|
|
if (infoValidation()) {
|
|
|
$('SNMPinfo').submit();
|
|
|
// loadXMLDoc('info.cgi?owner='+ $('owner').value + '&sysLocation='+ $('location').value + '&comment='+ decodeURIComponent($('comment').value), 'GET', function(){
|
|
@@ -418,7 +422,7 @@ function submitInfo() {
|
|
|
|
|
|
function getJSON(url, successHandler, errorHandler) {
|
|
|
var xhr;
|
|
|
- xhr = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
|
|
|
+ xhr = window.XMLHttpRequest ? new XMLHttpRequest() : new window.ActiveXObject('Microsoft.XMLHTTP');
|
|
|
xhr.open('GET', url, true);
|
|
|
xhr.onreadystatechange = function () {
|
|
|
var status;
|
|
@@ -438,27 +442,24 @@ function getJSON(url, successHandler, errorHandler) {
|
|
|
|
|
|
function getCGI(url) {
|
|
|
var xmlhttp;
|
|
|
- var q, a;
|
|
|
+ var q;
|
|
|
if (url == 'reset.cgi') {
|
|
|
- q = confirm("Вы уверены что хотите сбросить на заводские настройки?");
|
|
|
- // a = "Сброс отменен.";
|
|
|
+ q = confirm('Вы уверены что хотите сбросить на заводские настройки?');
|
|
|
}
|
|
|
if (url == 'reboot.cgi') {
|
|
|
- q = confirm("Вы уверены что хотите перезагрузить устройство?");
|
|
|
- // a = "Перезагрузка отменена.";
|
|
|
+ q = confirm('Вы уверены что хотите перезагрузить устройство?');
|
|
|
}
|
|
|
if (url == 'update.cgi') {
|
|
|
- q = confirm("Вы уверены что хотите обновить прошивку устройства?");
|
|
|
- // a = "Обновление отменено.";
|
|
|
+ q = confirm('Вы уверены что хотите обновить прошивку устройства?');
|
|
|
}
|
|
|
if (q) {
|
|
|
if (window.XMLHttpRequest) {
|
|
|
xmlhttp = new XMLHttpRequest();
|
|
|
} else {
|
|
|
- xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
|
|
|
+ xmlhttp = new window.ActiveXObject('Microsoft.XMLHTTP');
|
|
|
}
|
|
|
// xmlhttp.onreadystatechange = true;
|
|
|
- xmlhttp.open("GET", url, true);
|
|
|
+ xmlhttp.open('GET', url, true);
|
|
|
xmlhttp.send();
|
|
|
return true;
|
|
|
}
|
|
@@ -494,12 +495,12 @@ var states = {
|
|
|
|
|
|
function getState(i) {
|
|
|
switch(i) {
|
|
|
- case 0:
|
|
|
- break;
|
|
|
- case 1:
|
|
|
- break;
|
|
|
- default:
|
|
|
- break;
|
|
|
+ case 0:
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -589,7 +590,7 @@ function getPage(pn){
|
|
|
// checkNotify();
|
|
|
clearTimeout(mint);
|
|
|
mint = setTimeout(history_dataref, 5000);
|
|
|
- },function(status){
|
|
|
+ }, function(){
|
|
|
$('table').display = 'none';
|
|
|
$('content').innerHTML =
|
|
|
'<h1>Журнал событий</h1>'+
|
|
@@ -666,33 +667,33 @@ function JSONToCSVConvertor(JSONData,ShowLabel) {
|
|
|
console.log(row);
|
|
|
CSV += header + row;
|
|
|
if (CSV === '') {
|
|
|
- alert('Данные отсутствуют');
|
|
|
- return;
|
|
|
+ alert('Данные отсутствуют');
|
|
|
+ return;
|
|
|
}
|
|
|
var d = new Date();
|
|
|
var fileName = d.getDate()+'_'+d.getMonth()+'_'+d.getHours()+d.getMinutes();
|
|
|
if(msieversion()){
|
|
|
- var IEwindow = window.open();
|
|
|
- IEwindow.document.write( 'sep=;\r\n' + utf8_decode(CSV) );
|
|
|
- IEwindow.document.close();
|
|
|
- IEwindow.document.execCommand('SaveAs', true, fileName + '.csv');
|
|
|
- IEwindow.close();
|
|
|
+ var IEwindow = window.open();
|
|
|
+ IEwindow.document.write( 'sep=;\r\n' + utf8_decode(CSV) );
|
|
|
+ IEwindow.document.close();
|
|
|
+ IEwindow.document.execCommand('SaveAs', true, fileName + '.csv');
|
|
|
+ IEwindow.close();
|
|
|
} else {
|
|
|
- var uri = 'data:application/csv;charset=utf-8,' + escape( utf8_decode(CSV) );
|
|
|
- var link = document.createElement('a');
|
|
|
- link.href = uri;
|
|
|
- link.style = 'visibility:hidden';
|
|
|
- link.download = fileName + '.csv';
|
|
|
- document.body.appendChild(link);
|
|
|
- link.click();
|
|
|
- document.body.removeChild(link);
|
|
|
+ var uri = 'data:application/csv;charset=utf-8,' + escape( utf8_decode(CSV) );
|
|
|
+ var link = document.createElement('a');
|
|
|
+ link.href = uri;
|
|
|
+ link.style = 'visibility:hidden';
|
|
|
+ link.download = fileName + '.csv';
|
|
|
+ document.body.appendChild(link);
|
|
|
+ link.click();
|
|
|
+ document.body.removeChild(link);
|
|
|
}
|
|
|
}
|
|
|
function msieversion() {
|
|
|
var ua = window.navigator.userAgent;
|
|
|
- var msie = ua.indexOf("MSIE ");
|
|
|
+ var msie = ua.indexOf('MSIE ');
|
|
|
if (msie != -1 || !!navigator.userAgent.match(/Trident.*rv\:11\./)) /*If IE, return version number*/ return true;
|
|
|
- else return false;
|
|
|
+
|
|
|
return false;
|
|
|
}
|
|
|
|
|
@@ -746,11 +747,11 @@ function settingsGET(){
|
|
|
$('ntpservip').options[3].value = data.ntpservip;
|
|
|
$('ntpservip').parentNode.insertBefore(newInput, $('ntpservip').nextSibling);
|
|
|
|
|
|
- ntpservipValue = data.ntpservip;
|
|
|
- newInput.value = ntpservipValue;
|
|
|
+ window.ntpservipValue = data.ntpservip;
|
|
|
+ newInput.value = window.ntpservipValue;
|
|
|
} else {
|
|
|
- ntpservipValue = data.ntpservip;
|
|
|
- $('ntpservip').value = ntpservipValue;
|
|
|
+ window.ntpservipValue = data.ntpservip;
|
|
|
+ $('ntpservip').value = window.ntpservipValue;
|
|
|
}
|
|
|
$('utc').value = data.utc;
|
|
|
$('date').value = data.date;
|
|
@@ -761,7 +762,7 @@ function settingsGET(){
|
|
|
timesetType($('ntp'));
|
|
|
netsettings_changed = data.netsettings_changed;
|
|
|
// profilaction_changed = data.NeedProfilaction;
|
|
|
- }, function(status) {
|
|
|
+ }, function() {
|
|
|
alert('Не удалось получить данные.');
|
|
|
});
|
|
|
}
|
|
@@ -923,10 +924,11 @@ SpinBox.prototype.setValue = function (value) {
|
|
|
if ('dispatchEvent' in this.input){
|
|
|
|
|
|
// create the event
|
|
|
+ var event;
|
|
|
try{
|
|
|
- var event = new Event('change', {bubbles : true, cancelable : true});
|
|
|
+ event = new Event('change', {bubbles : true, cancelable : true});
|
|
|
}catch (e){
|
|
|
- var event = document.createEvent('Event');
|
|
|
+ event = document.createEvent('Event');
|
|
|
event.initEvent('change', true, true);
|
|
|
}
|
|
|
|
|
@@ -1126,13 +1128,13 @@ DYN_WEB.Event = {
|
|
|
cap = cap || false;
|
|
|
obj.addEventListener(etype, fp, cap);
|
|
|
} : function (obj, etype, fp) {
|
|
|
- obj.attachEvent("on" + etype, fp);
|
|
|
+ obj.attachEvent('on' + etype, fp);
|
|
|
},
|
|
|
remove: document.removeEventListener ? function (obj, etype, fp, cap) {
|
|
|
cap = cap || false;
|
|
|
obj.removeEventListener(etype, fp, cap);
|
|
|
} : function (obj, etype, fp) {
|
|
|
- obj.detachEvent("on" + etype, fp);
|
|
|
+ obj.detachEvent('on' + etype, fp);
|
|
|
},
|
|
|
DOMit: function (e) {
|
|
|
e = e ? e : window.event;
|
|
@@ -1157,12 +1159,19 @@ DYN_WEB.Event = {
|
|
|
DYN_WEB.Cookie = {
|
|
|
set: function (name, value, days, path, domain, secure) {
|
|
|
var date, expires;
|
|
|
- if (typeof days == "number") {
|
|
|
+ if (typeof days == 'number') {
|
|
|
date = new Date();
|
|
|
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
|
|
|
expires = date.toGMTString();
|
|
|
}
|
|
|
- document.cookie = name + "=" + encodeURIComponent(value) + ((expires) ? "; expires=" + expires : "") + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : "");
|
|
|
+ document.cookie = name + '=' + encodeURIComponent(value) + (
|
|
|
+ (expires) ? '; expires=' + expires : ''
|
|
|
+ ) + (
|
|
|
+ (path) ? '; path=' + path : ''
|
|
|
+ ) + (
|
|
|
+ (domain) ? '; domain=' + domain : ''
|
|
|
+ ) + (
|
|
|
+ (secure) ? '; secure' : '');
|
|
|
},
|
|
|
get: function (name) {
|
|
|
var c, cookies = document.cookie.split(/;\s/g);
|
|
@@ -1176,7 +1185,11 @@ DYN_WEB.Cookie = {
|
|
|
},
|
|
|
del: function (name, path, domain) {
|
|
|
if (dw_Cookie.get(name)) {
|
|
|
- document.cookie = name + "=" + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
|
|
|
+ document.cookie = name + '=' + (
|
|
|
+ (path) ? '; path=' + path : ''
|
|
|
+ ) + (
|
|
|
+ (domain) ? '; domain=' + domain : ''
|
|
|
+ ) + '; expires=Thu, 01-Jan-70 00:00:01 GMT';
|
|
|
}
|
|
|
}
|
|
|
};
|
|
@@ -1442,7 +1455,7 @@ DYN_WEB.Tabs = (function () {
|
|
|
},
|
|
|
|
|
|
removeClass: function (el, cl) {
|
|
|
- el.className = Ut.normalizeString(el.className.replace(cl, " "));
|
|
|
+ el.className = Ut.normalizeString(el.className.replace(cl, ' '));
|
|
|
},
|
|
|
|
|
|
getElementsByClassName: function (sClass, sTag, oCont) {
|
|
@@ -1516,242 +1529,228 @@ DYN_WEB.Tabs = (function () {
|
|
|
* @return {Function} Timing function.
|
|
|
*/
|
|
|
function requestFrame(type) {
|
|
|
- // The only vendor prefixes required.
|
|
|
- var vendors = ['moz', 'webkit'],
|
|
|
-
|
|
|
- // Disassembled timing function abbreviations.
|
|
|
- aF = 'AnimationFrame',
|
|
|
- rqAF = 'Request' + aF,
|
|
|
+ // The only vendor prefixes required.
|
|
|
+ var vendors = ['moz', 'webkit'],
|
|
|
|
|
|
- // Final assigned functions.
|
|
|
- assignedRequestAnimationFrame,
|
|
|
- assignedCancelAnimationFrame,
|
|
|
+ // Disassembled timing function abbreviations.
|
|
|
+ aF = 'AnimationFrame',
|
|
|
+ rqAF = 'Request' + aF,
|
|
|
|
|
|
- // Initial time of the timing lapse.
|
|
|
- previousTime = 0,
|
|
|
+ // Final assigned functions.
|
|
|
+ assignedRequestAnimationFrame,
|
|
|
+ assignedCancelAnimationFrame,
|
|
|
|
|
|
- mozRAF = window.mozRequestAnimationFrame,
|
|
|
- mozCAF = window.mozCancelAnimationFrame,
|
|
|
+ // Initial time of the timing lapse.
|
|
|
+ previousTime = 0,
|
|
|
|
|
|
- // Checks for firefox 4 - 10 function pair mismatch.
|
|
|
- hasMozMismatch = mozRAF && !mozCAF,
|
|
|
+ mozRAF = window.mozRequestAnimationFrame,
|
|
|
+ mozCAF = window.mozCancelAnimationFrame,
|
|
|
|
|
|
- func;
|
|
|
+ // Checks for firefox 4 - 10 function pair mismatch.
|
|
|
+ hasMozMismatch = mozRAF && !mozCAF,
|
|
|
|
|
|
- // Date.now polyfill, mainly for legacy IE versions.
|
|
|
- if (!Date.now) {
|
|
|
- Date.now = function() {
|
|
|
- return new Date().getTime();
|
|
|
- };
|
|
|
- }
|
|
|
+ func;
|
|
|
|
|
|
- /**
|
|
|
- * hasIOS6RequestAnimationFrameBug.
|
|
|
- * @See {@Link https://gist.github.com/julienetie/86ac394ec41f1271ff0a}
|
|
|
- * - for Commentary.
|
|
|
- * @Copyright 2015 - Julien Etienne.
|
|
|
- * @License: MIT.
|
|
|
- */
|
|
|
- function hasIOS6RequestAnimationFrameBug() {
|
|
|
- var webkitRAF = window.webkitRequestAnimationFrame,
|
|
|
- rAF = window.requestAnimationFrame,
|
|
|
-
|
|
|
- // CSS/ Device with max for iOS6 Devices.
|
|
|
- hasMobileDeviceWidth = screen.width <= 768 ? true : false,
|
|
|
+ // Date.now polyfill, mainly for legacy IE versions.
|
|
|
+ if (!Date.now) {
|
|
|
+ Date.now = function() {
|
|
|
+ return new Date().getTime();
|
|
|
+ };
|
|
|
+ }
|
|
|
|
|
|
- // Only supports webkit prefixed requestAnimtionFrane.
|
|
|
- requiresWebkitprefix = !(webkitRAF && rAF),
|
|
|
+ /**
|
|
|
+ * hasIOS6RequestAnimationFrameBug.
|
|
|
+ * @See {@Link https://gist.github.com/julienetie/86ac394ec41f1271ff0a}
|
|
|
+ * - for Commentary.
|
|
|
+ * @Copyright 2015 - Julien Etienne.
|
|
|
+ * @License: MIT.
|
|
|
+ */
|
|
|
+ function hasIOS6RequestAnimationFrameBug() {
|
|
|
+ var webkitRAF = window.webkitRequestAnimationFrame,
|
|
|
+ rAF = window.requestAnimationFrame,
|
|
|
|
|
|
- // iOS6 webkit browsers don't support performance now.
|
|
|
- hasNoNavigationTiming = window.performance ? false : true,
|
|
|
+ // CSS/ Device with max for iOS6 Devices.
|
|
|
+ hasMobileDeviceWidth = screen.width <= 768 ? true : false,
|
|
|
|
|
|
- iOS6Notice = 'setTimeout is being used as a substitiue for' +
|
|
|
- 'requestAnimationFrame due to a bug within iOS 6 builds',
|
|
|
+ // Only supports webkit prefixed requestAnimtionFrane.
|
|
|
+ requiresWebkitprefix = !(webkitRAF && rAF),
|
|
|
|
|
|
- hasIOS6Bug = requiresWebkitprefix && hasMobileDeviceWidth &&
|
|
|
- hasNoNavigationTiming;
|
|
|
+ // iOS6 webkit browsers don't support performance now.
|
|
|
+ hasNoNavigationTiming = window.performance ? false : true,
|
|
|
|
|
|
- function bugCheckresults(timingFnA, timingFnB, notice) {
|
|
|
- if (timingFnA || timingFnB) {
|
|
|
- console.warn(notice);
|
|
|
- return true;
|
|
|
- } else {
|
|
|
- return false;
|
|
|
- }
|
|
|
- }
|
|
|
+ iOS6Notice = 'setTimeout is being used as a substitiue for' +
|
|
|
+ 'requestAnimationFrame due to a bug within iOS 6 builds',
|
|
|
|
|
|
- function displayResults() {
|
|
|
- if (hasIOS6Bug) {
|
|
|
- return bugCheckresults(webkitRAF, rAF, iOS6Notice);
|
|
|
- } else {
|
|
|
- return false;
|
|
|
- }
|
|
|
- }
|
|
|
+ hasIOS6Bug = requiresWebkitprefix && hasMobileDeviceWidth &&
|
|
|
+ hasNoNavigationTiming;
|
|
|
|
|
|
- return displayResults();
|
|
|
+ function bugCheckresults(timingFnA, timingFnB, notice) {
|
|
|
+ if (timingFnA || timingFnB) {
|
|
|
+ console.warn(notice);
|
|
|
+ return true;
|
|
|
+ } else {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Native clearTimeout function.
|
|
|
- * @return {Function}
|
|
|
- */
|
|
|
- function clearTimeoutWithId(id) {
|
|
|
- clearTimeout(id);
|
|
|
+ function displayResults() {
|
|
|
+ if (hasIOS6Bug) {
|
|
|
+ return bugCheckresults(webkitRAF, rAF, iOS6Notice);
|
|
|
+ } else {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Based on a polyfill by Erik, introduced by Paul Irish &
|
|
|
- * further improved by Darius Bacon.
|
|
|
- * @see {@link http://www.paulirish.com/2011/
|
|
|
- * requestanimationframe-for-smart-animating}
|
|
|
- * @see {@link https://github.com/darius/requestAnimationFrame/blob/
|
|
|
- * master/requestAnimationFrame.js}
|
|
|
- * @callback {Number} Timestamp.
|
|
|
- * @return {Function} setTimeout Function.
|
|
|
- */
|
|
|
- function setTimeoutWithTimestamp(callback) {
|
|
|
- var immediateTime = Date.now(),
|
|
|
- lapsedTime = Math.max(previousTime + 16, immediateTime);
|
|
|
- return setTimeout(function() {
|
|
|
- callback(previousTime = lapsedTime);
|
|
|
- },
|
|
|
- lapsedTime - immediateTime);
|
|
|
- }
|
|
|
+ return displayResults();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Native clearTimeout function.
|
|
|
+ * @return {Function}
|
|
|
+ */
|
|
|
+ function clearTimeoutWithId(id) {
|
|
|
+ clearTimeout(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Based on a polyfill by Erik, introduced by Paul Irish &
|
|
|
+ * further improved by Darius Bacon.
|
|
|
+ * @see {@link http://www.paulirish.com/2011/
|
|
|
+ * requestanimationframe-for-smart-animating}
|
|
|
+ * @see {@link https://github.com/darius/requestAnimationFrame/blob/
|
|
|
+ * master/requestAnimationFrame.js}
|
|
|
+ * @callback {Number} Timestamp.
|
|
|
+ * @return {Function} setTimeout Function.
|
|
|
+ */
|
|
|
+ function setTimeoutWithTimestamp(callback) {
|
|
|
+ var immediateTime = Date.now(),
|
|
|
+ lapsedTime = Math.max(previousTime + 16, immediateTime);
|
|
|
+ return setTimeout(function() {
|
|
|
+ callback(previousTime = lapsedTime);
|
|
|
+ },
|
|
|
+ lapsedTime - immediateTime);
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* Queries the native function, prefixed function
|
|
|
* or use the setTimeoutWithTimestamp function.
|
|
|
* @return {Function}
|
|
|
*/
|
|
|
- function queryRequestAnimationFrame() {
|
|
|
- if (Array.prototype.filter) {
|
|
|
- assignedRequestAnimationFrame = window['request' + aF] ||
|
|
|
- window[vendors.filter(function(vendor) {
|
|
|
- if (window[vendor + rqAF] !== undefined)
|
|
|
- return vendor;
|
|
|
- }) + rqAF] || setTimeoutWithTimestamp;
|
|
|
- } else {
|
|
|
- return setTimeoutWithTimestamp;
|
|
|
- }
|
|
|
- if (!hasIOS6RequestAnimationFrameBug()) {
|
|
|
- return assignedRequestAnimationFrame;
|
|
|
- } else {
|
|
|
- return setTimeoutWithTimestamp;
|
|
|
- }
|
|
|
+ function queryRequestAnimationFrame() {
|
|
|
+ if (Array.prototype.filter) {
|
|
|
+ assignedRequestAnimationFrame = window['request' + aF] ||
|
|
|
+ window[vendors.filter(function(vendor) {
|
|
|
+ if (window[vendor + rqAF] !== undefined)
|
|
|
+ return vendor;
|
|
|
+ }) + rqAF] || setTimeoutWithTimestamp;
|
|
|
+ } else {
|
|
|
+ return setTimeoutWithTimestamp;
|
|
|
+ }
|
|
|
+ if (!hasIOS6RequestAnimationFrameBug()) {
|
|
|
+ return assignedRequestAnimationFrame;
|
|
|
+ } else {
|
|
|
+ return setTimeoutWithTimestamp;
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* Queries the native function, prefixed function
|
|
|
* or use the clearTimeoutWithId function.
|
|
|
* @return {Function}
|
|
|
*/
|
|
|
- function queryCancelAnimationFrame() {
|
|
|
- var cancellationNames = [];
|
|
|
- if (Array.prototype.map) {
|
|
|
- vendors.map(function(vendor) {
|
|
|
- return ['Cancel', 'CancelRequest'].map(
|
|
|
- function(cancellationNamePrefix) {
|
|
|
- cancellationNames.push(vendor +
|
|
|
- cancellationNamePrefix + aF);
|
|
|
- });
|
|
|
- });
|
|
|
- } else {
|
|
|
- return clearTimeoutWithId;
|
|
|
- }
|
|
|
+ function queryCancelAnimationFrame() {
|
|
|
+ var cancellationNames = [];
|
|
|
+ if (Array.prototype.map) {
|
|
|
+ vendors.map(function(vendor) {
|
|
|
+ return ['Cancel', 'CancelRequest'].map(
|
|
|
+ function(cancellationNamePrefix) {
|
|
|
+ cancellationNames.push(vendor +
|
|
|
+ cancellationNamePrefix + aF);
|
|
|
+ });
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ return clearTimeoutWithId;
|
|
|
+ }
|
|
|
|
|
|
- /**
|
|
|
- * Checks for the prefixed cancelAnimationFrame implementation.
|
|
|
- * @param {Array} prefixedNames - An array of the prefixed names.
|
|
|
- * @param {Number} i - Iteration start point.
|
|
|
- * @return {Function} prefixed cancelAnimationFrame function.
|
|
|
- */
|
|
|
- function prefixedCancelAnimationFrame(prefixedNames, i) {
|
|
|
- var cancellationFunction;
|
|
|
- for (; i < prefixedNames.length; i++) {
|
|
|
- if (window[prefixedNames[i]]) {
|
|
|
- cancellationFunction = window[prefixedNames[i]];
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- return cancellationFunction;
|
|
|
+ /**
|
|
|
+ * Checks for the prefixed cancelAnimationFrame implementation.
|
|
|
+ * @param {Array} prefixedNames - An array of the prefixed names.
|
|
|
+ * @param {Number} i - Iteration start point.
|
|
|
+ * @return {Function} prefixed cancelAnimationFrame function.
|
|
|
+ */
|
|
|
+ function prefixedCancelAnimationFrame(prefixedNames, i) {
|
|
|
+ var cancellationFunction;
|
|
|
+ for (; i < prefixedNames.length; i++) {
|
|
|
+ if (window[prefixedNames[i]]) {
|
|
|
+ cancellationFunction = window[prefixedNames[i]];
|
|
|
+ break;
|
|
|
}
|
|
|
+ }
|
|
|
+ return cancellationFunction;
|
|
|
+ }
|
|
|
|
|
|
- // Use truthly function
|
|
|
- assignedCancelAnimationFrame = window['cancel' + aF] ||
|
|
|
- prefixedCancelAnimationFrame(cancellationNames, 0) ||
|
|
|
- clearTimeoutWithId;
|
|
|
+ // Use truthly function
|
|
|
+ assignedCancelAnimationFrame = window['cancel' + aF] ||
|
|
|
+ prefixedCancelAnimationFrame(cancellationNames, 0) ||
|
|
|
+ clearTimeoutWithId;
|
|
|
|
|
|
- // Check for iOS 6 bug
|
|
|
- if (!hasIOS6RequestAnimationFrameBug()) {
|
|
|
- return assignedCancelAnimationFrame;
|
|
|
- } else {
|
|
|
- return clearTimeoutWithId;
|
|
|
- }
|
|
|
+ // Check for iOS 6 bug
|
|
|
+ if (!hasIOS6RequestAnimationFrameBug()) {
|
|
|
+ return assignedCancelAnimationFrame;
|
|
|
+ } else {
|
|
|
+ return clearTimeoutWithId;
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- function getRequestFn() {
|
|
|
- if (hasMozMismatch) {
|
|
|
- return setTimeoutWithTimestamp;
|
|
|
- } else {
|
|
|
- return queryRequestAnimationFrame();
|
|
|
- }
|
|
|
+ function getRequestFn() {
|
|
|
+ if (hasMozMismatch) {
|
|
|
+ return setTimeoutWithTimestamp;
|
|
|
+ } else {
|
|
|
+ return queryRequestAnimationFrame();
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- function getCancelFn() {
|
|
|
- return queryCancelAnimationFrame();
|
|
|
- }
|
|
|
+ function getCancelFn() {
|
|
|
+ return queryCancelAnimationFrame();
|
|
|
+ }
|
|
|
|
|
|
- function setNativeFn() {
|
|
|
- if (hasMozMismatch) {
|
|
|
- window.requestAnimationFrame = setTimeoutWithTimestamp;
|
|
|
- window.cancelAnimationFrame = clearTimeoutWithId;
|
|
|
- } else {
|
|
|
- window.requestAnimationFrame = queryRequestAnimationFrame();
|
|
|
- window.cancelAnimationFrame = queryCancelAnimationFrame();
|
|
|
- }
|
|
|
+ function setNativeFn() {
|
|
|
+ if (hasMozMismatch) {
|
|
|
+ window.requestAnimationFrame = setTimeoutWithTimestamp;
|
|
|
+ window.cancelAnimationFrame = clearTimeoutWithId;
|
|
|
+ } else {
|
|
|
+ window.requestAnimationFrame = queryRequestAnimationFrame();
|
|
|
+ window.cancelAnimationFrame = queryCancelAnimationFrame();
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* The type value "request" singles out firefox 4 - 10 and
|
|
|
* assigns the setTimeout function if plausible.
|
|
|
*/
|
|
|
|
|
|
- switch (type) {
|
|
|
- case 'request':
|
|
|
- case '':
|
|
|
- func = getRequestFn();
|
|
|
- break;
|
|
|
-
|
|
|
- case 'cancel':
|
|
|
- func = getCancelFn();
|
|
|
- break;
|
|
|
-
|
|
|
- case 'native':
|
|
|
- setNativeFn();
|
|
|
- break;
|
|
|
- default:
|
|
|
- throw new Error('RequestFrame parameter is not a type.');
|
|
|
- }
|
|
|
- return func;
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-// Node.js/ CommonJS
|
|
|
-if (typeof module === 'object' && typeof module.exports === 'object') {
|
|
|
-module.exports = exports = requestFrame;
|
|
|
-}
|
|
|
-
|
|
|
-// AMD
|
|
|
-else if (typeof define === 'function' && define.amd) {
|
|
|
-define(function() {
|
|
|
- return requestFrame;
|
|
|
-});
|
|
|
-}
|
|
|
-
|
|
|
-// Default to window as global
|
|
|
-else if (typeof window === 'object') {
|
|
|
-window.requestFrame = requestFrame;
|
|
|
+ switch (type) {
|
|
|
+ case 'request':
|
|
|
+ case '':
|
|
|
+ func = getRequestFn();
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 'cancel':
|
|
|
+ func = getCancelFn();
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 'native':
|
|
|
+ setNativeFn();
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ throw new Error('RequestFrame parameter is not a type.');
|
|
|
+ }
|
|
|
+ return func;
|
|
|
}
|
|
|
-/* global -module, -exports, -define */
|
|
|
+ // Default to window as global
|
|
|
+ if (typeof window === 'object') {
|
|
|
+ window.requestFrame = requestFrame;
|
|
|
+ }
|
|
|
+ /* global-define */
|
|
|
|
|
|
-}((typeof window === "undefined" ? {} : window)));
|
|
|
+}((typeof window === 'undefined' ? {} : window)));
|