Skip to content

Commit

Permalink
Move several gelato.js function to the application scope
Browse files Browse the repository at this point in the history
  • Loading branch information
mcfarljw committed Sep 25, 2016
1 parent 60a836b commit c5a4ede
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 19 deletions.
19 changes: 0 additions & 19 deletions src/gelato.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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 = '';

Expand All @@ -66,8 +53,6 @@ function setCookie(name, value, days) {
document.cookie = name + '=' + value + expires + '; path=/';
}

Gelato.getCookie = getCookie;

Gelato.getScreenHeight = getScreenHeight;

Gelato.getScreenWidth = getScreenWidth;
Expand All @@ -78,10 +63,6 @@ Gelato.isLocalhost = isLocalhost;

Gelato.isWebsite = isWebsite;

Gelato.reload = reload;

Gelato.setCookie = setCookie;

Gelato._BUILD = '{!date!}';

Gelato._VERSION = '{!version!}';
34 changes: 34 additions & 0 deletions src/modules/Application.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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 || {};
Expand Down

0 comments on commit c5a4ede

Please sign in to comment.