main.js 63 KB

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