main.js 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971
  1. function $(id) {return document.getElementById(id);}
  2. // ############### Mobile Device ################
  3. if (window.screen.width < 769) {
  4. $('nav').style.display = 'none';
  5. }
  6. $('menu-icon').onclick = function(){
  7. $('nav').style.display = $('nav').style.display == 'none' ? 'block' : 'none';
  8. };
  9. //########## Main Page Alert Handler ############
  10. // fadeIn animation special for alerts
  11. function fadeIns(el){
  12. el.style.opacity = 0;
  13. (function fade() {
  14. var val = parseFloat(el.style.opacity);
  15. if (((val += 0.03) > 1) !== true) {
  16. el.style.opacity = val;
  17. var request = window.requestFrame('request');
  18. request(fade);
  19. }
  20. })();
  21. }
  22. var ac = $('AC'),
  23. dc = $('DC'),
  24. in_freq = $('in_freq'),
  25. out_freq = $('out_freq'),
  26. pwr = $('pwr'),
  27. bat_cap = $('bat_cap'),
  28. inner_temp = $('inner_temp'),
  29. battimeleft = $('bat_time_left'),
  30. // alarm = $('alarm'),
  31. sPower = $('sPower'),
  32. sBattery = $('sBattery');
  33. var battempCtrlChecked;
  34. function dataFadeIn(){
  35. var x = [
  36. ac,
  37. dc,
  38. in_freq,
  39. out_freq,
  40. pwr,
  41. bat_cap,
  42. inner_temp,
  43. battimeleft,
  44. sPower,
  45. sBattery
  46. ];
  47. for (var i = 0; i < x.length; i++){
  48. fadeIns(x[i]);
  49. }
  50. }
  51. // Alarm colors
  52. var ALARM_RED = '#ff5050',
  53. ALARM_YELLOW = '#f0ad4e',
  54. ALARM_GREEN = '#33cc00';
  55. //########## Settings Inform Boxes ############
  56. function HTMLcreate(htmlStr) {
  57. var frag = document.createDocumentFragment(),
  58. temp = document.createElement('div');
  59. temp.innerHTML = htmlStr;
  60. while (temp.firstChild) {
  61. frag.appendChild(temp.firstChild);
  62. }
  63. return frag;
  64. }
  65. // fade in animation
  66. function fadeIn(el, display){
  67. el.style.opacity = 0;
  68. el.style.display = display || 'block';
  69. (function fade() {
  70. var val = parseFloat(el.style.opacity);
  71. if (((val += 0.05) > 1) !== true) {
  72. el.style.opacity = val;
  73. var request = window.requestFrame('request');
  74. request(fade);
  75. }
  76. })();
  77. }
  78. //########## Settings Form ############
  79. function formValidation(){
  80. var read_community,write_community,managerIP,managerIP2,managerIP3,managerIP4,managerIP5,
  81. ipaddr, gw, mask,
  82. rs_server, rs_port, rs_key/*, ntpservip*/;
  83. read_community = $('read_community'),
  84. write_community = $('write_community'),
  85. managerIP = $('managerIP'),
  86. managerIP2 = $('managerIP2'),
  87. managerIP3 = $('managerIP3'),
  88. managerIP4 = $('managerIP4'),
  89. managerIP5 = $('managerIP5'),
  90. ipaddr = $('ipaddr'),
  91. gw = $('gw'),
  92. mask = $('mask'),
  93. rs_server = $('rs_server'),
  94. rs_port = $('rs_port'),
  95. rs_key = $('rs_key');
  96. // ntpservip = $('ntpservip');
  97. var flag = true;
  98. if (!$('dhcp').checked) {
  99. if(!ValidateIPaddress(ipaddr, ' IP-адрес устройства')) flag = false;
  100. if(!ValidateIPaddress(gw, ' IP-адрес шлюза')) flag = false;
  101. if(!ValidateIPaddress(mask, 'а Маска подсети')) flag = false;
  102. }
  103. if ($('rs_enabled').checked) {
  104. if(!ValidateIPaddress(rs_server, ' IP-адрес RADIUS сервера')) flag = false;
  105. if(!ValidateNumber(rs_port, ' Порт RADIUS сервера')) flag = false;
  106. if(!ValidateAlphanumeric(rs_key, ' Код атрибута access RADIUS сервера')) flag = false;
  107. }
  108. if(!ValidateIPaddress(managerIP, ' Сервер SNMP 1')) flag = false;
  109. if(!ValidateAlphanumeric(read_community, 'Read Community')) flag = false;
  110. if(!ValidateAlphanumeric(write_community, 'Write Community')) flag = false;
  111. if(!ValidateIPaddress(managerIP2, ' Сервер SNMP 2')) flag = false;
  112. if(!ValidateIPaddress(managerIP3, ' Сервер SNMP 3')) flag = false;
  113. if(!ValidateIPaddress(managerIP4, ' Сервер SNMP 4')) flag = false;
  114. if(!ValidateIPaddress(managerIP5, ' Сервер SNMP 5')) flag = false;
  115. return flag;
  116. }
  117. function ValidateIPaddress(ipaddress, z) {
  118. var warn = document.createElement('li');
  119. warn.innerHTML = 'Неправильно задан' + z + '!';
  120. if (/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(ipaddress.value)) {
  121. return true;
  122. }
  123. $('validation-box').appendChild(warn);
  124. return false;
  125. }
  126. function ValidateNumber(n, z) {
  127. var warn = document.createElement('li');
  128. warn.innerHTML = 'Неправильно задан' + z + '!';
  129. if(/^-?[\d.]+(?:e-?\d+)?$/.test(n.value)) {
  130. return true;
  131. }
  132. $('validation-box').appendChild(warn);
  133. return false;
  134. }
  135. function ValidateAlphanumeric(uadd, z) {
  136. var warn = document.createElement('li');
  137. var letter = /^[0-9a-zA-Z]+$/;
  138. warn.innerHTML = 'Поле ' + z + ' может содержать только латинские буквы и цифры';
  139. if (letter.test(uadd.value)) {return true;}
  140. $('validation-box').appendChild(warn);
  141. return false;
  142. }
  143. function validateUpload(oForm) {
  144. var file = oForm.elements.datafile.files[0];
  145. var fnmreg = /^.{1,}\.crt$/g;
  146. if (file && fnmreg.test(file.name) ) {
  147. upload(file);
  148. } else {
  149. alert('Файл сертификата не указан или не валиден!');
  150. }
  151. return false;
  152. }
  153. function submitForms() {
  154. if (confirm('Вы уверены что хотите применить настройки?')) {
  155. if ($('ntp-inp')) {
  156. $('ntpservip').options[3].value = $('ntp-inp').value;
  157. }
  158. if (formValidation()) {
  159. $('form1').submit();
  160. }
  161. else{
  162. $('validation-box').style.display = 'block';
  163. }
  164. }
  165. }
  166. function upload(file) {
  167. var fl = new FormData();
  168. fl.append('file', file);
  169. var xhr = new XMLHttpRequest();
  170. xhr.open('POST', '/srv_crt_upload.cgi', true);
  171. // обработчик для закачки
  172. xhr.upload.onprogress = function(event) {
  173. var progress = Math.floor((event.loaded / event.total) * 100);
  174. console.log(progress + '%');
  175. };
  176. xhr.onload = xhr.onerror = function() {
  177. if (this.status == 200) {
  178. if (+xhr.responseText == '1') {
  179. alert('Успешно');
  180. window.location.reload();
  181. } else {
  182. alert('Ошибка установки сертификата');
  183. }
  184. } else {
  185. alert('Ошибка ' + this.status);
  186. }
  187. };
  188. xhr.send(fl);
  189. }
  190. function checkPWD(){
  191. // $('checkUpdatePass').style.display = 'none';
  192. $('count-wrap').style.display = 'block';
  193. $('countdown').style.display = 'block';
  194. countdown();
  195. }
  196. function checkChangePWD(){
  197. var user = $('changePasswordUser').value;
  198. var oldpass = $('oldpwd').value;
  199. var newpass = $('newpwd').value;
  200. var newpassrepeat = $('newpwdrepeat').value;
  201. var letter = /^[0-9a-zA-Z.,/\\\-_*#()[\]+:'"@!^%&?|${}`~<>]+$/;
  202. if (oldpass.length === 0 || newpass.length === 0 || newpassrepeat.length === 0){
  203. alert('Поля не заполнены!');
  204. } else if (newpass !== newpassrepeat){
  205. alert('Поля с новым паролем не совпадают!');
  206. $('oldpwd').value = '';
  207. $('newpwd').value = '';
  208. $('newpwdrepeat').value = '';
  209. } else if (user === ''){
  210. alert('Не выбран пользователь для которого необходимо сменить пароль!');
  211. } else {
  212. if (letter.test(oldpass) && letter.test(newpass) && letter.test(newpassrepeat)) {
  213. loadXMLDoc('changepwd.cgi?username=' + encodeURIComponent(user) + '&oldpass=' + encodeURIComponent(oldpass) + '&newpass=' + encodeURIComponent(newpass), 'GET', function(){
  214. alert(this.responseText);
  215. window.location.reload();
  216. });
  217. } else {
  218. alert('Пароль задан неправильно');
  219. $('oldpwd').value = '';
  220. $('newpwd').value = '';
  221. $('newpwdrepeat').value = '';
  222. }
  223. }
  224. }
  225. function timesetType(el) {
  226. if (el.selectedIndex === 0) {
  227. $('ntpservip_l').className += ' hidden';
  228. $('ntpservip').className += ' hidden';
  229. $('ntpservip').setAttribute('disabled', 'disabled');
  230. if ($('ntp-inp')) {
  231. $('ntp-inp').className += ' hidden';
  232. $('ntp-inp').setAttribute('disabled', 'disabled');
  233. }
  234. $('lastsynctime_l').className += ' hidden';
  235. $('lastsynctime').className += ' hidden';
  236. // -----------------
  237. $('date_l').className = 'col span_1_of_2';
  238. $('date').className = 'form-control';
  239. $('time_l').className = 'col span_1_of_2';
  240. $('time').className = 'form-control';
  241. $('date').removeAttribute('disabled');
  242. $('time').removeAttribute('disabled');
  243. } else {
  244. $('ntpservip_l').className = 'col span_1_of_2';
  245. $('ntpservip').className = 'form-control';
  246. $('ntpservip').removeAttribute('disabled');
  247. if ($('ntp-inp')) {
  248. $('ntp-inp').className = 'form-control';
  249. $('ntp-inp').removeAttribute('disabled');
  250. }
  251. $('lastsynctime_l').className = 'col span_1_of_2';
  252. $('lastsynctime').className = 'form-control';
  253. // -------------
  254. $('date_l').className += ' hidden';
  255. $('date').className += ' hidden';
  256. $('time_l').className += ' hidden';
  257. $('time').className += ' hidden';
  258. $('date').setAttribute('disabled', 'disabled');
  259. $('time').setAttribute('disabled', 'disabled');
  260. }
  261. }
  262. function countdown(rel) {
  263. var countDown = 10;
  264. setInterval(function () {
  265. if (countDown == 1 && rel === true) {
  266. location.reload(true);
  267. }
  268. else if (countDown == 1 && rel !== true){
  269. window.location.href = 'http:' + window.location.origin.substring(window.location.protocol.length);
  270. }
  271. if (countDown > 0){countDown--;}
  272. $('count-number').innerHTML = countDown;
  273. return countDown;
  274. }, 1000);
  275. }
  276. function dhcpState() {
  277. if ($('dhcp').checked) {
  278. $('ipaddr').setAttribute('disabled', 'disabled');
  279. $('gw').setAttribute('disabled', 'disabled');
  280. $('mask').setAttribute('disabled', 'disabled');
  281. } else {
  282. $('ipaddr').removeAttribute('disabled');
  283. $('gw').removeAttribute('disabled');
  284. $('mask').removeAttribute('disabled');
  285. }
  286. }
  287. function radiusState() {
  288. if (!$('rs_enabled').checked) {
  289. $('rs_server').setAttribute('disabled', 'disabled');
  290. $('rs_port').setAttribute('disabled', 'disabled');
  291. $('rs_pwd').setAttribute('disabled', 'disabled');
  292. $('rs_key').setAttribute('disabled', 'disabled');
  293. } else {
  294. $('rs_server').removeAttribute('disabled');
  295. $('rs_port').removeAttribute('disabled');
  296. $('rs_pwd').removeAttribute('disabled');
  297. $('rs_key').removeAttribute('disabled');
  298. }
  299. }
  300. function authState() {
  301. if (!$('swauth').checked) {
  302. $('rs_enabled').setAttribute('disabled', 'disabled');
  303. $('rs_enabled').checked = false;
  304. } else {
  305. $('rs_enabled').removeAttribute('disabled');
  306. // $('rs_enabled').checked = true;
  307. }
  308. radiusState();
  309. }
  310. //########## Info Form Validation ############
  311. function infoValidation(){
  312. var sysname, owner, location,comment;
  313. sysname = $('sysname').value,
  314. owner = $('owner').value,
  315. location = $('location').value,
  316. comment = $('comment').value;
  317. var flag = true;
  318. if(!ValidateAlphanumeric2(sysname, 'Название устройства')){flag = false;}
  319. if(!ValidateAlphanumeric2(owner, 'Владелец')){flag = false;}
  320. if(!ValidateAlphanumeric2(location, 'Местоположение')){flag = false;}
  321. if(!ValidateAlphanumeric2(comment, 'Комментарии')){flag = false;}
  322. return flag;
  323. }
  324. function ValidateAlphanumeric2(uadd, z) {
  325. var warn = document.createElement('li');
  326. // var letter = /^[0-9a-zA-Z]+[^\u0430-\u044f\u0410-\u042f\u0451\u0401\?]+$/m;
  327. var letter = /^[0-9a-zA-Z.,/\-_*#()[\]+=;:'"@!^%&?|${}`~<>]+$/m;
  328. warn.innerHTML = 'Поле ' + z + ' может содержать только латинские буквы, цифры и символы .,/-_*#()[]+=;:\'"@!^%&?|${}`~<>';
  329. if (letter.test(uadd) || !uadd) {
  330. return true;
  331. }
  332. $('validation-box').appendChild(warn);
  333. return false;
  334. }
  335. function submitInfo() {
  336. if (confirm('Вы уверены что хотите применить изменения?')) {
  337. if (infoValidation()) {
  338. $('SNMPinfo').submit();
  339. // loadXMLDoc('info.cgi?owner='+ $('owner').value + '&sysLocation='+ $('location').value + '&comment='+ decodeURIComponent($('comment').value), 'GET', function(){
  340. // console.log('Сохранено');
  341. // });
  342. }
  343. else {
  344. $('validation-box').style.display = 'block';
  345. }
  346. }
  347. }
  348. function getJSON(url, successHandler, errorHandler) {
  349. var xhr;
  350. xhr = window.XMLHttpRequest ? new XMLHttpRequest() : new window.ActiveXObject('Microsoft.XMLHTTP');
  351. xhr.open('GET', url, true);
  352. xhr.onreadystatechange = function () {
  353. var status;
  354. var data;
  355. if (xhr.readyState == 4) {
  356. status = xhr.status;
  357. if (status == 200) {
  358. data = JSON.parse(xhr.responseText);
  359. successHandler(data);
  360. } else {
  361. errorHandler(status);
  362. }
  363. }
  364. };
  365. xhr.send();
  366. }
  367. function updatepage(){
  368. var loc = location.pathname.slice(1, -5);
  369. switch(loc){
  370. case 'settings':
  371. setTimeout(settingsGET, 1000);
  372. break;
  373. case 'history':
  374. getPage($('currentpage').value);
  375. break;
  376. }
  377. }
  378. function getCGI(url) {
  379. var xmlhttp;
  380. var q;
  381. if (url == 'reset.cgi') {
  382. q = confirm('Вы уверены что хотите сбросить в заводские настройки?');
  383. }
  384. if (url == 'reboot.cgi') {
  385. q = confirm('Вы уверены что хотите перезагрузить устройство?');
  386. }
  387. if (url == 'update.cgi') {
  388. q = confirm('Вы уверены что хотите обновить прошивку устройства?');
  389. }
  390. if (q) {
  391. if (window.XMLHttpRequest) {
  392. xmlhttp = new XMLHttpRequest();
  393. } else {
  394. xmlhttp = new window.ActiveXObject('Microsoft.XMLHTTP');
  395. }
  396. // xmlhttp.onreadystatechange = true;
  397. xmlhttp.open('GET', url, true);
  398. xmlhttp.send();
  399. return true;
  400. }
  401. // else {alert(a);}
  402. }
  403. function Alarm(bitmask, num) {
  404. // Bit mask format DEC <NUMBER>
  405. var answ = (bitmask & (1 << num)) >> num;
  406. return answ;
  407. }
  408. function setIcons(containerID, icnName) {
  409. $(containerID).innerHTML ='';
  410. var icons = typeof icnName === 'string' ? [icnName] : icnName;
  411. for (var i = 0; i < icons.length; i++) {
  412. var icnContainer = document.createElement('i');
  413. icnContainer.innerHTML = Icons[icons[i]]['icn'];
  414. icnContainer.style.paddingLeft = '10px';
  415. icnContainer.title = Icons[icons[i]]['title'];
  416. $(containerID).appendChild(icnContainer);
  417. }
  418. }
  419. function paramsRefresh() {
  420. getJSON('getJson.cgi'+'?'+Math.random(), function (data) {
  421. var alrm = +data.u_alarm;
  422. var ma = +data.m_alarm;
  423. var pstate = [];
  424. var bstate = [];
  425. var ups_bypass = Alarm(alrm, 5),
  426. ups_alarm = Alarm(alrm, 4) || Alarm(alrm, 7),
  427. ups_standby = Alarm(alrm, 3),
  428. ups_shutdown = Alarm(alrm, 1),
  429. bat_low = Alarm(alrm, 6),
  430. bat_test = Alarm(alrm, 2);
  431. // PPS
  432. $('AC').innerHTML = parseFloat(data.AC) + ' В';
  433. $('AC').style.color = Alarm(alrm, 7) ? ALARM_RED : ALARM_GREEN;
  434. $('DC').innerHTML = parseFloat(data.DC) + ' В';
  435. $('DC').style.color = Alarm(alrm, 7) ? ALARM_RED : ALARM_GREEN;
  436. $('in_freq').innerHTML = parseFloat(data.in_freq) + ' Гц';
  437. $('in_freq').style.color = Alarm(alrm, 7) ? ALARM_RED : ALARM_GREEN;
  438. $('out_freq').innerHTML = parseFloat(data.out_freq) + ' Гц';
  439. $('out_freq').style.color = Alarm(alrm, 7) ? ALARM_RED : ALARM_GREEN;
  440. $('pwr').innerHTML = parseFloat(data.pwr) + ' %';
  441. $('pwr').style.color = Alarm(ma, 0) ? ALARM_RED : ALARM_GREEN;
  442. $('pmode').innerHTML = ups_bypass ? 'Bypass' : 'Boost or Buck';
  443. // State
  444. ups_alarm ? pstate.push('exclamination') : pstate.push('normal');
  445. ups_standby ? pstate.push('clock') : null;
  446. ups_shutdown ? pstate.push('shutdown') : null;
  447. !Alarm(ma, 3) && !bat_low ? bstate.push('normal') : null;
  448. Alarm(ma, 3) ? bstate.push('exclamination') : null;
  449. bat_low ? bstate.push('batteryLow') : null;
  450. bat_test ? bstate.push('batTest') : null;
  451. setIcons('pstate_icons', pstate);
  452. setIcons('bstate_icons', bstate);
  453. // ACB
  454. $('bat_cap').innerHTML = parseFloat(data.bat_cap) + ' %';
  455. $('bat_cap').style.color = bat_low ? ALARM_RED : ALARM_GREEN;
  456. $('inner_temp').innerHTML = parseFloat(data.inner_temp) + ' °C';
  457. $('inner_temp').style.color = Alarm(ma, 1) || Alarm(ma, 5) ? ALARM_RED : ALARM_GREEN;
  458. $('bat_time_left').innerHTML = parseFloat(data.bat_time_left) + ' мин';
  459. $('bat_time_left').style.color = bat_low ? ALARM_RED : ALARM_GREEN;
  460. // Inputs
  461. $('di1').innerHTML = +data.di1 ? 'Разомкнут' : 'Замкнут';
  462. $('di1').style.color = Alarm(ma, 4) ? ALARM_RED : ALARM_GREEN;
  463. $('ro1').innerHTML = +data.ro1 ? 'Замкнут' : 'Разомкнут';
  464. $('ro1').style.color = +data.ro1 ? ALARM_RED : ALARM_GREEN;
  465. $('ro2').innerHTML = +data.ro2 ? 'Замкнут' : 'Разомкнут';
  466. $('ro2').style.color = +data.ro2 ? ALARM_RED : ALARM_GREEN;
  467. // checkState();
  468. window.setCookie('netsettings_changed', data.netsettings_changed);
  469. window.setCookie('device-error', Alarm(ma, 2));
  470. checkNotify();
  471. setTimeout(paramsRefresh, 1000);
  472. }, function (status) {
  473. if (status !== 0){
  474. alert('Не удалось получить данные.');
  475. setTimeout(paramsRefresh, 15000);
  476. }
  477. });
  478. }
  479. var mint;
  480. //########## History ############
  481. var ctrl_inputs = [
  482. 'h_param_',
  483. 'h_event_',
  484. 'h_datetime_'
  485. ];
  486. function getPage(pn){
  487. getJSON('history.cgi?page=' + pn, function(data){
  488. $('history_data').textContent = '';
  489. var n = data.page;
  490. $('currentpage').value = pn;
  491. $('pagelimit').innerHTML = data.pages;
  492. for (var i in n){
  493. var tr = document.createElement('tr');
  494. for (var num = 0; num < ctrl_inputs.length; num++) {
  495. var td = document.createElement('td');
  496. td.innerHTML = n[i].split(';')[num];
  497. td.id = ctrl_inputs[num] + i;
  498. tr.appendChild(td);
  499. }
  500. $('history_data').appendChild(tr);
  501. }
  502. window.setCookie('netsettings_changed', data.netsettings_changed);
  503. checkNotify();
  504. clearTimeout(mint);
  505. mint = setTimeout(history_dataref, 5000);
  506. }, function(){
  507. $('table').display = 'none';
  508. $('content').innerHTML =
  509. '<h1>Журнал событий</h1>'+
  510. '<div class="panel panel-default">'+
  511. '<div class="panel-heading">Ошибка</div>'+
  512. '<p style="text-align: center;">Данные отсутствуют.</p>'+
  513. '</div>';
  514. });
  515. }
  516. function history_dataref() {
  517. var pn = parseInt($('currentpage').value);
  518. getJSON('history.cgi?page=' + pn, function(data) {
  519. var p = data.page;
  520. for (var j in p) {
  521. for (var num = 0; num < ctrl_inputs.length; num++) {
  522. $(ctrl_inputs[num] + j).innerHTML = p[j].split(';')[num];
  523. }
  524. $('pagelimit').innerHTML = data.pages;
  525. }
  526. clearTimeout(mint);
  527. mint = setTimeout(history_dataref, 5000);
  528. });
  529. }
  530. function nextPage(){
  531. var next = parseInt($('currentpage').value);
  532. if (next < parseInt($('pagelimit').textContent)) {
  533. next = next + 1;
  534. getPage(next);
  535. }
  536. }
  537. function prevPage(){
  538. var prev = parseInt($('currentpage').value);
  539. if (prev != 1) {
  540. prev = prev - 1;
  541. getPage(prev);
  542. }
  543. }
  544. //########## UPS History ############
  545. var ups_inputs = [
  546. { id: 'h_inputv_', unit: ' В', parse: 'float' },
  547. { id: 'h_inputfv_', unit: ' В', parse: 'float' },
  548. { id: 'h_outputv_', unit: ' В', parse: 'float' },
  549. { id: 'h_outputc_', unit: '%', parse: 'float' },
  550. { id: 'h_inputf_', unit: ' Гц', parse: 'float' },
  551. { id: 'h_batv_', unit: ' В', parse: 'float' },
  552. { id: 'h_temp_', unit: ' °C', parse: 'float' },
  553. { id: 'h_status_', unit: '', parse: 'string' },
  554. { id: 'h_time_', unit: '', parse: 'string' }
  555. ];
  556. function getUPSPage(pn){
  557. getJSON('ups_history.cgi?page=' + pn, function(data){
  558. $('history_data').textContent = '';
  559. var n = data.page;
  560. $('currentpage').value = pn;
  561. $('pagelimit').innerHTML = data.pages;
  562. for (var i in n){
  563. var tr = document.createElement('tr');
  564. for (var num = 0; num < ups_inputs.length; num++) {
  565. var td = document.createElement('td');
  566. td.innerHTML = ups_inputs[num].parse === 'float' ? parseFloat(n[i].split(';')[num]) + ups_inputs[num].unit : n[i].split(';')[num] + ups_inputs[num].unit;
  567. td.id = ups_inputs[num].id + i;
  568. tr.appendChild(td);
  569. }
  570. $('history_data').appendChild(tr);
  571. }
  572. window.setCookie('netsettings_changed', data.netsettings_changed);
  573. checkNotify();
  574. clearTimeout(mint);
  575. mint = setTimeout(ups_history_dataref, 5000);
  576. }, function(){
  577. $('table').display = 'none';
  578. $('content').innerHTML =
  579. '<h1>Журнал событий</h1>'+
  580. '<div class="panel panel-default">'+
  581. '<div class="panel-heading">Ошибка</div>'+
  582. '<p style="text-align: center;">Данные отсутствуют.</p>'+
  583. '</div>';
  584. });
  585. }
  586. function ups_history_dataref() {
  587. var pn = parseInt($('currentpage').value);
  588. getJSON('ups_history.cgi?page=' + pn, function(data) {
  589. var p = data.page;
  590. for (var j in p) {
  591. for (var num = 0; num < ups_inputs.length; num++) {
  592. $(ups_inputs[num].id + j).innerHTML = ups_inputs[num].parse === 'float' ? parseFloat(p[j].split(';')[num]) + ups_inputs[num].unit : p[j].split(';')[num] + ups_inputs[num].unit;
  593. }
  594. $('pagelimit').innerHTML = data.pages;
  595. }
  596. clearTimeout(mint);
  597. mint = setTimeout(ups_history_dataref, 5000);
  598. });
  599. }
  600. function nextUPSPage(){
  601. var next = parseInt($('currentpage').value);
  602. if (next < parseInt($('pagelimit').textContent)) {
  603. next = next + 1;
  604. getUPSPage(next);
  605. }
  606. }
  607. function prevUPSPage(){
  608. var prev = parseInt($('currentpage').value);
  609. if (prev != 1) {
  610. prev = prev - 1;
  611. getUPSPage(prev);
  612. }
  613. }
  614. function utf8_decode (s) {
  615. var bb = '', c = 0;
  616. for (var i = 0; i < s.length; i++) {
  617. c = s.charCodeAt(i);
  618. if (c > 127) {
  619. if (c > 1024) {
  620. if (c == 1025) {
  621. c = 1016;
  622. } else if (c == 1105) {
  623. c = 1032;
  624. }
  625. bb += String.fromCharCode(c - 848);
  626. }
  627. } else {
  628. bb += s.charAt(i);
  629. }
  630. }
  631. return bb;
  632. }
  633. function msieversion() {
  634. var ua = window.navigator.userAgent;
  635. var msie = ua.indexOf('MSIE ');
  636. if (msie != -1 || !!navigator.userAgent.match(/Trident.*rv\:11\./)) /*If IE, return version number*/ return true;
  637. return false;
  638. }
  639. function blobLoad(requestUrl, fileName, buttonID){
  640. if(isMobile.iOS()){
  641. alert('На данном устройстве сохранение не доступно.');
  642. return false;
  643. }
  644. var old = $(buttonID).children[0].textContent;
  645. var pgFlag = 'Обработка';
  646. var pgFlagLen = pgFlag.length;
  647. var d = new Date();
  648. var fName;
  649. if (fileName === 'settings.dat') {
  650. fName = fileName;
  651. } else {
  652. fName = d.getDate()+'_'+(d.getMonth()+1)+'_'+d.getHours()+d.getMinutes() + '_' + fileName;
  653. }
  654. var xhr = new XMLHttpRequest();
  655. var fURL = requestUrl.split('.').pop() == 'cgi' ? requestUrl+'?' : requestUrl+'&';
  656. xhr.open('GET', fURL+'_='+ new Date().getTime());
  657. xhr.responseType = 'blob';
  658. $(buttonID).setAttribute('disabled', 'disabled');
  659. xhr.addEventListener('load', function(){
  660. $(buttonID).children[1].style.width = 0;
  661. $(buttonID).children[0].textContent = old;
  662. $(buttonID).removeAttribute('disabled');
  663. });
  664. xhr.onload = function(){
  665. if (this.status === 200) {
  666. var blob = this.response;
  667. if(msieversion()){
  668. if (window.navigator.msSaveOrOpenBlob) {
  669. window.navigator.msSaveOrOpenBlob(blob, fName);
  670. } else {
  671. var IEwindow = window.open(requestUrl);
  672. }
  673. } else {
  674. var objectUrl = URL.createObjectURL(blob);
  675. var uri = objectUrl;
  676. var link = document.createElement('a');
  677. link.href = uri;
  678. link.style = 'visibility:hidden';
  679. link.download = fName;
  680. document.body.appendChild(link);
  681. link.click();
  682. document.body.removeChild(link);
  683. }
  684. }
  685. };
  686. xhr.onprogress = function(event) {
  687. $(buttonID).children[0].textContent = parseInt((event.loaded / event.total) * 100) + '%';
  688. $(buttonID).children[1].style.width = parseInt((event.loaded / event.total) * 100) + '%';
  689. };
  690. xhr.send();
  691. }
  692. var isMobile = {
  693. Android: function() {
  694. return navigator.userAgent.match(/Android/i);
  695. },
  696. BlackBerry: function() {
  697. return navigator.userAgent.match(/BlackBerry/i);
  698. },
  699. iOS: function() {
  700. return navigator.userAgent.match(/iPhone|iPad|iPod/i);
  701. },
  702. Opera: function() {
  703. return navigator.userAgent.match(/Opera Mini/i);
  704. },
  705. Windows: function() {
  706. return navigator.userAgent.match(/IEMobile/i);
  707. },
  708. any: function() {
  709. return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
  710. }
  711. };
  712. function checkOther(ele) {
  713. if (ele.selectedIndex == 3) {
  714. var newInput = document.createElement('input');
  715. newInput.type = 'text';
  716. newInput.className = 'form-control';
  717. newInput.id = 'ntp-inp';
  718. newInput.value = ntpservipValue;
  719. newInput.style.marginTop = '10px';
  720. ele.parentNode.insertBefore(newInput, ele.nextSibling);
  721. }
  722. else if ($('ntp-inp')) {
  723. var d = $('ntp-inp');
  724. ele.parentNode.removeChild(d);
  725. }
  726. }
  727. // ################################################################################
  728. function fillTempRange(id, min, max) {
  729. var obj = $(id);
  730. for (var i = min; i <= max; i++) {
  731. var opt = document.createElement('option');
  732. opt.value = i;
  733. opt.text = i;
  734. obj.appendChild(opt);
  735. }
  736. }
  737. function settingsGET(){
  738. getJSON('settings.cgi', function(data) {
  739. //SNMP params
  740. $('managerIP').value = data.managerIP;
  741. $('read_community').value = data.read_community;
  742. $('write_community').value = data.write_community;
  743. $('managerIP2').value = data.managerIP2;
  744. $('managerIP3').value = data.managerIP3;
  745. $('managerIP4').value = data.managerIP4;
  746. $('managerIP5').value = data.managerIP5;
  747. $('di1').value = +data.di1;
  748. $('ro1').value = +data.ro1;
  749. $('ro2').value = +data.ro2;
  750. // Network params
  751. $('ipaddr').value = data.ipaddr;
  752. $('gw').value = data.gw;
  753. $('mask').value = data.mask;
  754. $('dhcp').checked = data.dhcp;
  755. // Alarms
  756. fillTempRange('temp_high', 40, 80);
  757. fillTempRange('temp_low', -40, 0);
  758. fillTempRange('loadvolt_high', 60, 120);
  759. $('temp_high').value = data.temp_high;
  760. $('temp_low').value = data.temp_low;
  761. temp_hist = new SpinBox('temp_hist', {
  762. 'name':'temp_hist','minimum':0.5,'maximum':2.0,'step':0.1,'decimals':1, 'value': data.temp_hist
  763. });
  764. $('loadvolt_high').value = data.loadvolt_high;
  765. loadvolt_hist = new SpinBox('loadvolt_hist', {
  766. 'name':'loadvolt_hist','minimum':0.5,'maximum':2.0,'step':0.1,'decimals':1, 'value': data.loadvolt_hist
  767. });
  768. // RADIUS params
  769. $('rs_server').value = data.rs_server;
  770. $('rs_port').value = data.rs_port;
  771. $('rs_pwd').value = data.rs_pwd;
  772. $('rs_key').value = data.rs_key;
  773. $('rs_enabled').checked = data.rs_enabled;
  774. $('swauth').checked = data.swauth;
  775. // DateTime
  776. if (data.ntpservip != $('ntpservip').options[0].value &&
  777. data.ntpservip != $('ntpservip').options[1].value &&
  778. data.ntpservip != $('ntpservip').options[2].value )
  779. {
  780. var newInput = document.createElement('input');
  781. newInput.type = 'text';
  782. newInput.className = 'form-control';
  783. newInput.id = 'ntp-inp';
  784. newInput.style.marginTop = '10px';
  785. $('ntpservip').options[3].selected = 'selected';
  786. $('ntpservip').options[3].value = data.ntpservip;
  787. $('ntpservip').parentNode.insertBefore(newInput, $('ntpservip').nextSibling);
  788. window.ntpservipValue = data.ntpservip;
  789. newInput.value = window.ntpservipValue;
  790. } else {
  791. window.ntpservipValue = data.ntpservip;
  792. $('ntpservip').value = window.ntpservipValue;
  793. }
  794. $('utc').value = data.utc;
  795. $('date').value = data.date;
  796. $('time').value = data.time;
  797. $('lastsynctime').value = data.lastsynctime;
  798. $('ntp').value = data.ntp;
  799. dhcpState();
  800. radiusState();
  801. authState();
  802. timesetType($('ntp'));
  803. window.setCookie('netsettings_changed', data.netsettings_changed);
  804. checkNotify();
  805. }, function() {
  806. alert('Не удалось получить данные.');
  807. });
  808. }
  809. function batTest(options) {
  810. this.options = (options ? options : {});
  811. if (this.options.time) {
  812. if (typeof this.options.time !== 'number' && this.options.time > 99) {
  813. return alert('Ошибка заданного времени');
  814. }
  815. }
  816. var str = '';
  817. for (var option in options) {
  818. str += option + '=' + options[option] + '&';
  819. }
  820. str = str.slice(0, -1);
  821. var url = 'bat_test.cgi';
  822. loadXMLDoc(url + '?' + str, 'GET', function(){
  823. this.responseText ? alert(this.responseText) : null;
  824. });
  825. }
  826. function UPSPowerOff(options) {
  827. this.options = (options ? options : {});
  828. if (typeof this.options.after !== 'number' && this.options.after > 9999) {
  829. return alert('Ошибка заданного времени отключения');
  830. }
  831. var str = '';
  832. for (var option in options) {
  833. str += option + '=' + options[option] + '&';
  834. }
  835. str = str.slice(0, -1);
  836. var url = 'ups_power.cgi';
  837. loadXMLDoc(url + '?' + str, 'GET', function(){
  838. this.responseText ? alert(this.responseText) : null;
  839. });
  840. }
  841. var apply_settings = new NotificationBox('apply-settings',
  842. {
  843. 'message': 'Внимание, для применения сетевых настроек необходимо их подтвердить. Иначе они будут сброшены в течении 10 минут.',
  844. 'bgcolor':'#ffcc00',
  845. 'textcolor': '#333',
  846. 'url': 'confirm.cgi',
  847. 'show': window.getCookie('role') < 2
  848. });
  849. var device_error = new NotificationBox('device-error',
  850. {
  851. 'message': 'Внимание, связь с UPS не установлена!',
  852. 'bgcolor':'#ec0035',
  853. 'textcolor': '#fff'
  854. });
  855. // ################################################################################
  856. function infoGet() {
  857. getJSON('info.cgi', function(data) {
  858. // Cotroller Info
  859. $('uptime').innerHTML = data.uptime;
  860. $('model').innerHTML = data.model;
  861. $('prodate').innerHTML = data.prodate;
  862. $('fwversion').innerHTML = data.fwversion;
  863. $('macaddr').innerHTML = data.macaddr;
  864. $('serno').innerHTML = data.serno;
  865. $('sysname').value = data.sysname;
  866. $('owner').value = data.owner;
  867. $('location').value = data.sysLocation;
  868. $('comment').value = data.comment;
  869. $('ups_fwversion').innerHTML = data.ups_fwversion;
  870. $('ups_sn').innerHTML = data.ups_sn;
  871. $('ups_model').innerHTML = data.ups_model;
  872. // utcParam = data.utc;
  873. window.setCookie('netsettings_changed', data.netsettings_changed);
  874. checkNotify();
  875. }, function() {
  876. alert('Не удалось получить данные.');
  877. });
  878. }
  879. // ################################################################################
  880. /*
  881. SpinBox.js
  882. Implements a spin box interface for a text field
  883. Created by Stephen Morley - http://code.stephenmorley.org/ - and released under
  884. the terms of the CC0 1.0 Universal legal code:
  885. http://creativecommons.org/publicdomain/zero/1.0/legalcode
  886. */
  887. /* Creates a spin box. The parameter is:
  888. *
  889. * container - either the DOM node to contain the spin box or the ID of the node
  890. * options - an object containing various parameters; this optional parameter
  891. * defaults to the empty object
  892. *
  893. * The options object may contain the following keys:
  894. *
  895. * className - a class name to apply to the container; the class name with the
  896. * suffixes 'Up' and 'Down' will be applied to the up and down
  897. * buttons. The default value is 'spinBox'.
  898. * value - the initial value for the spin box. The default is 0 (subject to
  899. * restrictions on the minimum and maximum value) if the input
  900. * element did not already exist, or the existing value if the input
  901. * element did already exist.
  902. * step - the value by which to increment or decrement the value. The
  903. * default value is 1.
  904. * minimum - the minimum allowed value. The default is not to have a minimum
  905. * value.
  906. * maximum - the maximum allowed value. The default is not to have a maximum
  907. * value.
  908. * decimals - the number of decimal places allowed. The default is 0.
  909. * name - input name attribute.
  910. *
  911. * Note that the minimum, maximum, and decimal places restrictions are enforced
  912. * for values set by the spin box, but a value outside of these restrictions may
  913. * be typed by the user.
  914. */
  915. function SpinBox(container, options) {
  916. // fetch the DOM node if a string was supplied
  917. if (typeof container == 'string') {
  918. container = document.getElementById(container);
  919. container.innerHTML = '';
  920. }
  921. // store the options and set the default values
  922. this.options = (options ? options : {});
  923. if (!('className' in this.options)) this.options.className = 'spinBox';
  924. if (!('step' in this.options)) this.options.step = 1;
  925. if (!('decimals' in this.options)) this.options.decimals = 0;
  926. // check whether the input field should be created
  927. var inputs = container.getElementsByTagName('input');
  928. if (inputs.length === 0) {
  929. // create the input node
  930. this.input = document.createElement('input');
  931. this.input.setAttribute('minimum', this.options.minimum);
  932. this.input.setAttribute('maximum', this.options.maximum);
  933. this.setValue('value' in this.options ? this.options.value : 0);
  934. this.setName('name' in this.options ? this.options.name : '');
  935. container.appendChild(this.input);
  936. } else {
  937. // store a reference to the input node
  938. this.input = inputs[0];
  939. this.setValue(this.options.value ? this.options.value : this.input.value);
  940. }
  941. // create the up button
  942. var upButton = document.createElement('span');
  943. upButton.appendChild(document.createElement('span'));
  944. upButton.innerHTML = '+';
  945. container.appendChild(upButton);
  946. // create the down button
  947. var downButton = document.createElement('span');
  948. downButton.appendChild(document.createElement('span'));
  949. downButton.innerHTML = '-';
  950. container.appendChild(downButton);
  951. // apply the classes
  952. container.className += ' ' + this.options.className;
  953. upButton.className = this.options.className + 'Up';
  954. downButton.className = this.options.className + 'Down';
  955. // add the listeners
  956. this.addEventListener(this.input, 'mousewheel', this.handleMouseWheel, [], true);
  957. this.addEventListener(this.input, 'DOMMouseScroll', this.handleMouseWheel, [], true);
  958. this.addEventListener(this.input, 'keydown', this.handleKeyDown, [], true);
  959. this.addEventListener(this.input, 'keypress', this.handleKeyPress, [], true);
  960. this.addEventListener(this.input, 'keyup', this.stop);
  961. this.addEventListener(upButton, 'mousedown', this.start, [true]);
  962. this.addEventListener(upButton, 'mouseup', this.stop);
  963. this.addEventListener(upButton, 'mouseout', this.stop);
  964. this.addEventListener(downButton, 'mousedown', this.start, [false]);
  965. this.addEventListener(downButton, 'mouseup', this.stop);
  966. this.addEventListener(downButton, 'mouseout', this.stop);
  967. }
  968. /* Returns the current value. This will be a number, or the value NaN if the
  969. * current contents of the input field do not start with a valid number.
  970. */
  971. SpinBox.prototype.getValue = function () {
  972. // parse and return the value
  973. return parseFloat(this.input.value);
  974. };
  975. SpinBox.prototype.setName = function (name) {
  976. // asign input name
  977. this.input.name = name;
  978. };
  979. /* Sets the value. Restrictions on the minimum and maximum value are enforced.
  980. * The parameter is:
  981. *
  982. * value - the value
  983. */
  984. SpinBox.prototype.setValue = function (value) {
  985. // ensure the value is within the permitted range
  986. if ('minimum' in this.options) value = Math.max(this.options.minimum, value);
  987. if ('maximum' in this.options) value = Math.min(this.options.maximum, value);
  988. // store the sign
  989. var sign = (value < 0 ? '-' : '');
  990. value = Math.abs(value);
  991. // determine the multiplier for rounding
  992. var multiplier = Math.pow(10, this.options.decimals);
  993. // split the value in to integer and fractional parts
  994. value = Math.round(value * multiplier);
  995. var integer = (value - value % multiplier) / multiplier;
  996. var fractional = '' + value % multiplier;
  997. // add leading zeros to the fractional part
  998. while (fractional.length < this.options.decimals) {
  999. fractional = '0' + fractional;
  1000. }
  1001. // set the value
  1002. this.input.value =
  1003. sign + integer + (this.options.decimals > 0 ? '.' + fractional : '');
  1004. // check whether the browser can dispatch events
  1005. if ('dispatchEvent' in this.input){
  1006. // create the event
  1007. try{
  1008. var event = new Event('change', {bubbles : true, cancelable : true});
  1009. }catch (e){
  1010. var event = document.createEvent('Event');
  1011. event.initEvent('change', true, true);
  1012. }
  1013. // dispatch the event
  1014. this.input.dispatchEvent(event);
  1015. }
  1016. };
  1017. /* Adds an event listener to a node. The event listener is bound to the current
  1018. * value of 'this'. The parameters are:
  1019. *
  1020. * node - the node
  1021. * event - the event name
  1022. * listener - the listener functions
  1023. * parameters - an array of additional parameters to pass to the listener;
  1024. * these are placed after the event parameter
  1025. * allowDefault - true if the default action should not be prevented
  1026. */
  1027. SpinBox.prototype.addEventListener = function (
  1028. node, event, listener, parameters, allowDefault) {
  1029. // store a reference to the 'this' object
  1030. var thisObject = this;
  1031. // create the bound listener
  1032. function boundListener(e) {
  1033. // get the event if it is not supplied
  1034. if (!e) e = window.event;
  1035. // call the listener
  1036. listener.apply(thisObject, [e].concat(parameters));
  1037. // prevent the default action if necessary
  1038. if (!allowDefault) {
  1039. if (e.preventDefault) {
  1040. e.preventDefault();
  1041. } else {
  1042. e.returnValue = false;
  1043. }
  1044. }
  1045. }
  1046. // add the event listener
  1047. if (node.addEventListener) {
  1048. node.addEventListener(event, boundListener, false);
  1049. } else {
  1050. node.attachEvent('on' + event, boundListener);
  1051. }
  1052. };
  1053. /* Handles a mouse wheel event by updating the value if the field is active. The
  1054. * parameter is:
  1055. *
  1056. * e - the event object
  1057. */
  1058. SpinBox.prototype.handleMouseWheel = function (e) {
  1059. // check whether the field is active
  1060. if (document.activeElement == this.input) {
  1061. // update the value
  1062. if (e.wheelDelta) {
  1063. this.start(e, e.wheelDelta > 1);
  1064. } else if (e.detail) {
  1065. this.start(e, e.detail < 1);
  1066. }
  1067. this.stop();
  1068. // prevent the default action
  1069. if (e.preventDefault) {
  1070. e.preventDefault();
  1071. } else {
  1072. e.returnValue = false;
  1073. }
  1074. }
  1075. };
  1076. /* Handles a key down event by starting updating if appropriate. The parameter
  1077. * is:
  1078. *
  1079. * e - the event object
  1080. */
  1081. SpinBox.prototype.handleKeyDown = function (e) {
  1082. // if the up or down keys were pressed, start updating
  1083. if (e.keyCode == 38) this.start(e, true);
  1084. if (e.keyCode == 40) this.start(e, false);
  1085. };
  1086. /* Handles a key press event by filtering out invalid characters. The parameter
  1087. * is:
  1088. *
  1089. * e - the event object
  1090. */
  1091. SpinBox.prototype.handleKeyPress = function (e) {
  1092. // determine the character code
  1093. var charCode = ('charCode' in e ? e.charCode : e.keyCode);
  1094. // allow special key presses
  1095. if (charCode === 0 || e.altKey || e.ctrlKey || e.metaKey) return;
  1096. // allow a minus sign if the value can be negative
  1097. if (charCode == 45 && (!('minimum' in this.options) || this.options.minimum < 0)) {
  1098. return;
  1099. }
  1100. // allow a decimal point if the value may contain decimals
  1101. if (charCode == 46 && this.options.decimals > 0) return;
  1102. // allow digits
  1103. if (charCode >= 48 && charCode <= 57) return;
  1104. // prevent the default action
  1105. if (e.preventDefault) {
  1106. e.preventDefault();
  1107. } else {
  1108. e.returnValue = false;
  1109. }
  1110. };
  1111. /* Starts updating the value. The parameters are:
  1112. *
  1113. * e - the event object
  1114. * up - true to increment the value, false to decrement the value
  1115. */
  1116. SpinBox.prototype.start = function (e, up) {
  1117. // if the field is disabled or we are already updating, return immediately
  1118. if (this.input.disabled || 'timeout' in this) return;
  1119. // set the update step
  1120. this.updateStep = (up ? this.options.step : -this.options.step);
  1121. // initialise the timeout delay
  1122. this.timeoutDelay = 500;
  1123. // update the value
  1124. this.update();
  1125. };
  1126. // Stops update the value.
  1127. SpinBox.prototype.stop = function () {
  1128. // clear the timeout if it exists
  1129. if ('timeout' in this) {
  1130. window.clearTimeout(this.timeout);
  1131. delete this.timeout;
  1132. }
  1133. };
  1134. // Updates the value.
  1135. SpinBox.prototype.update = function () {
  1136. // determine the current value
  1137. var value = parseFloat(this.input.value);
  1138. if (isNaN(value)) value = 0;
  1139. // update the value
  1140. this.setValue(value + this.updateStep);
  1141. // reduce the delay
  1142. this.timeoutDelay = Math.max(20, Math.floor(this.timeoutDelay * 0.9));
  1143. // call this function again
  1144. var thisObject = this;
  1145. this.timeout = window.setTimeout(function () { thisObject.update(); }, this.timeoutDelay);
  1146. };
  1147. /*
  1148. This code is from Dynamic Web Coding at dyn-web.com
  1149. Copyright 2009-12 by Sharon Paine
  1150. See Terms of Use at www.dyn-web.com/business/terms.php
  1151. regarding conditions under which you may use this code.
  1152. This notice must be retained in the code as is!
  1153. */
  1154. // DYN_WEB is namespace used for code from dyn-web.com
  1155. // replacing previous use of dw_ prefix for object names
  1156. var DYN_WEB = DYN_WEB || {};
  1157. DYN_WEB.Event = {
  1158. add: document.addEventListener ? function (obj, etype, fp, cap) {
  1159. cap = cap || false;
  1160. obj.addEventListener(etype, fp, cap);
  1161. } : function (obj, etype, fp) {
  1162. obj.attachEvent('on' + etype, fp);
  1163. },
  1164. remove: document.removeEventListener ? function (obj, etype, fp, cap) {
  1165. cap = cap || false;
  1166. obj.removeEventListener(etype, fp, cap);
  1167. } : function (obj, etype, fp) {
  1168. obj.detachEvent('on' + etype, fp);
  1169. },
  1170. DOMit: function (e) {
  1171. e = e ? e : window.event;
  1172. if (!e.target) e.target = e.srcElement;
  1173. if (!e.preventDefault) e.preventDefault = function () {
  1174. e.returnValue = false;
  1175. return false;
  1176. };
  1177. if (!e.stopPropagation) e.stopPropagation = function () {
  1178. e.cancelBubble = true;
  1179. };
  1180. return e;
  1181. },
  1182. getTarget: function (e) {
  1183. e = dw_Event.DOMit(e);
  1184. var tgt = e.target;
  1185. if (tgt.nodeType != 1) tgt = tgt.parentNode;
  1186. return tgt;
  1187. }
  1188. };
  1189. DYN_WEB.Cookie = {
  1190. set: function (name, value, days, path, domain, secure) {
  1191. var date, expires;
  1192. if (typeof days == 'number') {
  1193. date = new Date();
  1194. date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
  1195. expires = date.toGMTString();
  1196. }
  1197. document.cookie = name + '=' + encodeURIComponent(value) + (
  1198. (expires) ? '; expires=' + expires : ''
  1199. ) + (
  1200. (path) ? '; path=' + path : ''
  1201. ) + (
  1202. (domain) ? '; domain=' + domain : ''
  1203. ) + (
  1204. (secure) ? '; secure' : '');
  1205. },
  1206. get: function (name) {
  1207. var c, cookies = document.cookie.split(/;\s/g);
  1208. for (var i = 0; cookies[i]; i++) {
  1209. c = cookies[i];
  1210. if (c.indexOf(name + '=') === 0) {
  1211. return decodeURIComponent(c.slice(name.length + 1, c.length));
  1212. }
  1213. }
  1214. return null;
  1215. },
  1216. del: function (name, path, domain) {
  1217. if (dw_Cookie.get(name)) {
  1218. document.cookie = name + '=' + (
  1219. (path) ? '; path=' + path : ''
  1220. ) + (
  1221. (domain) ? '; domain=' + domain : ''
  1222. ) + '; expires=Thu, 01-Jan-70 00:00:01 GMT';
  1223. }
  1224. }
  1225. };
  1226. if (!DYN_WEB.Util) {
  1227. DYN_WEB.Util = {
  1228. // add props of Obj2 to Obj1
  1229. augment: function (Obj1, Obj2) {
  1230. var prop;
  1231. for (prop in Obj2) {
  1232. if (Obj2.hasOwnProperty(prop) && !Obj1[prop]) {
  1233. Obj1[prop] = Obj2[prop];
  1234. }
  1235. }
  1236. },
  1237. $: function (id) {
  1238. return document.getElementById(id);
  1239. }
  1240. };
  1241. }
  1242. DYN_WEB.Tabs = (function () {
  1243. // obj holds props: id, useCookies, etc.
  1244. function Constr(obj) {
  1245. this.useCookies = obj.useCookies;
  1246. this.before_hide = obj.before_hide || function () {};
  1247. this.on_activate = obj.on_activate || function () {};
  1248. this.on_init = obj.on_init || function () {};
  1249. Constr.col[obj.id] = this;
  1250. Constr.init(obj.id);
  1251. }
  1252. Constr.col = {};
  1253. Constr.prototype = {
  1254. current: null // id of currently active pane
  1255. };
  1256. return Constr;
  1257. })();
  1258. (function () {
  1259. var Ut = DYN_WEB.Util,
  1260. Ev = DYN_WEB.Event,
  1261. Cookie = DYN_WEB.Cookie,
  1262. Tabs = DYN_WEB.Tabs;
  1263. Ut.augment(Tabs, {
  1264. // static props/methods for DYN_WEB.Tabs
  1265. setup: function () {
  1266. var obj, settings = [];
  1267. if (Tabs.hasBrowserSupport()) {
  1268. for (var i = 0; obj = arguments[i]; i++) {
  1269. if (obj.css) {
  1270. Ut.writeStyleSheet(obj.css);
  1271. }
  1272. settings[i] = obj; // save to pass to constructor onload
  1273. }
  1274. Ev.add(window, 'load', function () {
  1275. for (var i = 0; settings[i]; i++) {
  1276. new Tabs(settings[i]);
  1277. }
  1278. });
  1279. }
  1280. },
  1281. hasBrowserSupport: function () {
  1282. if (document.getElementById && document.getElementsByTagName && typeof decodeURI !== 'undefined' && (document.addEventListener || document.attachEvent)) {
  1283. return true;
  1284. }
  1285. return false;
  1286. },
  1287. init: function (tabsetId) {
  1288. var _this = Tabs.col[tabsetId],
  1289. links = Tabs.getTabs(tabsetId),
  1290. // code uses hash in tab links but tabs can also link to other pages
  1291. // so compare current location to link's href
  1292. loc = Ut.getURLtoHash(location),
  1293. lnk, pg, paneId, pane, sel, dflt, cur, c, q, hash;
  1294. q = Ut.getValueFromQueryString(tabsetId);
  1295. if (_this.useCookies) {
  1296. c = Tabs.checkCookie(tabsetId);
  1297. }
  1298. // tab in query string or cookie?
  1299. sel = q ? q : c ? c : null;
  1300. // add ids and event handlers to links ...
  1301. for (var i = 0; lnk = links[i]; i++) {
  1302. paneId = '', pane = ''; // reset
  1303. pg = Ut.getURLtoHash(lnk);
  1304. hash = Ut.getHash(lnk);
  1305. if (lnk.hash && (loc == pg)) { // has hash and points to current page
  1306. paneId = hash;
  1307. lnk.id = tabsetId + '__' + paneId; // double underscore between
  1308. }
  1309. // if tab associated with tabpane, set up onclick fn
  1310. if (paneId) {
  1311. try {
  1312. pane = Ut.$(paneId);
  1313. } catch (err) { // showClicked fn throws
  1314. }
  1315. // first tab/pane is default
  1316. if (!dflt) {
  1317. dflt = paneId;
  1318. }
  1319. // if set active in markup, hold as current
  1320. if (pane && Ut.hasClass(lnk, 'activeTab') && Ut.hasClass(pane, 'activePane')) {
  1321. _this.current = cur = paneId;
  1322. }
  1323. // to pass paneId, tabsetId to showClicked...
  1324. Ev.add(lnk, 'click', function (paneId, tabsetId) {
  1325. return function (e) {
  1326. Tabs.showClicked(e, paneId, tabsetId);
  1327. };
  1328. }(paneId, tabsetId));
  1329. }
  1330. }
  1331. // check if tab and pane for sel
  1332. if (sel && (lnk = Ut.$(tabsetId + '__' + sel)) && (pane = Ut.$(sel))) {
  1333. if (cur && cur !== sel) {
  1334. Tabs.hideCurrent(tabsetId, cur);
  1335. }
  1336. Ut.addClass(lnk, 'activeTab');
  1337. Ut.addClass(pane, 'activePane');
  1338. _this.current = sel;
  1339. } else if (!cur && dflt) {
  1340. Ut.addClass(Ut.$(tabsetId + '__' + dflt), 'activeTab');
  1341. Ut.addClass(Ut.$(dflt), 'activePane');
  1342. _this.current = dflt;
  1343. }
  1344. _this.on_init();
  1345. },
  1346. getTabs: function (id) {
  1347. var set = Ut.$(id),
  1348. list, links;
  1349. if (!set) {
  1350. throw new Error('No element matching tabset id found.');
  1351. return [];
  1352. }
  1353. list = Ut.getElementsByClassName('tabnavs', 'ul', set);
  1354. if (list.length === 0) {
  1355. throw new Error('No tabnavs were found in the tabset.');
  1356. return [];
  1357. }
  1358. links = list[0].getElementsByTagName('a');
  1359. return links;
  1360. },
  1361. showClicked: function (e, paneId, tabsetId) {
  1362. var tabId = tabsetId + '__' + paneId;
  1363. var _this = Tabs.col[tabsetId];
  1364. _this.before_hide(tabId, paneId, tabsetId);
  1365. Tabs.hideCurrent(tabsetId, _this.current);
  1366. Ut.addClass(Ut.$(tabId), 'activeTab');
  1367. try {
  1368. Ut.addClass(Ut.$(paneId), 'activePane');
  1369. } catch (err) {
  1370. throw new Error('showClicked can\'t find pane associated with tab. Check tab hash and pane id.');
  1371. return false;
  1372. }
  1373. _this.current = paneId;
  1374. if (_this.useCookies) {
  1375. Tabs.setCookie(tabsetId, paneId);
  1376. }
  1377. _this.on_activate(tabId, paneId, tabsetId);
  1378. if (e) {
  1379. Ev.DOMit(e);
  1380. e.preventDefault();
  1381. }
  1382. return false;
  1383. },
  1384. hideCurrent: function (tabsetId, cur) {
  1385. var tab = Ut.$(tabsetId + '__' + cur),
  1386. pane = Ut.$(cur);
  1387. Ut.removeClass(tab, 'activeTab');
  1388. Ut.removeClass(pane, 'activePane');
  1389. },
  1390. checkCookie: function (tabsetId) {
  1391. var c, cookies, tab_cookies = Cookie.get('dw_Tabs');
  1392. if (tab_cookies) {
  1393. cookies = tab_cookies.split(',');
  1394. for (var i = 0; cookies[i]; i++) {
  1395. c = cookies[i];
  1396. if (c.indexOf(tabsetId + ':') === 0) {
  1397. return decodeURI(c.slice(tabsetId.length + 1, c.length));
  1398. }
  1399. }
  1400. }
  1401. return null;
  1402. },
  1403. setCookie: function (tabsetId, paneId) {
  1404. // format for cookies (multiple tabsets supported): dw_Tabs=tabsetId:paneId,tabsetId:paneId;
  1405. var new_tab_cookies = '',
  1406. cookies,
  1407. tab_cookies = Cookie.get('dw_Tabs');
  1408. if (tab_cookies) {
  1409. cookies = tab_cookies.split(',');
  1410. for (var i = 0; cookies[i]; i++) {
  1411. if (cookies[i].indexOf(tabsetId + ':') === 0) {
  1412. cookies[i] = tabsetId + ':' + paneId;
  1413. new_tab_cookies = cookies.join(',');
  1414. break;
  1415. }
  1416. }
  1417. if (!new_tab_cookies) { // if no match for this tabsetId
  1418. new_tab_cookies = tab_cookies + ',' + tabsetId + ':' + paneId;
  1419. }
  1420. } else { // no dw_Tabs set yet
  1421. new_tab_cookies = tabsetId + ':' + paneId;
  1422. }
  1423. Cookie.set('dw_Tabs', new_tab_cookies, null, '/');
  1424. }
  1425. });
  1426. })();
  1427. // util
  1428. (function () {
  1429. var Ut = DYN_WEB.Util;
  1430. // add methods to DYN_WEB.Util
  1431. Ut.augment(Ut, {
  1432. trim: function (str) {
  1433. if (String.prototype.trim) {
  1434. return str.trim(); // ECMAScript 5
  1435. } else {
  1436. var re = /^\s+|\s+$/g;
  1437. return str.replace(re, '');
  1438. }
  1439. },
  1440. normalizeString: function (str) {
  1441. var re = /\s\s+/g;
  1442. return Ut.trim(str).replace(re, ' ');
  1443. },
  1444. hasClass: function (el, cl) {
  1445. var re = new RegExp('\\b' + cl + '\\b', 'i');
  1446. if (re.test(el.className)) {
  1447. return true;
  1448. }
  1449. return false;
  1450. },
  1451. addClass: function (el, cl) {
  1452. if (!Ut.hasClass(el, cl)) {
  1453. el.className = Ut.trim(el.className + ' ' + cl);
  1454. }
  1455. },
  1456. removeClass: function (el, cl) {
  1457. el.className = Ut.normalizeString(el.className.replace(cl, ' '));
  1458. },
  1459. getElementsByClassName: function (sClass, sTag, oCont) {
  1460. oCont = oCont ? oCont : document;
  1461. if (oCont.getElementsByClassName) {
  1462. return oCont.getElementsByClassName(sClass); // html5
  1463. } else {
  1464. sTag = sTag || '*';
  1465. var result = [],
  1466. re = new RegExp('\\b' + sClass + '\\b', 'i'),
  1467. list = oCont.getElementsByTagName(sTag);
  1468. for (var i = 0; list[i]; i++) {
  1469. if (re.test(list[i].className)) result.push(list[i]);
  1470. }
  1471. return result;
  1472. }
  1473. },
  1474. // obj: link or window.location
  1475. getValueFromQueryString: function (name, obj) {
  1476. obj = obj ? obj : window.location;
  1477. var pairs, set;
  1478. if (obj.search && obj.search.indexOf(name != -1)) {
  1479. pairs = obj.search.slice(1).split('&'); // name/value pairs
  1480. for (var i = 0; pairs[i]; i++) {
  1481. set = pairs[i].split('='); // Check each pair for match on name
  1482. if (set[0] == name && set[1]) {
  1483. return set[1];
  1484. }
  1485. }
  1486. }
  1487. return '';
  1488. },
  1489. getURLtoHash: function (obj) {
  1490. obj = obj ? obj : window.location;
  1491. var href = obj.href,
  1492. pt = href.indexOf('#'),
  1493. url = (pt != -1) ? href.slice(0, pt) : href; // remove hash from href
  1494. return url;
  1495. },
  1496. getHash: function (obj) {
  1497. obj = obj ? obj : window.location;
  1498. var hash = '';
  1499. if (obj.hash) { // some browsers say true if just #, some '' (ff)
  1500. hash = obj.hash.slice(1);
  1501. }
  1502. return hash;
  1503. },
  1504. // Alternate functions are available that use DOM methods instead of document.write
  1505. writeStyleSheet: function (file, bScreen) {
  1506. var screen = (bScreen !== false) ? '" media="screen" />\n' : '"/>\n';
  1507. document.write('\n<link rel="stylesheet" href="' + file + screen);
  1508. },
  1509. // used to set min-height (as on dyn-web home page)
  1510. writeStyleRule: function (rule, bScreen) {
  1511. var screen = (bScreen !== false) ? ' media="screen">' : '>';
  1512. document.write('\n<style type="text/css"' + screen + rule + '</style>');
  1513. }
  1514. });
  1515. })();
  1516. (function (window) {
  1517. /**
  1518. * @param {String} type - request | cancel | native.
  1519. * @return {Function} Timing function.
  1520. */
  1521. function requestFrame(type) {
  1522. // The only vendor prefixes required.
  1523. var vendors = ['moz', 'webkit'],
  1524. // Disassembled timing function abbreviations.
  1525. aF = 'AnimationFrame',
  1526. rqAF = 'Request' + aF,
  1527. // Final assigned functions.
  1528. assignedRequestAnimationFrame,
  1529. assignedCancelAnimationFrame,
  1530. // Initial time of the timing lapse.
  1531. previousTime = 0,
  1532. mozRAF = window.mozRequestAnimationFrame,
  1533. mozCAF = window.mozCancelAnimationFrame,
  1534. // Checks for firefox 4 - 10 function pair mismatch.
  1535. hasMozMismatch = mozRAF && !mozCAF,
  1536. func;
  1537. // Date.now polyfill, mainly for legacy IE versions.
  1538. if (!Date.now) {
  1539. Date.now = function() {
  1540. return new Date().getTime();
  1541. };
  1542. }
  1543. /**
  1544. * hasIOS6RequestAnimationFrameBug.
  1545. * @See {@Link https://gist.github.com/julienetie/86ac394ec41f1271ff0a}
  1546. * - for Commentary.
  1547. * @Copyright 2015 - Julien Etienne.
  1548. * @License: MIT.
  1549. */
  1550. function hasIOS6RequestAnimationFrameBug() {
  1551. var webkitRAF = window.webkitRequestAnimationFrame,
  1552. rAF = window.requestAnimationFrame,
  1553. // CSS/ Device with max for iOS6 Devices.
  1554. hasMobileDeviceWidth = screen.width <= 768 ? true : false,
  1555. // Only supports webkit prefixed requestAnimtionFrane.
  1556. requiresWebkitprefix = !(webkitRAF && rAF),
  1557. // iOS6 webkit browsers don't support performance now.
  1558. hasNoNavigationTiming = window.performance ? false : true,
  1559. iOS6Notice = 'setTimeout is being used as a substitiue for' +
  1560. 'requestAnimationFrame due to a bug within iOS 6 builds',
  1561. hasIOS6Bug = requiresWebkitprefix && hasMobileDeviceWidth &&
  1562. hasNoNavigationTiming;
  1563. function bugCheckresults(timingFnA, timingFnB, notice) {
  1564. if (timingFnA || timingFnB) {
  1565. console.warn(notice);
  1566. return true;
  1567. } else {
  1568. return false;
  1569. }
  1570. }
  1571. function displayResults() {
  1572. if (hasIOS6Bug) {
  1573. return bugCheckresults(webkitRAF, rAF, iOS6Notice);
  1574. } else {
  1575. return false;
  1576. }
  1577. }
  1578. return displayResults();
  1579. }
  1580. /**
  1581. * Native clearTimeout function.
  1582. * @return {Function}
  1583. */
  1584. function clearTimeoutWithId(id) {
  1585. clearTimeout(id);
  1586. }
  1587. /**
  1588. * Based on a polyfill by Erik, introduced by Paul Irish &
  1589. * further improved by Darius Bacon.
  1590. * @see {@link http://www.paulirish.com/2011/
  1591. * requestanimationframe-for-smart-animating}
  1592. * @see {@link https://github.com/darius/requestAnimationFrame/blob/
  1593. * master/requestAnimationFrame.js}
  1594. * @callback {Number} Timestamp.
  1595. * @return {Function} setTimeout Function.
  1596. */
  1597. function setTimeoutWithTimestamp(callback) {
  1598. var immediateTime = Date.now(),
  1599. lapsedTime = Math.max(previousTime + 16, immediateTime);
  1600. return setTimeout(function() {
  1601. callback(previousTime = lapsedTime);
  1602. },
  1603. lapsedTime - immediateTime);
  1604. }
  1605. /**
  1606. * Queries the native function, prefixed function
  1607. * or use the setTimeoutWithTimestamp function.
  1608. * @return {Function}
  1609. */
  1610. function queryRequestAnimationFrame() {
  1611. if (Array.prototype.filter) {
  1612. assignedRequestAnimationFrame = window['request' + aF] ||
  1613. window[vendors.filter(function(vendor) {
  1614. if (window[vendor + rqAF] !== undefined)
  1615. return vendor;
  1616. }) + rqAF] || setTimeoutWithTimestamp;
  1617. } else {
  1618. return setTimeoutWithTimestamp;
  1619. }
  1620. if (!hasIOS6RequestAnimationFrameBug()) {
  1621. return assignedRequestAnimationFrame;
  1622. } else {
  1623. return setTimeoutWithTimestamp;
  1624. }
  1625. }
  1626. /**
  1627. * Queries the native function, prefixed function
  1628. * or use the clearTimeoutWithId function.
  1629. * @return {Function}
  1630. */
  1631. function queryCancelAnimationFrame() {
  1632. var cancellationNames = [];
  1633. if (Array.prototype.map) {
  1634. vendors.map(function(vendor) {
  1635. return ['Cancel', 'CancelRequest'].map(
  1636. function(cancellationNamePrefix) {
  1637. cancellationNames.push(vendor +
  1638. cancellationNamePrefix + aF);
  1639. });
  1640. });
  1641. } else {
  1642. return clearTimeoutWithId;
  1643. }
  1644. /**
  1645. * Checks for the prefixed cancelAnimationFrame implementation.
  1646. * @param {Array} prefixedNames - An array of the prefixed names.
  1647. * @param {Number} i - Iteration start point.
  1648. * @return {Function} prefixed cancelAnimationFrame function.
  1649. */
  1650. function prefixedCancelAnimationFrame(prefixedNames, i) {
  1651. var cancellationFunction;
  1652. for (; i < prefixedNames.length; i++) {
  1653. if (window[prefixedNames[i]]) {
  1654. cancellationFunction = window[prefixedNames[i]];
  1655. break;
  1656. }
  1657. }
  1658. return cancellationFunction;
  1659. }
  1660. // Use truthly function
  1661. assignedCancelAnimationFrame = window['cancel' + aF] ||
  1662. prefixedCancelAnimationFrame(cancellationNames, 0) ||
  1663. clearTimeoutWithId;
  1664. // Check for iOS 6 bug
  1665. if (!hasIOS6RequestAnimationFrameBug()) {
  1666. return assignedCancelAnimationFrame;
  1667. } else {
  1668. return clearTimeoutWithId;
  1669. }
  1670. }
  1671. function getRequestFn() {
  1672. if (hasMozMismatch) {
  1673. return setTimeoutWithTimestamp;
  1674. } else {
  1675. return queryRequestAnimationFrame();
  1676. }
  1677. }
  1678. function getCancelFn() {
  1679. return queryCancelAnimationFrame();
  1680. }
  1681. function setNativeFn() {
  1682. if (hasMozMismatch) {
  1683. window.requestAnimationFrame = setTimeoutWithTimestamp;
  1684. window.cancelAnimationFrame = clearTimeoutWithId;
  1685. } else {
  1686. window.requestAnimationFrame = queryRequestAnimationFrame();
  1687. window.cancelAnimationFrame = queryCancelAnimationFrame();
  1688. }
  1689. }
  1690. /**
  1691. * The type value "request" singles out firefox 4 - 10 and
  1692. * assigns the setTimeout function if plausible.
  1693. */
  1694. switch (type) {
  1695. case 'request':
  1696. case '':
  1697. func = getRequestFn();
  1698. break;
  1699. case 'cancel':
  1700. func = getCancelFn();
  1701. break;
  1702. case 'native':
  1703. setNativeFn();
  1704. break;
  1705. default:
  1706. throw new Error('RequestFrame parameter is not a type.');
  1707. }
  1708. return func;
  1709. }
  1710. // Default to window as global
  1711. if (typeof window === 'object') {
  1712. window.requestFrame = requestFrame;
  1713. }
  1714. /* global-define */
  1715. }((typeof window === 'undefined' ? {} : window)));
  1716. // Icons
  1717. var Icons = {
  1718. clock: {
  1719. icn: '<svg width="20" height="20" viewBox="0 0 1792 1792" xmlns="http://www.w3.org/2000/svg"><path d="M1024 544v448q0 14-9 23t-23 9h-320q-14 0-23-9t-9-23v-64q0-14 9-23t23-9h224v-352q0-14 9-23t23-9h64q14 0 23 9t9 23zm416 352q0-148-73-273t-198-198-273-73-273 73-198 198-73 273 73 273 198 198 273 73 273-73 198-198 73-273zm224 0q0 209-103 385.5t-279.5 279.5-385.5 103-385.5-103-279.5-279.5-103-385.5 103-385.5 279.5-279.5 385.5-103 385.5 103 279.5 279.5 103 385.5z" fill="'+ ALARM_YELLOW +'"/></svg>',
  1720. title: 'Режим ожидания'
  1721. },
  1722. exclamination: {
  1723. icn: '<svg width="20" height="20" viewBox="0 0 1792 1792" xmlns="http://www.w3.org/2000/svg"><path d="M1088 1248v224q0 26-19 45t-45 19h-256q-26 0-45-19t-19-45v-224q0-26 19-45t45-19h256q26 0 45 19t19 45zm30-1056l-28 768q-1 26-20.5 45t-45.5 19h-256q-26 0-45.5-19t-20.5-45l-28-768q-1-26 17.5-45t44.5-19h320q26 0 44.5 19t17.5 45z" fill="'+ ALARM_RED +'"/></svg>',
  1724. title: 'Авария'
  1725. },
  1726. normal: {
  1727. icn: '<svg width="20" height="20" viewBox="0 0 1792 1792" xmlns="http://www.w3.org/2000/svg"><path d="M1299 813l-422 422q-19 19-45 19t-45-19l-294-294q-19-19-19-45t19-45l102-102q19-19 45-19t45 19l147 147 275-275q19-19 45-19t45 19l102 102q19 19 19 45t-19 45zm141 83q0-148-73-273t-198-198-273-73-273 73-198 198-73 273 73 273 198 198 273 73 273-73 198-198 73-273zm224 0q0 209-103 385.5t-279.5 279.5-385.5 103-385.5-103-279.5-279.5-103-385.5 103-385.5 279.5-279.5 385.5-103 385.5 103 279.5 279.5 103 385.5z" fill="'+ ALARM_GREEN +'"/></svg>',
  1728. title: 'Норма'
  1729. },
  1730. shutdown: {
  1731. icn: '<svg width="20" height="20" viewBox="0 0 1792 1792" xmlns="http://www.w3.org/2000/svg"><path d="M1664 896q0 156-61 298t-164 245-245 164-298 61-298-61-245-164-164-245-61-298q0-182 80.5-343t226.5-270q43-32 95.5-25t83.5 50q32 42 24.5 94.5t-49.5 84.5q-98 74-151.5 181t-53.5 228q0 104 40.5 198.5t109.5 163.5 163.5 109.5 198.5 40.5 198.5-40.5 163.5-109.5 109.5-163.5 40.5-198.5q0-121-53.5-228t-151.5-181q-42-32-49.5-84.5t24.5-94.5q31-43 84-50t95 25q146 109 226.5 270t80.5 343zm-640-768v640q0 52-38 90t-90 38-90-38-38-90v-640q0-52 38-90t90-38 90 38 38 90z" fill="'+ ALARM_RED +'"/></svg>',
  1732. title: 'Выключение'
  1733. },
  1734. batteryLow: {
  1735. icn: '<svg width="30" height="20" viewBox="0 0 1792 1792" xmlns="http://www.w3.org/2000/svg"><path d="M1920 576q53 0 90.5 37.5t37.5 90.5v384q0 53-37.5 90.5t-90.5 37.5v160q0 66-47 113t-113 47h-1856q-66 0-113-47t-47-113v-960q0-66 47-113t113-47h1856q66 0 113 47t47 113v160zm0 512v-384h-128v-288q0-14-9-23t-23-9h-1856q-14 0-23 9t-9 23v960q0 14 9 23t23 9h1856q14 0 23-9t9-23v-288h128z" fill="'+ ALARM_RED +'"/></svg>',
  1736. title: 'Низкий уровень заряда'
  1737. },
  1738. batTest: {
  1739. icn: '<svg width="20" height="20" viewBox="0 0 1792 1792" xmlns="http://www.w3.org/2000/svg"><path d="M1024 1408h640v-128h-640v128zm-384-512h1024v-128h-1024v128zm640-512h384v-128h-384v128zm512 832v256q0 26-19 45t-45 19h-1664q-26 0-45-19t-19-45v-256q0-26 19-45t45-19h1664q26 0 45 19t19 45zm0-512v256q0 26-19 45t-45 19h-1664q-26 0-45-19t-19-45v-256q0-26 19-45t45-19h1664q26 0 45 19t19 45zm0-512v256q0 26-19 45t-45 19h-1664q-26 0-45-19t-19-45v-256q0-26 19-45t45-19h1664q26 0 45 19t19 45z" fill="'+ ALARM_YELLOW +'"/></svg>',
  1740. title: 'Тестирование'
  1741. }
  1742. };