{"version":3,"names":[],"mappings":"","sources":["borsveckan.js"],"sourcesContent":["/**\n * This script contains site specific logic\n * Made at Oxys.\n */\n\n(function ($) {\n\n /*************************************************\n *\n * Global events\n *\n *************************************************/\n\n $(document).ready(function () {\n // Should not contain breakpoint specific stuff, should be handled by pagestates\n Oxys.dispatch({\n 'any': {\n 'setResponsiveState': [],\n 'noticeClose' : []\n },\n 'path-frontpage': {\n 'slideinit': [],\n 'modalBlock': []\n },\n 'arkiv' : {\n 'noClick' : [],\n 'splitDate' : []\n },\n 'page-node-type-issue': {\n 'sideMenu' : [],\n 'sideAffix': [],\n 'smoothScroll': [],\n 'modalImage': [],\n 'carousel' : [],\n 'articleStop' : [],\n }\n });\n });\n\n\n $(window).resize(function () {\n Oxys.resizeTimeOut();\n });\n\n /*************************************************\n *\n * Initalize, utility functions\n *\n *************************************************/\n\n var Oxys = {\n // Used for state handling\n pageStates: {\n enabled: [],\n states: {\n breakpoints: {\n xxs: ['somethingOnlyOnMobile'],\n xs: ['somethingOnlyOnMobile'],\n sm: ['somethingOnlyOnMobile'],\n md: [],\n lg: []\n }\n },\n // See bottom of script\n handlers: {}\n }\n };\n\n\n /**\n * Cache jQuery results.\n * Use $m() instead os $() when you want to cache result for performance\n * @param query\n * @returns {*}\n */\n var $memory = [];\n function $m(query, clearCache) {\n if (query in $memory && !clearCache) {\n return $memory[query];\n } else {\n return $memory[query] = $(query);\n }\n }\n\n\n /**\n * Cache of existing elements\n * @param query\n * @returns bool\n */\n var hasElement = [];\n function $has(query, clearCache) {\n if (query in hasElement && !clearCache) {\n return hasElement[query];\n } else {\n return hasElement[query] = ($m(query, clearCache).length > 0);\n }\n }\n\n // add indexOf to !E < 9\n if(!Array.prototype.indexOf) {\n Array.prototype.indexOf = function(what, i) {\n i = i || 0;\n var L = this.length;\n while (i < L) {\n if(this[i] === what) return i;\n ++i;\n }\n return -1;\n };\n }\n\n\n /**\n * Handle different page states for different breakpoints, moving nodes in DOM etc.\n */\n\n /**\n * Switch to a given display state. Checks diff against current applied.\n * @param desiredStates\n */\n Oxys.pageStates.setStates = function(desiredStates) {\n\n // clone currently applied states array\n var enabledStates = this.enabled.slice();\n\n // Compare arrays, See if there's anything to do\n if (enabledStates.sort().toString() !== desiredStates.sort().toString()) {\n // Desired does not match current\n // Assume all should be disabled\n var todo = { enable: [], disable: enabledStates};\n // Create a diff\n var arrayLength = desiredStates.length;\n for (var i = 0; i < arrayLength; i++) {\n var stateName = desiredStates[i];\n // state is desired\n var index = enabledStates.indexOf(stateName);\n if (index === -1) {\n // state is not enabled\n todo.enable.push(stateName);\n } else {\n // state is desired and enabled\n todo.disable.splice(index, 1);\n }\n }\n\n // Disable first\n arrayLength = todo.disable.length;\n for (var i = 0; i < arrayLength; i++) {\n this.toggleState(todo.disable[i], false);\n }\n\n // Enable\n arrayLength = todo.enable.length;\n for (var i = 0; i < arrayLength; i++) {\n this.toggleState(todo.enable[i], true);\n }\n\n }\n };\n\n\n /**\n * Turn a state on or off by calling its enable and disable methods respectively\n *\n * @param handlerName\n * @param state\n * @returns {boolean}\n */\n Oxys.pageStates.toggleState = function(handlerName, state) {\n\n if (typeof this.handlers[handlerName] !== 'undefined') {\n // Handler exists\n var handler = this.handlers[handlerName];\n var index = this.enabled.indexOf(handlerName);\n var isEnabled = (index >= 0);\n\n if (state === true) {\n // We are going to enable\n\n if (isEnabled) {\n // already enabled\n return true;\n }\n\n if (handler.enable()) {\n // We successfully enabled\n // TODO: sanitize class name\n // TODO: Remove jQuery dependency\n $m('body').addClass('state-' + handlerName);\n // Add handler to enabled\n this.enabled.push(handlerName);\n return true;\n } else {\n console.log('Could not apply state: ' + handlerName);\n return false;\n }\n\n } else {\n // We are going to disable\n\n if (!isEnabled) {\n // already disabled\n return true;\n }\n\n if (handler.disable()) {\n // We successfully disabled\n $m('body').removeClass('state-' + handlerName);\n // Remove handler from enabled\n this.enabled.splice(index, 1);\n return true;\n } else {\n console.log('Could not restore state: ' + handlerName);\n return false;\n }\n }\n } else {\n console.log('Undefined handler: ' + handlerName);\n return false;\n }\n };\n\n\n\n /*************************************************\n *\n * Oxys methods\n *\n *************************************************/\n\n /**\n * A method for initalizing methods ONLY on desired pages/templates\n */\n Oxys.dispatch = function (initializers) {\n for (var template in initializers) {\n if (template === \"any\" || $m('body').hasClass(template)) {\n var methods = initializers[template];\n for (var m in methods) {\n if (typeof Oxys[m] !== 'undefined') {\n // Make sure we are passing an array and that it's flat\n Oxys[m].apply(this, Array.prototype.concat.apply([], new Array(methods[m])));\n }\n }\n }\n }\n };\n\n /**\n * Runs on window resize, calls setResponsiveState after delay\n */\n Oxys.resizeTimeOut = function () {\n window.clearTimeout(Oxys.resizeTimer);\n Oxys.resizeTimer = window.setTimeout(Oxys.setResponsiveState, 300);\n }\n\n /**\n * Set page states based on breakpoints\n */\n Oxys.setResponsiveState = function() {\n var breakpoint = Oxys.getBreakpoint();\n if (typeof Oxys.pageStates.states.breakpoints[breakpoint] !== 'undefined') {\n Oxys.pageStates.setStates(Oxys.pageStates.states.breakpoints[breakpoint]);\n }\n };\n\n /**\n * Find the active breakpoint from content of pseudo-element set by mediaquery in css\n *\n * @returns {string}\n */\n Oxys.getBreakpoint = function() {\n var win = window,\n doc = win.document,\n el,\n pseudo;\n if (win.getComputedStyle && doc.querySelector) {\n el = doc.querySelector('body');\n pseudo = win.getComputedStyle(el, ':after').getPropertyValue('content');\n if (pseudo) {\n // Firefox bug replace\n return pseudo.replace( /\"/g,'');\n }\n } else {\n // Default for old browsers\n return 'md';\n }\n };\n\n\n /**\n * Return true if current breakpoint is in passed array\n *\n * @param breakpoints\n * @returns {boolean}\n */\n Oxys.isBp = function (breakpoints) {\n var index = $.inArray(Oxys.getBreakpoint(), breakpoints);\n return (index >= 0);\n };\n\n Oxys.slideinit = function () {\n $('.carousel')\n .find('.region-highlighted').addClass('carousel-inner')\n .children('.block').addClass('item')\n .first().addClass('active');\n $('.carousel').carousel()\n };\n\n function deselect(e) {\n $('#block-borsveckanblock').removeClass('show');\n $('#dl-preview').removeClass('selected');\n }\n\n Oxys.modalBlock = function () {\n $('#download-trial').one('click', function() {\n\n var ajaxSettings = {\n url: Drupal.url('admin/config/modal_form'),\n };\n Drupal.ajax(ajaxSettings).execute();\n });\n };\n\n Oxys.noClick = function() {\n $('#block-archivepagehighlight').click(function(e) {\n e.preventDefault();\n });\n };\n\n Oxys.sideMenu = function() {\n var pageWrapper = $('#page-wrapper');\n var menuButton = $('#menu-button');\n\n menuButton.on('click', function () {\n pageWrapper.toggleClass('menu-open');\n });\n\n $('#content').on('click', function () {\n if($('#main-wrapper').css(\"marginLeft\") == \"300px\" ) {\n menuButton.trigger('click');\n }\n });\n };\n\n Oxys.sideAffix = function () {\n\n var currScrollPos = 1000;\n\n $(window).on('scroll', function () {\n\n var newScrollPos = $(this).scrollTop();\n\n if (newScrollPos > 1000 && newScrollPos > currScrollPos) {\n $('#side-bar').addClass('affix');\n }\n else {\n $('#side-bar').removeClass('affix');\n }\n currScrollPos = newScrollPos;\n });\n\n //$('#side-bar').affix('checkPosition');\n }\n\n\n Oxys.smoothScroll = function () {\n // URL updates and the element focus is maintained\n // originally found via in Update 3 on http://www.learningjquery.com/2007/10/improved-animated-scrolling-script-for-same-page-links\n\n // filter handling for a /dir/ OR /indexordefault.page\n function filterPath(string) {\n return string\n .replace(/^\\//, '')\n .replace(/(index|default).[a-zA-Z]{3,4}$/, '')\n .replace(/\\/$/, '');\n }\n\n var locationPath = filterPath(location.pathname);\n\n $('a[href*=\"#\"]').each(function () {\n var thisPath = filterPath(this.pathname) || locationPath;\n var hash = this.hash;\n if ($(\"#\" + hash.replace(/#/, '')).length) {\n if (locationPath == thisPath && (location.hostname == this.hostname || !this.hostname) && this.hash.replace(/#/, '')) {\n var $target = $(hash), target = this.hash;\n if (target) {\n\n $(this).click(function (event) {\n\n\n if($('#main-wrapper').css(\"marginLeft\") == \"300px\") {\n $('#menu-button').trigger('click');\n }\n event.preventDefault();\n\n $('html, body').animate({scrollTop: $target.offset().top}, 1000, function () {\n location.hash = target;\n $target.focus();\n if ($target.is(\":focus\")){ //checking if the target was focused\n return false;\n }else{\n $target.attr('tabindex','-1'); //Adding tabindex for elements not focusable\n $target.focus(); //Setting focus\n };\n\n });\n\n });\n }\n }\n }\n });\n };\n\n Oxys.modalImage = function () {\n\n $('.imageModal a').on('click', function(e) {\n if(Oxys.isBp(['md', 'lg'])) {\n e.preventDefault();\n $(this).closest('.node--type-image-content').find('.field--name-field-image-link').clone().appendTo($('.modal-link').addClass('has-link'));\n $('.imageModalSrc').attr('src', $(this).find('img').first().attr('src'));\n $('#imageModal').modal('show');\n }\n\n });\n\n //Push dataLayer event once per image-content element.\n $('.node--type-image-content .imageModal a').one('click', function(e) {\n var article = $(this).closest('article');\n var title = $(article).attr('data-title');\n var issue = $(article).attr('data-issue');\n\n\n dataLayer.push({\n 'issue': issue,\n 'title': title,\n 'event': 'imageContentZoom'\n });\n });\n\n $('#imageModal').on('shown.bs.modal', function () {\n $('html').css('overflow-y', 'hidden');\n });\n\n $('#imageModal').on('hide.bs.modal', function () {\n $('html').css('overflow-y', 'scroll');\n if($('.modal-link').hasClass('has-link')) {\n $('.modal-link .field--name-field-image-link').remove();\n }\n });\n\n };\n\n\n Oxys.splitDate = function() {\n $('article').each(function(t) {\n var title = $(this).find('.node__title a');\n var str = title.text();\n var res = str.split(\"/\");\n $(title).html(res[0] + ' ' + res[1]);\n })\n };\n\n Oxys.noticeClose = function() {\n\n var cookie = getCookie('noticeClosed');\n if(!cookie) {\n $('#notice-block').removeClass('closed');\n $('.notice-block-close').on('click', function() {\n setCookie('noticeClosed', true);\n $('#notice-block').addClass('closed');\n })\n }\n };\n\n function setCookie(key, value) {\n var expires = new Date();\n expires.setTime(expires.getTime() + 31536000000); //1 year\n document.cookie = key + '=' + value + ';expires=' + expires.toUTCString();\n }\n\n function getCookie(key) {\n var keyValue = document.cookie.match('(^|;) ?' + key + '=([^;]*)(;|$)');\n return keyValue ? keyValue[2] : null;\n }\n\n /**\n * Carousel\n */\n Oxys.carousel = function () {\n // Carousel swipe\n $('.carousel').bcSwipe({ threshold: 50 });\n };\n\n Oxys.articleStop = function() {\n $('article').each(function() {\n $(this).find('.paragraph--type--paragraph p').last().append(\"\");\n });\n };\n\n\n /*************************************************\n *\n * Oxys page state handlers\n *\n *************************************************/\n\n /**\n * Do stuff\n */\n Oxys.pageStates.handlers.somethingOnlyOnMobile = {\n enable: function() {\n if ($has(\".something\")) {\n //Do stuff\n return true;\n }\n return false;\n },\n\n disable: function() {\n if ($has(\".something\")) {\n // Revert stuff\n return true;\n }\n return false;\n }\n };\n\n\n\n\n\n})(jQuery);\n\n//# sourceMappingURL=maps/borsveckan.js.map\n"],"file":"../borsveckan.js"}