Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.13 KB | None | 0 0
  1. $(function () {
  2.  
  3. datePicker.translations();
  4. datePicker.init();
  5.  
  6. zipcodeMask.init();
  7.  
  8. mobileMenu.init();
  9.  
  10. sidebarDropdowns.init();
  11.  
  12. knowledgeBase.init('.allKnowledgeItems ');
  13. knowledgeBase.init('.highlightedKnowledgeItems ');
  14.  
  15. categoriesFAQDropdown.init();
  16.  
  17. printPage.init();
  18.  
  19. departmentSearch.init();
  20.  
  21. changeLoginDetailsChoice.init();
  22.  
  23. wysiwyg.init();
  24.  
  25.  
  26. /* THIS IS FOR TESTING ONLY
  27. ============================================================== */
  28. debug.menuOnLoad();
  29.  
  30. });
  31.  
  32. /* DatePicker Translations And Init
  33. ============================================================== */
  34. var datePicker = {
  35.  
  36. /* Translations */
  37. translations: function () {
  38. $.datepicker.regional['nl'] = {
  39. closeText: 'Sluiten',
  40. prevText: '←',
  41. nextText: '→',
  42. currentText: 'Vandaag',
  43. monthNames: ['januari', 'februari', 'maart', 'april', 'mei', 'juni',
  44. 'juli', 'augustus', 'september', 'oktober', 'november', 'december'],
  45. monthNamesShort: ['jan', 'feb', 'maa', 'apr', 'mei', 'jun',
  46. 'jul', 'aug', 'sep', 'okt', 'nov', 'dec'],
  47. dayNames: ['zondag', 'maandag', 'dinsdag', 'woensdag', 'donderdag', 'vrijdag', 'zaterdag'],
  48. dayNamesShort: ['zon', 'maa', 'din', 'woe', 'don', 'vri', 'zat'],
  49. dayNamesMin: ['zo', 'ma', 'di', 'wo', 'do', 'vr', 'za'],
  50. weekHeader: 'Wk',
  51. dateFormat: 'dd-mm-yy',
  52. firstDay: 1,
  53. isRTL: false,
  54. showMonthAfterYear: false,
  55. yearSuffix: ''
  56. };
  57. $.datepicker.setDefaults($.datepicker.regional['nl']);
  58. },
  59.  
  60. /* Init */
  61. init: function () {
  62. $('.datepicker').datepicker({
  63. changeMonth: true,
  64. changeYear: true,
  65. yearRange: '1920:+0'
  66. });
  67. }
  68. }
  69.  
  70. /* Zipcode input field mask init and auto uppercase
  71. ============================================================== */
  72. var zipcodeMask = {
  73. init: function() {
  74. $('#zipcode').mask('9999 aa');
  75. $('#zipcode').bind('blur', function () {
  76. $(this).val($(this).val().toUpperCase());
  77. });
  78. }
  79. }
  80.  
  81.  
  82. /* Mobile Menu and Mobile Sidebar Dropdown
  83. ============================================================== */
  84. var mobileMenu = {
  85.  
  86. /* Init
  87. ========== */
  88. init: function () {
  89. /* Open Menu */
  90. $('.showMenu .hamburger').on('click', function () {
  91. mobileMenu.show('menu');
  92. });
  93.  
  94. /* Open Sidebar */
  95. $('.showMenu .profile').on('click', function () {
  96. mobileMenu.show('sidebar');
  97. });
  98.  
  99. /* Close menu through close icon */
  100. $('.closeMenu').on('click', function () {
  101. mobileMenu.hide('menu');
  102. mobileMenu.hide('sidebar');
  103. });
  104.  
  105. /* Close menu through clicking outside menu */
  106. $('.menuOverlay').on('click', function () {
  107. mobileMenu.hide('menu');
  108. mobileMenu.hide('sidebar');
  109. });
  110. },
  111.  
  112. /* Show
  113. ========== */
  114. show: function (elem) {
  115. /* If main menu, open main menu */
  116. if (elem == 'menu') {
  117. $('.menuColumn').show(0);
  118. $('body').addClass('menuOpen');
  119. }
  120. /* If sidebar, open sidebar */
  121. else if (elem == 'sidebar') {
  122. $('.sidebar').show(0);
  123. $('body').addClass('sidebarOpen');
  124. }
  125. $('.menuOverlay').fadeIn(300);
  126. },
  127.  
  128. /* Hide
  129. ========== */
  130. hide: function (elem) {
  131. /* If main menu, close main menu */
  132. if (elem == 'menu') {
  133. setTimeout(function () {
  134. $('.menuColumn').hide(0);
  135. }, 300);
  136. $('body').removeClass('menuOpen');
  137. }
  138. /* If sidebar, close sidebar */
  139. else if (elem == 'sidebar') {
  140. setTimeout(function () {
  141. $('.sidebar').hide(0);
  142. }, 300);
  143. $('body').removeClass('sidebarOpen');
  144. }
  145. $('.menuOverlay').fadeOut(300);
  146. }
  147. }
  148.  
  149.  
  150. /* Sidebar Dropdowns
  151. ============================================================== */
  152. var sidebarDropdowns = {
  153. init: function () {
  154.  
  155. // Hide dropdowns on page load (needed to show dropdown content to non-javascript users)
  156. $('ul.dropdownList').hide(0);
  157. $('div.dropdownContent').hide(0);
  158.  
  159. // Prime first type of dropdowns for click events
  160. $('.myDepartmentList > .hasDropdown .title').on('click', function () {
  161. $(this).parent().toggleClass('open');
  162. $(this).parent().find('.dropdownList').slideToggle();
  163. });
  164.  
  165. // Prime second type of dropdowns for click events
  166. $('.sidebarDropdown h4').on('click', function () {
  167. $(this).toggleClass('open');
  168. $(this).parent().find('.dropdownContent').slideToggle();
  169. });
  170. }
  171. }
  172.  
  173.  
  174. /* Knowledge Base Dropdowns
  175. ============================================================== */
  176. var knowledgeBase = {
  177.  
  178. // Run URL hashtag recognition + prime click events on page load. Hide dropdowns on page load (needed to show dropdown content to non-javascript users).
  179. init: function (parent) {
  180. $(parent + '.knowledgeBaseDropdownContent').hide(0);
  181.  
  182. $(parent + '.knowledgeBaseDropdownHead').on('click', function () {
  183. knowledgeBase.executeDropdown($(this), parent);
  184. });
  185.  
  186. knowledgeBase.processHash();
  187. },
  188.  
  189. // Animate dropdowns and add corresponding open class
  190. executeDropdown: function (elem, parent) {
  191. if (!elem.hasClass('open')) {
  192. $(parent + '.knowledgeBaseDropdownContent').slideUp();
  193. $(parent + '.knowledgeBaseDropdownHead').removeClass('open');
  194. elem.addClass('open');
  195. elem.parent().find('.knowledgeBaseDropdownContent').slideDown();
  196. } else {
  197. elem.parent().find('.knowledgeBaseDropdownContent').slideUp();
  198. elem.removeClass('open');
  199. }
  200. knowledgeBase.textToHash(elem);
  201. },
  202.  
  203. // Get title from dropdown and strip it from uppercase characters, special characters and whitespace.
  204. textToHash: function (elem) {
  205. var headText = elem.text();
  206. var strippedText = headText.replace(/[^a-zA-Z ]/g, '').replace(/ /g, '-').toLowerCase();
  207. var hashText = '#' + strippedText;
  208. var currentHash = window.location.hash;
  209.  
  210. // Call function to push new (or empty) hashtag
  211. if (currentHash != hashText) {
  212. knowledgeBase.setHash(hashText);
  213. } else {
  214. knowledgeBase.setHash(' ');
  215. }
  216. },
  217.  
  218. // Push hash to URL by using history states. Fallback for older browsers. Gets rid of native browser scrolling on setting hash
  219. setHash: function (hash) {
  220. if (history.replaceState) {
  221. history.replaceState(null, null, hash);
  222. }
  223. else {
  224. location.hash = hash;
  225. }
  226. },
  227.  
  228. // On page load, open correct dropdown based on hash in URL
  229. processHash: function () {
  230. var currentHash = window.location.hash;
  231.  
  232. if (currentHash != '') {
  233. $(currentHash).find('.knowledgeBaseDropdownContent').show(0);
  234. $(currentHash).find('.knowledgeBaseDropdownHead').addClass('open');
  235. }
  236. }
  237. }
  238.  
  239.  
  240. /* Print button
  241. ============================================================== */
  242. var printPage = {
  243. init: function () {
  244. $('.printButton').on('click', function () {
  245. window.print();
  246. return false;
  247. });
  248. }
  249. }
  250.  
  251. /* FAQ category dropdown
  252. ============================================================== */
  253. var categoriesFAQDropdown = {
  254. init: function () {
  255. $('.categoriesFAQ .categoriesSubTitle').on('click', function () {
  256. $(this).parent().find('ul').slideToggle();
  257. });
  258. }
  259. }
  260.  
  261. /* Search departments
  262. ============================================================== */
  263. var departmentSearch = {
  264. init: function () {
  265.  
  266. var searchValue = getQueryVarByName('searchTerm');
  267. var province = getQueryVarByName('provinceSelect');
  268.  
  269. if (searchValue != '' && searchValue != null) {
  270. $('#searchTerm').val(searchValue);
  271. $('.searchTermText').text(searchValue);
  272. } else {
  273. // DEBUG ONLY
  274. $('.searchResults').hide(0);
  275. }
  276.  
  277. if (province != '' && province != null) {
  278. $('#provinceSelect').val(province);
  279. }
  280.  
  281. }
  282. }
  283.  
  284.  
  285. /* Choose to change password or emailaddress
  286. ============================================================== */
  287. var changeLoginDetailsChoice = {
  288. init: function () {
  289. $('.tabsContainer .tab').hide(0);
  290. $('.tabsContainer .tab:first-of-type').show(0);
  291.  
  292. $('.tabsContainer .tabsHead li').on('click', function () {
  293. $('.tabsContainer .tabsHead li').removeClass('active');
  294. $(this).addClass('active');
  295.  
  296.  
  297. var targetTab = $(this).find('a').data('href');
  298. $('.tabsContainer .tab').hide(0);
  299. $('.tabsContainer .tab#' + targetTab).show(0);
  300. });
  301. }
  302. }
  303.  
  304.  
  305. /* TinyMCE Init with config options
  306. ============================================================== */
  307. var wysiwyg = {
  308. init: function () {
  309.  
  310. tinymce.init({
  311. selector: 'textarea.rte',
  312. height: 300,
  313. theme: 'modern',
  314. language: 'nl',
  315. plugins: [
  316. 'advlist autolink lists link image charmap pagebreak media table searchreplace visualchars paste textpattern imagetools'
  317. ],
  318. menubar: false,
  319. toolbar1: 'cut copy paste | undo redo | link bullist numlist table charmap',
  320. toolbar2: 'bold italic underline | alignleft aligncenter alignright alignjustify | image media'
  321. });
  322. }
  323. }
  324.  
  325.  
  326. /* Get Query Vars
  327. ============================================================== */
  328. function getQueryVarByName(name, url) {
  329. if (!url) {
  330. url = window.location.href;
  331. }
  332. name = name.replace(/[\[\]]/g, "\\$&");
  333. var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
  334. results = regex.exec(url);
  335. if (!results) return null;
  336. if (!results[2]) return '';
  337. return decodeURIComponent(results[2].replace(/\+/g, " "));
  338. }
  339.  
  340.  
  341. /* THIS IS FOR TESTING ONLY
  342. ============================================================== */
  343. var debug = {
  344.  
  345. menuOnClick: function () {
  346. $('nav > ul > li > a').on('click', function () {
  347. $('nav > ul > li').removeClass('active');
  348. $(this).parent().addClass('active');
  349. });
  350.  
  351. $('nav > ul > li > ul a').on('click', function () {
  352. $('nav > ul > li > ul li').removeClass('active');
  353. $(this).parent().addClass('active');
  354. });
  355. },
  356.  
  357. menuOnLoad: function () {
  358.  
  359. // Get current page by URL
  360. var currentPage = location.pathname;
  361. if (location.pathname.slice(-1) != '/') {
  362. currentPage = currentPage + '/';
  363. }
  364.  
  365. // Set active menu item based on current page
  366. if (currentPage == '/Pages/Nieuws/' || currentPage == '/Pages/NieuwsDetail/' || currentPage == '/Pages/ContentpaginaIframe/') {
  367. $('.navMenu > nav > ul > li:nth-child(1)').addClass('active');
  368.  
  369. if (currentPage == '/Pages/Nieuws/') {
  370. $('.navMenu > nav > ul > li:nth-child(1) li:nth-child(1)').addClass('active');
  371. }
  372. else if (currentPage == '/Pages/ContentpaginaIframe/') {
  373. $('.navMenu > nav > ul > li:nth-child(1) li:nth-child(2)').addClass('active');
  374. }
  375. }
  376. else if (currentPage == '/Pages/Kennisbank/' || currentPage == '/Pages/KennisbankDetail/') {
  377. $('.navMenu > nav > ul > li:nth-child(2)').addClass('active');
  378. $('#content').removeClass('withSubmenu');
  379. }
  380. else if (currentPage == '/Pages/Cursussen/' || currentPage == '/Pages/CursusDetail/' || currentPage == '/Pages/CursusInschrijving/') {
  381. $('.navMenu > nav > ul > li:nth-child(3)').addClass('active');
  382. $('#content').removeClass('withSubmenu');
  383. }
  384. else if (currentPage == '/Pages/AgendaOverzicht/' || currentPage == '/Pages/AgendaDetail/' || currentPage == '/Pages/AgendaArchief/') {
  385. $('.navMenu > nav > ul > li:nth-child(4)').addClass('active');
  386.  
  387. if (currentPage == '/Pages/AgendaOverzicht/') {
  388. $('.navMenu > nav > ul > li:nth-child(4) li:nth-child(1)').addClass('active');
  389. }
  390. else if (currentPage == '/Pages/AgendaArchief/') {
  391. $('.navMenu > nav > ul > li:nth-child(4) li:nth-child(2)').addClass('active');
  392. }
  393. }
  394. else {
  395. $('#content').removeClass('withSubmenu');
  396. }
  397.  
  398. }
  399. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement