init.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  1. $(document).ready(function(){
  2. if($('.body-login')[0]){
  3. $('input').first().focus();
  4. }
  5. $(".submenu-select-dropdown").each(function(){
  6. $(this).wrap("<span class='submenu-select-wrapper'></span>");
  7. $(this).after("<span class='holder'></span>");
  8. });
  9. $(".submenu-select-dropdown").change(function(){
  10. var selectedOption = $(this).find(":selected").text();
  11. $(this).next(".holder").text(selectedOption);
  12. }).trigger('change');
  13. $('.to-top').on('click', function(evt) {
  14. evt.preventDefault();
  15. $("html, body").animate({ scrollTop: 0 }, "normal");
  16. });
  17. $('.button').on('click',function(evt){
  18. var action = $(this).data('action');
  19. var id = $(this).data('id');
  20. if(action=='submit' && document.getElementById(id)){
  21. evt.preventDefault();
  22. $(document.getElementById(id)).submit();
  23. }
  24. });
  25. var isMobile = false; //initiate as false
  26. // device detection
  27. /* eslint-disable no-useless-escape */
  28. 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)
  29. || /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))){
  30. isMobile = true;
  31. $('body').addClass('mobile');
  32. }
  33. /* eslint-enable no-useless-escape */
  34. $(window).scroll(function(){set_sticky_class()});
  35. $('.l-sort-toolbar .sort-by').click(function(){
  36. $('.context-menu.sort-order').toggle().css({left: $(this).parent().parent().parent().position().left - 0});
  37. });
  38. // CREATE BUTTON
  39. $('.l-sort__create-btn').hover(function(){
  40. $(".l-sort__create-btn").append("<div id='add-icon'></div>");
  41. $(".l-sort__create-btn").append("<div id='tooltip'>"+$('.l-sort__create-btn').attr('title').replace(' ','&nbsp;')+"</div>");
  42. }, function(){
  43. $("#add-icon").remove();
  44. $("#tooltip").remove();
  45. });
  46. // SEARCH BOX
  47. $('.l-sort-toolbar__search, .l-sort-toolbar__search-box .search-input').hover(function(){
  48. clearTimeout(VE.tmp.search_display_interval);
  49. clearTimeout(VE.tmp.search_hover_interval);
  50. VE.tmp.search_display_interval = setTimeout(function(){$('.search-input').addClass('activated');}, 150);
  51. }, function(){
  52. clearTimeout(VE.tmp.search_display_interval);
  53. clearTimeout(VE.tmp.search_hover_interval);
  54. VE.tmp.search_hover_interval = setTimeout(function(){
  55. if(!VE.tmp.search_activated && !$(".search-input").val().length){
  56. $(".search-input").removeClass('activated');
  57. }
  58. }, 600);
  59. });
  60. $('.search-input').focus(function(){
  61. VE.tmp.search_activated = 1;
  62. clearTimeout(VE.tmp.search_hover_interval);
  63. });
  64. $('.search-input').blur(function(){
  65. VE.tmp.search_activated = 0;
  66. clearTimeout(VE.tmp.search_hover_interval);
  67. VE.tmp.search_hover_interval = setTimeout(function(){
  68. if(!$(".search-input").val().length){
  69. $(".search-input").removeClass('activated');
  70. }
  71. }, 600);
  72. });
  73. // TIMER
  74. if($('.movement.left').length){
  75. VE.helpers.refresh_timer.right = $('.movement.right');
  76. VE.helpers.refresh_timer.left = $('.movement.left');
  77. VE.helpers.refresh_timer.start();
  78. $('.pause').click(function(){
  79. VE.helpers.refresh_timer.stop();
  80. $('.pause').addClass('u-hidden');
  81. $('.play').removeClass('u-hidden');
  82. $('.refresh-timer').addClass('paused');
  83. });
  84. $('.play').click(function(){
  85. VE.helpers.refresh_timer.start();
  86. $('.pause').removeClass('u-hidden');
  87. $('.play').addClass('u-hidden');
  88. $('.refresh-timer').removeClass('paused');
  89. });
  90. }
  91. // SORTING
  92. $('#vstobjects input, #vstobjects select, #vstobjects textarea').change(function(){VE.tmp.form_changed=1});
  93. $('.sort-order span').click(function(){
  94. $('.context-menu.sort-order').toggle();
  95. if($(this).hasClass('active'))
  96. return;
  97. $('.sort-order span').removeClass('active');
  98. $(this).addClass('active');
  99. VE.tmp.sort_par = $(this).parent('li').attr('entity');
  100. VE.tmp.sort_as_int = $(this).parent('li').attr('sort_as_int');
  101. VE.tmp.sort_direction = $(this).hasClass('up')*1 || -1;
  102. $('.l-sort .sort-by span b').html($(this).parent('li').find('.name').html());
  103. $('.l-sort .sort-by i').removeClass('fa-sort-alpha-up fa-sort-alpha-down');
  104. $(this).hasClass('up') ? $('.l-sort .sort-by i').addClass('fa-sort-alpha-up') : $('.l-sort .sort-by i').addClass('fa-sort-alpha-down');
  105. $('.units .l-unit').sort(function (a, b) {
  106. if(VE.tmp.sort_as_int)
  107. return parseInt($(a).attr(VE.tmp.sort_par)) >= parseInt($(b).attr(VE.tmp.sort_par)) ? VE.tmp.sort_direction : VE.tmp.sort_direction * -1;
  108. else
  109. return $(a).attr(VE.tmp.sort_par) <= $(b).attr(VE.tmp.sort_par) ? VE.tmp.sort_direction : VE.tmp.sort_direction * -1;
  110. }).appendTo(".l-center.units");
  111. });
  112. $('#objects').submit( function (e){
  113. if(!e.originalEvent){
  114. return;
  115. }
  116. e.preventDefault();
  117. $('.ch-toggle').each( function (){
  118. if($(this).prop('checked')){
  119. key=this.name;
  120. div=$('<input type="hidden" name="'+key+'" value="'+this.value+'">');
  121. $('#objects').append(div);
  122. }
  123. });
  124. $('#objects').submit();
  125. return false;
  126. });
  127. // Shortcuts
  128. shortcut.add("Ctrl+Enter", function(){
  129. $('form#vstobjects').submit();
  130. }, {
  131. 'type': 'keydown',
  132. 'propagate': false,
  133. 'disable_in_input': false,
  134. 'target': document
  135. }
  136. );
  137. shortcut.add("Ctrl+Backspace", function(){
  138. var redirect = $('a.button#btn-back').attr('href')
  139. if(VE.tmp.form_changed && redirect){
  140. VE.helpers.createConfirmationDialog($('.js-confirm-dialog-redirect'), '', redirect);
  141. } else if($('form#vstobjects .button.cancel')[0]){
  142. location.href=$('form#vstobjects input.cancel').attr('onclick').replace("location.href='", "").replace("'","");
  143. } else if(redirect){
  144. location.href = redirect;
  145. }
  146. }, {
  147. 'type': 'keydown',
  148. 'propagate': false,
  149. 'disable_in_input': false,
  150. 'target': document
  151. }
  152. );
  153. shortcut.add("f", function(){
  154. $('.search-input').addClass('activated').focus();
  155. }, {
  156. 'type': 'keydown',
  157. 'propagate': false,
  158. 'disable_in_input': true,
  159. 'target': document
  160. }
  161. );
  162. $(window).on('keypress', function(evt) {
  163. var tag = evt.target.tagName.toLowerCase();
  164. if (evt.charCode == 97 && tag != 'input' && tag != 'textarea' && tag != 'selectbox') {
  165. evt.preventDefault();
  166. if (!evt.ctrlKey && !evt.shiftKey) {
  167. //if ($('.l-sort__create-btn')[0]) {
  168. if ($('.button#btn-create').length) {
  169. location.href=$('.button#btn-create').attr('href');
  170. }
  171. }
  172. else {
  173. if ($('.l-unit .ch-toggle:eq(0)').prop('checked')) {
  174. $('.l-unit').removeClass('selected');
  175. $('.l-unit .ch-toggle').prop('checked', false);
  176. }
  177. else {
  178. $('.l-unit').addClass('selected');
  179. $('.l-unit .ch-toggle').prop('checked', true);
  180. }
  181. }
  182. }
  183. });
  184. shortcut.add("1", function(){
  185. var target = $('.l-stat .l-stat__col:nth-of-type(1) a')
  186. if(target.length != 1){
  187. return;
  188. }
  189. if(VE.tmp.form_changed){
  190. VE.helpers.createConfirmationDialog($('.js-confirm-dialog-redirect'), '', target.attr('href'));
  191. } else {
  192. location.href=target.attr('href');
  193. }
  194. }, {
  195. 'type': 'keydown',
  196. 'propagate': false,
  197. 'disable_in_input': true,
  198. 'target': document
  199. }
  200. );
  201. shortcut.add("2", function(){
  202. var target = $('.l-stat .l-stat__col:nth-of-type(2) a')
  203. if(target.length != 1){
  204. return;
  205. }
  206. if(VE.tmp.form_changed){
  207. VE.helpers.createConfirmationDialog($('.js-confirm-dialog-redirect'), '', target.attr('href'));
  208. } else {
  209. location.href=target.attr('href');
  210. }
  211. }, {
  212. 'type': 'keydown',
  213. 'propagate': false,
  214. 'disable_in_input': true,
  215. 'target': document
  216. }
  217. );
  218. shortcut.add("3", function(){
  219. var target = $('.l-stat .l-stat__col:nth-of-type(3) a')
  220. if(target.length != 1){
  221. return;
  222. }
  223. if(VE.tmp.form_changed){
  224. VE.helpers.createConfirmationDialog($('.js-confirm-dialog-redirect'), '', target.attr('href'));
  225. } else {
  226. location.href=target.attr('href');
  227. }
  228. }, {
  229. 'type': 'keydown',
  230. 'propagate': false,
  231. 'disable_in_input': true,
  232. 'target': document
  233. }
  234. );
  235. shortcut.add("4", function(){
  236. var target = $('.l-stat .l-stat__col:nth-of-type(4) a')
  237. if(target.length != 1){
  238. return;
  239. }
  240. if(VE.tmp.form_changed){
  241. VE.helpers.createConfirmationDialog($('.js-confirm-dialog-redirect'), '', target.attr('href'));
  242. } else {
  243. location.href=target.attr('href');
  244. }
  245. }, {
  246. 'type': 'keydown',
  247. 'propagate': false,
  248. 'disable_in_input': true,
  249. 'target': document
  250. }
  251. );
  252. shortcut.add("5", function(){
  253. var target = $('.l-stat .l-stat__col:nth-of-type(5) a')
  254. if(target.length != 1){
  255. return;
  256. }
  257. if(VE.tmp.form_changed){
  258. VE.helpers.createConfirmationDialog($('.js-confirm-dialog-redirect'), '', target.attr('href'));
  259. } else {
  260. location.href=target.attr('href');
  261. }
  262. }, {
  263. 'type': 'keydown',
  264. 'propagate': false,
  265. 'disable_in_input': true,
  266. 'target': document
  267. }
  268. );
  269. shortcut.add("6", function(){
  270. var target = $('.l-stat .l-stat__col:nth-of-type(6) a')
  271. if(target.length != 1){
  272. return;
  273. }
  274. if(VE.tmp.form_changed){
  275. VE.helpers.createConfirmationDialog($('.js-confirm-dialog-redirect'), '', target.attr('href'));
  276. } else {
  277. location.href=target.attr('href');
  278. }
  279. }, {
  280. 'type': 'keydown',
  281. 'propagate': false,
  282. 'disable_in_input': true,
  283. 'target': document
  284. }
  285. );
  286. shortcut.add("7", function(){
  287. var target = $('.l-stat .l-stat__col:nth-of-type(7) a')
  288. if(target.length != 1){
  289. return;
  290. }
  291. if(VE.tmp.form_changed){
  292. VE.helpers.createConfirmationDialog($('.js-confirm-dialog-redirect'), '', target.attr('href'));
  293. } else {
  294. location.href=target.attr('href');
  295. }
  296. }, {
  297. 'type': 'keydown',
  298. 'propagate': false,
  299. 'disable_in_input': true,
  300. 'target': document
  301. }
  302. );
  303. shortcut.add("h", function(){
  304. var shortcutsDialog = document.querySelector('.shortcuts');
  305. if (shortcutsDialog.open) {
  306. shortcutsDialog.close();
  307. } else {
  308. shortcutsDialog.showModal();
  309. }
  310. }, {
  311. 'type': 'keydown',
  312. 'propagate': false,
  313. 'disable_in_input': true,
  314. 'target': document
  315. }
  316. );
  317. shortcut.add("Esc", function(){
  318. var shortcutsDialog = document.querySelector('.shortcuts');
  319. if (shortcutsDialog.open) {
  320. shortcutsDialog.close();
  321. }
  322. $('input, checkbox, textarea, select').blur();
  323. }, {
  324. 'type': 'keydown',
  325. 'propagate': false,
  326. 'disable_in_input': false,
  327. 'target': document
  328. }
  329. );
  330. shortcut.add("Left", function(){
  331. VE.navigation.move_focus_left();
  332. }, {
  333. 'type': 'keydown',
  334. 'propagate': false,
  335. 'disable_in_input': true,
  336. 'target': document
  337. }
  338. );
  339. shortcut.add("Right", function(){
  340. VE.navigation.move_focus_right();
  341. }, {
  342. 'type': 'keydown',
  343. 'propagate': false,
  344. 'disable_in_input': true,
  345. 'target': document
  346. }
  347. );
  348. shortcut.add("down", function(){
  349. VE.navigation.move_focus_down();
  350. }, {
  351. 'type': 'keydown',
  352. 'propagate': false,
  353. 'disable_in_input': true,
  354. 'target': document
  355. }
  356. );
  357. shortcut.add("up", function(){
  358. VE.navigation.move_focus_up();
  359. }, {
  360. 'type': 'keydown',
  361. 'propagate': false,
  362. 'disable_in_input': true,
  363. 'target': document
  364. }
  365. );
  366. shortcut.add("l", function(){
  367. var elm = $('.units.active .l-unit.focus .shortcut-l');
  368. if(elm.length){
  369. VE.navigation.shortcut(elm);
  370. }
  371. }, {
  372. 'type': 'keydown',
  373. 'propagate': false,
  374. 'disable_in_input': true,
  375. 'target': document
  376. }
  377. );
  378. shortcut.add("s", function(){
  379. var elm = $('.units.active .l-unit.focus .shortcut-s');
  380. if(elm.length){
  381. VE.navigation.shortcut(elm);
  382. }
  383. }, {
  384. 'type': 'keydown',
  385. 'propagate': false,
  386. 'disable_in_input': true,
  387. 'target': document
  388. }
  389. );
  390. shortcut.add("w", function(){
  391. var elm = $('.units.active .l-unit.focus .shortcut-w');
  392. if(elm.length){
  393. VE.navigation.shortcut(elm);
  394. }
  395. }, {
  396. 'type': 'keydown',
  397. 'propagate': false,
  398. 'disable_in_input': true,
  399. 'target': document
  400. }
  401. );
  402. shortcut.add("d", function(){
  403. var elm = $('.units.active .l-unit.focus .shortcut-d');
  404. if(elm.length){
  405. VE.navigation.shortcut(elm);
  406. }
  407. }, {
  408. 'type': 'keydown',
  409. 'propagate': false,
  410. 'disable_in_input': true,
  411. 'target': document
  412. }
  413. );
  414. shortcut.add("r", function(){
  415. var elm = $('.units.active .l-unit.focus .shortcut-r');
  416. if(elm.length){
  417. VE.navigation.shortcut(elm);
  418. }
  419. }, {
  420. 'type': 'keydown',
  421. 'propagate': false,
  422. 'disable_in_input': true,
  423. 'target': document
  424. }
  425. );
  426. shortcut.add("n", function(){
  427. var elm = $('.units.active .l-unit.focus .shortcut-n');
  428. if(elm.length){
  429. VE.navigation.shortcut(elm);
  430. }
  431. }, {
  432. 'type': 'keydown',
  433. 'propagate': false,
  434. 'disable_in_input': true,
  435. 'target': document
  436. }
  437. );
  438. shortcut.add("u", function(){
  439. var elm = $('.units.active .l-unit.focus .shortcut-u');
  440. if(elm.length){
  441. VE.navigation.shortcut(elm);
  442. }
  443. }, {
  444. 'type': 'keydown',
  445. 'propagate': false,
  446. 'disable_in_input': true,
  447. 'target': document
  448. }
  449. );
  450. shortcut.add("Delete", function(){
  451. var elm = $('.units.active .l-unit.focus .shortcut-delete');
  452. if(elm.length){
  453. VE.navigation.shortcut(elm);
  454. }
  455. }, {
  456. 'type': 'keydown',
  457. 'propagate': false,
  458. 'disable_in_input': true,
  459. 'target': document
  460. }
  461. );
  462. shortcut.add("Enter", function(evt){
  463. if (evt.target.tagName == 'INPUT' && evt.target.form.id == 'vstobjects'){
  464. $('form#vstobjects').submit();
  465. }
  466. if(VE.tmp.form_changed){
  467. if(!$('.ui-dialog').is(':visible')){
  468. VE.helpers.createConfirmationDialog($('.js-confirm-dialog-redirect')[0], '', $(VE.navigation.state.menu_selector + '.focus a').attr('href'));
  469. } else { // if dialog is opened - submitting confirm box by "enter" shortcut
  470. $('.ui-dialog button.submit').click();
  471. }
  472. } else {
  473. if(!$('.ui-dialog').is(':visible')){
  474. var elm = $('.units.active .l-unit.focus .shortcut-enter');
  475. if(elm.length){
  476. VE.navigation.shortcut(elm);
  477. } else {
  478. VE.navigation.enter_focused();
  479. }
  480. } else { // if dialog is opened - submitting confirm box by "enter" shortcut
  481. $('.ui-dialog button.submit').click();
  482. }
  483. }
  484. }, {
  485. 'type': 'keydown',
  486. 'propagate': true,
  487. 'disable_in_input': false,
  488. 'target': document
  489. }
  490. );
  491. document.querySelector('.shortcuts-close').addEventListener('click', function(){
  492. var shortcutsDialog = document.querySelector('.shortcuts');
  493. if (shortcutsDialog.open) {
  494. shortcutsDialog.close();
  495. }
  496. });
  497. document.querySelector('.to-shortcuts').addEventListener('click', function() {
  498. event.preventDefault();
  499. var shortcutsDialog = document.querySelector('.shortcuts');
  500. if (shortcutsDialog.open) {
  501. shortcutsDialog.close();
  502. } else {
  503. shortcutsDialog.showModal();
  504. }
  505. });
  506. $(document).click(function(evt){
  507. //close notification popup
  508. if(!$(evt.target).hasClass('l-profile__notifications') && $(evt.target).parents('ul.notification-container').length == 0){
  509. $('.notification-container').addClass('u-hidden');
  510. $('.l-profile__notifications').removeClass('active');
  511. }
  512. });
  513. // focusing on the first input at form
  514. if( location.href.indexOf('lead=') == -1 && !$('.ui-dialog').is(':visible') ){
  515. $('#vstobjects .form-control:not([disabled]), #vstobjects .form-select:not([disabled])').first().focus();
  516. }
  517. $('.l-profile__notifications').click(function(){
  518. if(!$('.l-profile__notifications').hasClass('active')){
  519. VE.notifications.get_list();
  520. $('.l-profile__notifications').addClass('active');
  521. left = $('.l-profile__notifications').offset().left - $('.notification-container').outerWidth() + 22;
  522. $('.notification-container').css({left: left+'px'});
  523. } else {
  524. $('.notification-container').addClass('u-hidden');
  525. $('.l-profile__notifications').removeClass('active');
  526. }
  527. });
  528. VE.navigation.init();
  529. $('.button').attr('title','ctrl+Enter');
  530. $('.button.cancel').attr('title','ctrl+Backspace');
  531. VE.core.register();
  532. if (location.href.search(/list/) != -1) {
  533. var shift_select_ref = $('body').finderSelect({
  534. children: '.l-unit',
  535. 'onFinish': function(evt) {
  536. if ($('.l-content').find('.l-unit.selected').length == $('.l-content').find('.l-unit').length) {
  537. $('.toggle-all').addClass('clicked-on');
  538. }
  539. },
  540. 'toggleAllHook': function() {
  541. if ($('.l-unit').length == $('.ch-toggle:checked').length) {
  542. $('.l-unit.selected').removeClass('selected');
  543. $('.ch-toggle').prop('checked', false);
  544. $('#toggle-all').prop('checked', false);
  545. }
  546. else {
  547. $('.ch-toggle').prop('checked', true);
  548. $('#toggle-all').prop('checked', true);
  549. }
  550. }
  551. });
  552. $('table').on('mousedown', 'td', function(e) {
  553. if (e.ctrlKey) {
  554. e.preventDefault();
  555. }
  556. });
  557. }
  558. //
  559. $('form#objects').on('submit', function(evt) {
  560. $('.l-unit').find('.ch-toggle').prop('checked', false);
  561. $('.l-unit.selected').find('.ch-toggle').prop('checked', true);
  562. });
  563. // todo: maybe give the save button id?
  564. $(".button[data-id=vstobjects][data-action=submit]").on('click', function(ev){
  565. let loadingAnimationEle = document.createElement("div");
  566. loadingAnimationEle.innerHTML = '<div class="timer-container" style="float:right;"><div class="timer-button spinner"><div class="spinner-inner"></div><div class="spinner-mask"></div> <div class="spinner-mask-two"></div></div></div>';
  567. // improve alignment
  568. var buttonStrip = this.closest(".l-unit-toolbar__buttonstrip");
  569. buttonStrip.style.marginTop = "8px";
  570. // this both gives an indication that we've clicked and is loading, also prevents double-clicking/clicking-on-something-else while loading.
  571. $(".button[data-id=vstobjects][data-action=submit]").replaceWith(loadingAnimationEle);
  572. $(".button").replaceWith('');
  573. // workaround a render bug on Safari (loading icon doesn't render without this)
  574. ev.preventDefault();
  575. $('#vstobjects').submit();
  576. });
  577. });
  578. /**
  579. * generates a random string
  580. * using a cryptographically secure rng,
  581. * and ensuring it contains at least 1 lowercase, 1 uppercase, and 1 number.
  582. *
  583. * @param int length
  584. * @throws Error if length is too small to create a "sufficiently secure" string
  585. * @returns string
  586. */
  587. function randomString2(length = 16) {
  588. var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
  589. var secure_rng = function (min, max) {
  590. if (min < 0 || min > 0xffff) {
  591. throw new Error(
  592. "minimum supported number is 0, this generator can only make numbers between 0-65535 inclusive."
  593. );
  594. }
  595. if (max > 0xffff || max < 0) {
  596. throw new Error(
  597. "max supported number is 65535, this generator can only make numbers between 0-65535 inclusive."
  598. );
  599. }
  600. if (min > max) {
  601. throw new Error("dude min>max wtf");
  602. }
  603. // micro-optimization
  604. let randArr = max > 255 ? new Uint16Array(1) : new Uint8Array(1);
  605. let ret;
  606. let attempts = 0;
  607. for (;;) {
  608. crypto.getRandomValues(randArr);
  609. ret = randArr[0];
  610. if (ret >= min && ret <= max) {
  611. return ret;
  612. }
  613. ++attempts;
  614. if (attempts > 1000000) {
  615. // should basically never happen with max 0xFFFF/Uint16Array.
  616. throw new Error("tried a million times, something is wrong");
  617. }
  618. }
  619. };
  620. let attempts = 0;
  621. let minimumStrengthRegex = new RegExp(
  622. /^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*\d)[a-zA-Z\d]{8,}$/
  623. );
  624. let randmax = chars.length - 1;
  625. for (;;) {
  626. let ret = "";
  627. for (let i = 0; i < length; ++i) {
  628. ret += chars[secure_rng(0, randmax)];
  629. }
  630. if (minimumStrengthRegex.test(ret)) {
  631. return ret;
  632. }
  633. ++attempts;
  634. if (attempts > 1000000) {
  635. throw new Error("tried a million times, something is wrong");
  636. }
  637. }
  638. }