init.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713
  1. // Replace .no-js class with .js
  2. document.documentElement.className = document.documentElement.className.replace('no-js', 'js')
  3. $(document).ready(function(){
  4. if($('.body-login')[0]){
  5. $('input').first().focus();
  6. }
  7. $(".submenu-select-dropdown").each(function(){
  8. $(this).wrap("<span class='submenu-select-wrapper'></span>");
  9. $(this).after("<span class='holder'></span>");
  10. });
  11. $(".submenu-select-dropdown").change(function(){
  12. var selectedOption = $(this).find(":selected").text();
  13. $(this).next(".holder").text(selectedOption);
  14. }).trigger('change');
  15. $('.to-top').on('click', function(evt) {
  16. evt.preventDefault();
  17. $("html, body").animate({ scrollTop: 0 }, "normal");
  18. });
  19. $('.button').on('click',function(evt){
  20. var action = $(this).data('action');
  21. var id = $(this).data('id');
  22. if(action=='submit' && document.getElementById(id)){
  23. evt.preventDefault();
  24. $(document.getElementById(id)).submit();
  25. }
  26. });
  27. var isMobile = false; //initiate as false
  28. // device detection
  29. /* eslint-disable no-useless-escape */
  30. if(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|ipad|iris|kindle|Android|Silk|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(navigator.userAgent)
  31. || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(navigator.userAgent.substr(0,4))){
  32. isMobile = true;
  33. $('body').addClass('mobile');
  34. }
  35. /* eslint-enable no-useless-escape */
  36. $(window).scroll(function(){set_sticky_class()});
  37. $('.l-sort-toolbar .sort-by').click(function(){
  38. $('.context-menu.sort-order').toggle().css({left: $(this).parent().parent().parent().position().left - 0});
  39. });
  40. // CREATE BUTTON
  41. $('.l-sort__create-btn').hover(function(){
  42. $(".l-sort__create-btn").append("<div id='add-icon'></div>");
  43. $(".l-sort__create-btn").append("<div id='tooltip'>"+$('.l-sort__create-btn').attr('title').replace(' ','&nbsp;')+"</div>");
  44. }, function(){
  45. $("#add-icon").remove();
  46. $("#tooltip").remove();
  47. });
  48. // SEARCH BOX
  49. $('.l-sort-toolbar__search, .l-sort-toolbar__search-box .js-search-input').hover(function(){
  50. clearTimeout(VE.tmp.search_display_interval);
  51. clearTimeout(VE.tmp.search_hover_interval);
  52. VE.tmp.search_display_interval = setTimeout(function(){$('.js-search-input').addClass('activated');}, 150);
  53. }, function(){
  54. clearTimeout(VE.tmp.search_display_interval);
  55. clearTimeout(VE.tmp.search_hover_interval);
  56. VE.tmp.search_hover_interval = setTimeout(function(){
  57. if(!VE.tmp.search_activated && !$(".js-search-input").val().length){
  58. $(".js-search-input").removeClass('activated');
  59. }
  60. }, 600);
  61. });
  62. $('.js-search-input').focus(function(){
  63. VE.tmp.search_activated = 1;
  64. clearTimeout(VE.tmp.search_hover_interval);
  65. });
  66. $('.js-search-input').blur(function(){
  67. VE.tmp.search_activated = 0;
  68. clearTimeout(VE.tmp.search_hover_interval);
  69. VE.tmp.search_hover_interval = setTimeout(function(){
  70. if(!$(".js-search-input").val().length){
  71. $(".js-search-input").removeClass('activated');
  72. }
  73. }, 600);
  74. });
  75. // TIMER
  76. if($('.movement.left').length){
  77. VE.helpers.refresh_timer.right = $('.movement.right');
  78. VE.helpers.refresh_timer.left = $('.movement.left');
  79. VE.helpers.refresh_timer.start();
  80. $('.pause').click(function(){
  81. VE.helpers.refresh_timer.stop();
  82. $('.pause').addClass('u-hidden');
  83. $('.play').removeClass('u-hidden');
  84. $('.refresh-timer').addClass('paused');
  85. });
  86. $('.play').click(function(){
  87. VE.helpers.refresh_timer.start();
  88. $('.pause').removeClass('u-hidden');
  89. $('.play').addClass('u-hidden');
  90. $('.refresh-timer').removeClass('paused');
  91. });
  92. }
  93. // SORTING
  94. $('#vstobjects input, #vstobjects select, #vstobjects textarea').change(function(){VE.tmp.form_changed=1});
  95. $('.sort-order span').click(function(){
  96. $('.context-menu.sort-order').toggle();
  97. if($(this).hasClass('active'))
  98. return;
  99. $('.sort-order span').removeClass('active');
  100. $(this).addClass('active');
  101. VE.tmp.sort_par = $(this).parent('li').attr('entity');
  102. VE.tmp.sort_as_int = $(this).parent('li').attr('sort_as_int');
  103. VE.tmp.sort_direction = $(this).hasClass('up')*1 || -1;
  104. $('.l-sort .sort-by b').html($(this).parent('li').find('.name').html());
  105. $('.l-sort .sort-by i').removeClass('fa-arrow-up-a-z fa-arrow-down-a-z');
  106. $(this).hasClass('up') ? $('.l-sort .sort-by i').addClass('fa-arrow-up-a-z') : $('.l-sort .sort-by i').addClass('fa-arrow-down-a-z');
  107. $('.units .l-unit').sort(function (a, b) {
  108. if(VE.tmp.sort_as_int)
  109. return parseInt($(a).attr(VE.tmp.sort_par)) >= parseInt($(b).attr(VE.tmp.sort_par)) ? VE.tmp.sort_direction : VE.tmp.sort_direction * -1;
  110. else
  111. return $(a).attr(VE.tmp.sort_par) <= $(b).attr(VE.tmp.sort_par) ? VE.tmp.sort_direction : VE.tmp.sort_direction * -1;
  112. }).appendTo(".l-center.units");
  113. });
  114. $('#objects').submit( function (e){
  115. if(!e.originalEvent){
  116. return;
  117. }
  118. e.preventDefault();
  119. $('.ch-toggle').each( function (){
  120. if($(this).prop('checked')){
  121. key=this.name;
  122. div=$('<input type="hidden" name="'+key+'" value="'+this.value+'">');
  123. $('#objects').append(div);
  124. }
  125. });
  126. $('#objects').submit();
  127. return false;
  128. });
  129. // Shortcuts
  130. shortcut.add("Ctrl+Enter", function(){
  131. $('form#vstobjects').submit();
  132. }, {
  133. 'type': 'keydown',
  134. 'propagate': false,
  135. 'disable_in_input': false,
  136. 'target': document
  137. }
  138. );
  139. shortcut.add("Ctrl+Backspace", function(){
  140. var redirect = $('a.button#btn-back').attr('href')
  141. if(VE.tmp.form_changed && redirect){
  142. VE.helpers.createConfirmationDialog($('.js-confirm-dialog-redirect'), '', redirect);
  143. } else if($('form#vstobjects .button.cancel')[0]){
  144. location.href=$('form#vstobjects input.cancel').attr('onclick').replace("location.href='", "").replace("'","");
  145. } else if(redirect){
  146. location.href = redirect;
  147. }
  148. }, {
  149. 'type': 'keydown',
  150. 'propagate': false,
  151. 'disable_in_input': false,
  152. 'target': document
  153. }
  154. );
  155. shortcut.add("f", function(){
  156. $('.js-search-input').addClass('activated').focus();
  157. }, {
  158. 'type': 'keydown',
  159. 'propagate': false,
  160. 'disable_in_input': true,
  161. 'target': document
  162. }
  163. );
  164. $(window).on('keypress', function(evt) {
  165. var tag = evt.target.tagName.toLowerCase();
  166. if (evt.charCode == 97 && tag != 'input' && tag != 'textarea' && tag != 'selectbox') {
  167. evt.preventDefault();
  168. if (!evt.ctrlKey && !evt.shiftKey) {
  169. //if ($('.l-sort__create-btn')[0]) {
  170. if ($('.button#btn-create').length) {
  171. location.href=$('.button#btn-create').attr('href');
  172. }
  173. }
  174. else {
  175. if ($('.l-unit .ch-toggle:eq(0)').prop('checked')) {
  176. $('.l-unit').removeClass('selected');
  177. $('.l-unit .ch-toggle').prop('checked', false);
  178. }
  179. else {
  180. $('.l-unit').addClass('selected');
  181. $('.l-unit .ch-toggle').prop('checked', true);
  182. }
  183. }
  184. }
  185. });
  186. shortcut.add("1", function(){
  187. var target = $('.main-menu .main-menu-item:nth-of-type(1) a')
  188. if(target.length != 1){
  189. return;
  190. }
  191. if(VE.tmp.form_changed){
  192. VE.helpers.createConfirmationDialog($('.js-confirm-dialog-redirect'), '', target.attr('href'));
  193. } else {
  194. location.href=target.attr('href');
  195. }
  196. }, {
  197. 'type': 'keydown',
  198. 'propagate': false,
  199. 'disable_in_input': true,
  200. 'target': document
  201. }
  202. );
  203. shortcut.add("2", function(){
  204. var target = $('.main-menu .main-menu-item:nth-of-type(2) a')
  205. if(target.length != 1){
  206. return;
  207. }
  208. if(VE.tmp.form_changed){
  209. VE.helpers.createConfirmationDialog($('.js-confirm-dialog-redirect'), '', target.attr('href'));
  210. } else {
  211. location.href=target.attr('href');
  212. }
  213. }, {
  214. 'type': 'keydown',
  215. 'propagate': false,
  216. 'disable_in_input': true,
  217. 'target': document
  218. }
  219. );
  220. shortcut.add("3", function(){
  221. var target = $('.main-menu .main-menu-item:nth-of-type(3) a')
  222. if(target.length != 1){
  223. return;
  224. }
  225. if(VE.tmp.form_changed){
  226. VE.helpers.createConfirmationDialog($('.js-confirm-dialog-redirect'), '', target.attr('href'));
  227. } else {
  228. location.href=target.attr('href');
  229. }
  230. }, {
  231. 'type': 'keydown',
  232. 'propagate': false,
  233. 'disable_in_input': true,
  234. 'target': document
  235. }
  236. );
  237. shortcut.add("4", function(){
  238. var target = $('.main-menu .main-menu-item:nth-of-type(4) a')
  239. if(target.length != 1){
  240. return;
  241. }
  242. if(VE.tmp.form_changed){
  243. VE.helpers.createConfirmationDialog($('.js-confirm-dialog-redirect'), '', target.attr('href'));
  244. } else {
  245. location.href=target.attr('href');
  246. }
  247. }, {
  248. 'type': 'keydown',
  249. 'propagate': false,
  250. 'disable_in_input': true,
  251. 'target': document
  252. }
  253. );
  254. shortcut.add("5", function(){
  255. var target = $('.main-menu .main-menu-item:nth-of-type(5) a')
  256. if(target.length != 1){
  257. return;
  258. }
  259. if(VE.tmp.form_changed){
  260. VE.helpers.createConfirmationDialog($('.js-confirm-dialog-redirect'), '', target.attr('href'));
  261. } else {
  262. location.href=target.attr('href');
  263. }
  264. }, {
  265. 'type': 'keydown',
  266. 'propagate': false,
  267. 'disable_in_input': true,
  268. 'target': document
  269. }
  270. );
  271. shortcut.add("6", function(){
  272. var target = $('.main-menu .main-menu-item:nth-of-type(6) a')
  273. if(target.length != 1){
  274. return;
  275. }
  276. if(VE.tmp.form_changed){
  277. VE.helpers.createConfirmationDialog($('.js-confirm-dialog-redirect'), '', target.attr('href'));
  278. } else {
  279. location.href=target.attr('href');
  280. }
  281. }, {
  282. 'type': 'keydown',
  283. 'propagate': false,
  284. 'disable_in_input': true,
  285. 'target': document
  286. }
  287. );
  288. shortcut.add("7", function(){
  289. var target = $('.main-menu .main-menu-item:nth-of-type(7) a')
  290. if(target.length != 1){
  291. return;
  292. }
  293. if(VE.tmp.form_changed){
  294. VE.helpers.createConfirmationDialog($('.js-confirm-dialog-redirect'), '', target.attr('href'));
  295. } else {
  296. location.href=target.attr('href');
  297. }
  298. }, {
  299. 'type': 'keydown',
  300. 'propagate': false,
  301. 'disable_in_input': true,
  302. 'target': document
  303. }
  304. );
  305. shortcut.add("h", function(){
  306. var shortcutsDialog = document.querySelector('.shortcuts');
  307. if (shortcutsDialog.open) {
  308. shortcutsDialog.close();
  309. } else {
  310. shortcutsDialog.showModal();
  311. }
  312. }, {
  313. 'type': 'keydown',
  314. 'propagate': false,
  315. 'disable_in_input': true,
  316. 'target': document
  317. }
  318. );
  319. shortcut.add("Esc", function(){
  320. var shortcutsDialog = document.querySelector('.shortcuts');
  321. if (shortcutsDialog.open) {
  322. shortcutsDialog.close();
  323. }
  324. $('input, checkbox, textarea, select').blur();
  325. }, {
  326. 'type': 'keydown',
  327. 'propagate': false,
  328. 'disable_in_input': false,
  329. 'target': document
  330. }
  331. );
  332. shortcut.add("Left", function(){
  333. VE.navigation.move_focus_left();
  334. }, {
  335. 'type': 'keydown',
  336. 'propagate': false,
  337. 'disable_in_input': true,
  338. 'target': document
  339. }
  340. );
  341. shortcut.add("Right", function(){
  342. VE.navigation.move_focus_right();
  343. }, {
  344. 'type': 'keydown',
  345. 'propagate': false,
  346. 'disable_in_input': true,
  347. 'target': document
  348. }
  349. );
  350. shortcut.add("down", function(){
  351. VE.navigation.move_focus_down();
  352. }, {
  353. 'type': 'keydown',
  354. 'propagate': false,
  355. 'disable_in_input': true,
  356. 'target': document
  357. }
  358. );
  359. shortcut.add("up", function(){
  360. VE.navigation.move_focus_up();
  361. }, {
  362. 'type': 'keydown',
  363. 'propagate': false,
  364. 'disable_in_input': true,
  365. 'target': document
  366. }
  367. );
  368. shortcut.add("l", function(){
  369. var elm = $('.units.active .l-unit.focus .shortcut-l');
  370. if(elm.length){
  371. VE.navigation.shortcut(elm);
  372. }
  373. }, {
  374. 'type': 'keydown',
  375. 'propagate': false,
  376. 'disable_in_input': true,
  377. 'target': document
  378. }
  379. );
  380. shortcut.add("s", function(){
  381. var elm = $('.units.active .l-unit.focus .shortcut-s');
  382. if(elm.length){
  383. VE.navigation.shortcut(elm);
  384. }
  385. }, {
  386. 'type': 'keydown',
  387. 'propagate': false,
  388. 'disable_in_input': true,
  389. 'target': document
  390. }
  391. );
  392. shortcut.add("w", function(){
  393. var elm = $('.units.active .l-unit.focus .shortcut-w');
  394. if(elm.length){
  395. VE.navigation.shortcut(elm);
  396. }
  397. }, {
  398. 'type': 'keydown',
  399. 'propagate': false,
  400. 'disable_in_input': true,
  401. 'target': document
  402. }
  403. );
  404. shortcut.add("d", function(){
  405. var elm = $('.units.active .l-unit.focus .shortcut-d');
  406. if(elm.length){
  407. VE.navigation.shortcut(elm);
  408. }
  409. }, {
  410. 'type': 'keydown',
  411. 'propagate': false,
  412. 'disable_in_input': true,
  413. 'target': document
  414. }
  415. );
  416. shortcut.add("r", function(){
  417. var elm = $('.units.active .l-unit.focus .shortcut-r');
  418. if(elm.length){
  419. VE.navigation.shortcut(elm);
  420. }
  421. }, {
  422. 'type': 'keydown',
  423. 'propagate': false,
  424. 'disable_in_input': true,
  425. 'target': document
  426. }
  427. );
  428. shortcut.add("n", function(){
  429. var elm = $('.units.active .l-unit.focus .shortcut-n');
  430. if(elm.length){
  431. VE.navigation.shortcut(elm);
  432. }
  433. }, {
  434. 'type': 'keydown',
  435. 'propagate': false,
  436. 'disable_in_input': true,
  437. 'target': document
  438. }
  439. );
  440. shortcut.add("u", function(){
  441. var elm = $('.units.active .l-unit.focus .shortcut-u');
  442. if(elm.length){
  443. VE.navigation.shortcut(elm);
  444. }
  445. }, {
  446. 'type': 'keydown',
  447. 'propagate': false,
  448. 'disable_in_input': true,
  449. 'target': document
  450. }
  451. );
  452. shortcut.add("Delete", function(){
  453. var elm = $('.units.active .l-unit.focus .shortcut-delete');
  454. if(elm.length){
  455. VE.navigation.shortcut(elm);
  456. }
  457. }, {
  458. 'type': 'keydown',
  459. 'propagate': false,
  460. 'disable_in_input': true,
  461. 'target': document
  462. }
  463. );
  464. shortcut.add("Enter", function(evt){
  465. if (evt.target.tagName == 'INPUT' && evt.target.form.id == 'vstobjects'){
  466. $('form#vstobjects').submit();
  467. }
  468. if(VE.tmp.form_changed){
  469. if(!$('.ui-dialog').is(':visible')){
  470. VE.helpers.createConfirmationDialog($('.js-confirm-dialog-redirect')[0], '', $(VE.navigation.state.menu_selector + '.focus a').attr('href'));
  471. } else { // if dialog is opened - submitting confirm box by "enter" shortcut
  472. $('.ui-dialog button.submit').click();
  473. }
  474. } else {
  475. if(!$('.ui-dialog').is(':visible')){
  476. var elm = $('.units.active .l-unit.focus .shortcut-enter');
  477. if(elm.length){
  478. VE.navigation.shortcut(elm);
  479. } else {
  480. VE.navigation.enter_focused();
  481. }
  482. } else { // if dialog is opened - submitting confirm box by "enter" shortcut
  483. $('.ui-dialog button.submit').click();
  484. }
  485. }
  486. }, {
  487. 'type': 'keydown',
  488. 'propagate': true,
  489. 'disable_in_input': false,
  490. 'target': document
  491. }
  492. );
  493. document.querySelector('.shortcuts-close').addEventListener('click', function(){
  494. var shortcutsDialog = document.querySelector('.shortcuts');
  495. if (shortcutsDialog.open) {
  496. shortcutsDialog.close();
  497. }
  498. });
  499. document.querySelector('.to-shortcuts').addEventListener('click', function() {
  500. event.preventDefault();
  501. var shortcutsDialog = document.querySelector('.shortcuts');
  502. if (shortcutsDialog.open) {
  503. shortcutsDialog.close();
  504. } else {
  505. shortcutsDialog.showModal();
  506. }
  507. });
  508. $(document).click(function(evt){
  509. //close notification popup
  510. if(!$(evt.target).hasClass('l-profile__notifications') && $(evt.target).parents('ul.notification-container').length == 0){
  511. $('.notification-container').addClass('u-hidden');
  512. $('.l-profile__notifications').removeClass('active');
  513. }
  514. });
  515. // focusing on the first input at form
  516. if( location.href.indexOf('lead=') == -1 && !$('.ui-dialog').is(':visible') ){
  517. $('#vstobjects .form-control:not([disabled]), #vstobjects .form-select:not([disabled])').first().focus();
  518. }
  519. $('.l-profile__notifications').click(function(evt){
  520. evt.preventDefault();
  521. if(!$('.l-profile__notifications').hasClass('active')){
  522. VE.notifications.get_list();
  523. $('.l-profile__notifications').addClass('active');
  524. } else {
  525. $('.notification-container').addClass('u-hidden');
  526. $('.l-profile__notifications').removeClass('active');
  527. }
  528. });
  529. VE.navigation.init();
  530. $('.button').attr('title','ctrl+Enter');
  531. $('.button.cancel').attr('title','ctrl+Backspace');
  532. VE.core.register();
  533. if (location.href.search(/list/) != -1) {
  534. var shift_select_ref = $('body').finderSelect({
  535. children: '.l-unit',
  536. 'onFinish': function(evt) {
  537. if ($('.l-content').find('.l-unit.selected').length == $('.l-content').find('.l-unit').length) {
  538. $('.toggle-all').addClass('clicked-on');
  539. }
  540. },
  541. 'toggleAllHook': function() {
  542. if ($('.l-unit').length == $('.ch-toggle:checked').length) {
  543. $('.l-unit.selected').removeClass('selected');
  544. $('.ch-toggle').prop('checked', false);
  545. $('#toggle-all').prop('checked', false);
  546. }
  547. else {
  548. $('.ch-toggle').prop('checked', true);
  549. $('#toggle-all').prop('checked', true);
  550. }
  551. }
  552. });
  553. $('table').on('mousedown', 'td', function(e) {
  554. if (e.ctrlKey) {
  555. e.preventDefault();
  556. }
  557. });
  558. }
  559. //
  560. $('form#objects').on('submit', function(evt) {
  561. $('.l-unit').find('.ch-toggle').prop('checked', false);
  562. $('.l-unit.selected').find('.ch-toggle').prop('checked', true);
  563. });
  564. // todo: maybe give the save button id?
  565. $(".button[data-id=vstobjects][data-action=submit]").on('click', function(ev){
  566. let loadingAnimationEle = document.createElement("div");
  567. loadingAnimationEle.className = "spinner";
  568. loadingAnimationEle.innerHTML = '<div class="spinner-inner"></div><div class="spinner-mask"></div> <div class="spinner-mask-two"></div>';
  569. // improve alignment
  570. var buttonStrip = this.closest(".l-unit-toolbar__buttonstrip");
  571. // this both gives an indication that we've clicked and is loading, also prevents double-clicking/clicking-on-something-else while loading.
  572. $(".button[data-id=vstobjects][data-action=submit]").replaceWith(loadingAnimationEle);
  573. $(".button").replaceWith('');
  574. // workaround a render bug on Safari (loading icon doesn't render without this)
  575. ev.preventDefault();
  576. $('#vstobjects').submit();
  577. });
  578. });
  579. /**
  580. * generates a random string
  581. * using a cryptographically secure rng,
  582. * and ensuring it contains at least 1 lowercase, 1 uppercase, and 1 number.
  583. *
  584. * @param int length
  585. * @throws Error if length is too small to create a "sufficiently secure" string
  586. * @returns string
  587. */
  588. function randomString2(length = 16) {
  589. var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
  590. var secure_rng = function (min, max) {
  591. if (min < 0 || min > 0xffff) {
  592. throw new Error(
  593. "minimum supported number is 0, this generator can only make numbers between 0-65535 inclusive."
  594. );
  595. }
  596. if (max > 0xffff || max < 0) {
  597. throw new Error(
  598. "max supported number is 65535, this generator can only make numbers between 0-65535 inclusive."
  599. );
  600. }
  601. if (min > max) {
  602. throw new Error("dude min>max wtf");
  603. }
  604. // micro-optimization
  605. let randArr = max > 255 ? new Uint16Array(1) : new Uint8Array(1);
  606. let ret;
  607. let attempts = 0;
  608. for (;;) {
  609. crypto.getRandomValues(randArr);
  610. ret = randArr[0];
  611. if (ret >= min && ret <= max) {
  612. return ret;
  613. }
  614. ++attempts;
  615. if (attempts > 1000000) {
  616. // should basically never happen with max 0xFFFF/Uint16Array.
  617. throw new Error("tried a million times, something is wrong");
  618. }
  619. }
  620. };
  621. let attempts = 0;
  622. let minimumStrengthRegex = new RegExp(
  623. /^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*\d)[a-zA-Z\d]{8,}$/
  624. );
  625. let randmax = chars.length - 1;
  626. for (;;) {
  627. let ret = "";
  628. for (let i = 0; i < length; ++i) {
  629. ret += chars[secure_rng(0, randmax)];
  630. }
  631. if (minimumStrengthRegex.test(ret)) {
  632. return ret;
  633. }
  634. ++attempts;
  635. if (attempts > 1000000) {
  636. throw new Error("tried a million times, something is wrong");
  637. }
  638. }
  639. }