init.js 29 KB

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