diff --git a/src/gelato.js b/src/gelato.js index f4fbbf0..90e87f1 100644 --- a/src/gelato.js +++ b/src/gelato.js @@ -20,15 +20,6 @@ if (Backbone === undefined) { window.Backbone = Backbone; } -function getCookie(name) { - const value = '; ' + document.cookie; - const parts = value.split('; ' + name + '='); - - if (parts.length == 2) { - return parts.pop().split(';').shift(); - } -} - function getScreenHeight() { return $(window).height(); } @@ -49,10 +40,6 @@ function isWebsite() { return _.includes(document.location, 'http'); } -function reload(forcedReload) { - document.location.reload(forcedReload); -} - function setCookie(name, value, days) { let expires = ''; @@ -66,8 +53,6 @@ function setCookie(name, value, days) { document.cookie = name + '=' + value + expires + '; path=/'; } -Gelato.getCookie = getCookie; - Gelato.getScreenHeight = getScreenHeight; Gelato.getScreenWidth = getScreenWidth; @@ -78,10 +63,6 @@ Gelato.isLocalhost = isLocalhost; Gelato.isWebsite = isWebsite; -Gelato.reload = reload; - -Gelato.setCookie = setCookie; - Gelato._BUILD = '{!date!}'; Gelato._VERSION = '{!version!}'; diff --git a/src/modules/Application.js b/src/modules/Application.js index bb841e2..0e1e4ec 100644 --- a/src/modules/Application.js +++ b/src/modules/Application.js @@ -17,10 +17,27 @@ class GelatoApplication extends Backbone.View { return this; } + getCookie(name) { + const value = '; ' + document.cookie; + const parts = value.split('; ' + name + '='); + + if (parts.length == 2) { + return parts.pop().split(';').shift(); + } + } + getHeight() { return Backbone.$('gelato-application').height(); } + getQueryString(name, url) { + const href = url ? url : window.location.href; + const expression = new RegExp( '[?&]' + name + '=([^&#]*)', 'i' ); + const result = expression.exec(href); + + return result ? result[1] : null; + } + getWidth() { return Backbone.$('gelato-application').width(); } @@ -33,6 +50,23 @@ class GelatoApplication extends Backbone.View { return this.getWidth() <= this.getHeight(); } + reload(forcedReload) { + document.location.reload(forcedReload); + } + + setCookie(name, value, days) { + let expires = ''; + + if (days) { + const date = new Date(); + + date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); + expires = '; expires=' + date.toGMTString(); + } + + document.cookie = name + '=' + value + expires + '; path=/'; + } + } Gelato = Gelato || {};