Skip to content
This repository was archived by the owner on Jun 20, 2019. It is now read-only.

Commit

Permalink
IE8 Compatibility, removed defineProperty
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Karl committed Aug 12, 2014
1 parent 817cf1d commit 2543e56
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 116 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2013 Matt Karl
Copyright (c) 2014 Matt Karl

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
Expand Down
3 changes: 2 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "canteen",
"version": "1.1.4",
"version": "1.1.5",
"main": "lib/canteen.min.js",
"dependencies": {
"cloudkid-debug": "*",
Expand All @@ -12,6 +12,7 @@
},
"ignore": [
".gitignore",
".gitattributes",
"build.xml",
"build.properties",
"docs.json",
Expand Down
2 changes: 1 addition & 1 deletion build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ git.master=master

compressor=uglifyjs
js.validator=jshint
version=1.1.4
version=1.1.5

output.name=canteen
output.min=${build.dir}/${output.name}.min.js
Expand Down
40 changes: 15 additions & 25 deletions lib/canteen.debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,16 +201,17 @@
siteLoadingId: "body",
loadingClass: "loading"
};
p.gateway = null, p.parameters = null, p.options = {}, Site.ENTER = "enter", Site.EXIT = "exit",
Site.READY = "ready", Site.LOADING = "loading", Site.LOADING_DONE = "loadingDone",
Site.VERSION = "1.1.4", p.initialize = function() {
p.currentState = null, p.currentPage = null, p.gateway = null, p.parameters = null,
p.options = {}, Site.ENTER = "enter", Site.EXIT = "exit", Site.READY = "ready",
Site.LOADING = "loading", Site.LOADING_DONE = "loadingDone", Site.VERSION = "1.1.5",
Site.instance = null, p.initialize = function() {
if (_instance) throw "Site has already been created. Use Canteen.Site.instance";
_instance = this;
Site.instance = _instance = this;
var opts = this.options = _defaultOptions;
(Canteen.settings.clientEnabled === undefined || Canteen.settings.clientEnabled) && ($(opts.siteLoadingId).addClass(opts.loadingClass),
this.parameters = LocationUtils.getParameters(), Debug.enabled = Canteen.settings.debug,
_currentId = 1, _currentState = Canteen.settings.uriRequest, this._enableHistory(!0),
this._fixInternalLinks(), this.gateway = new Gateway(Canteen.settings.gatewayPath, this._gatewayReady.bind(this)));
_currentId = 1, this.currentState = _currentState = Canteen.settings.uriRequest,
this._enableHistory(!0), this._fixInternalLinks(), this.gateway = new Gateway(Canteen.settings.gatewayPath, this._gatewayReady.bind(this)));
}, p._enableHistory = function(enable) {
$(global).off("statechange"), enable && $(global).on("statechange", this._onStateChange.bind(this));
}, p.redirect = function(uri, replaceInHistory, allowRefresh, asyncRefresh) {
Expand All @@ -222,19 +223,7 @@
}, siteTitle, state) : (_currentId++, History.pushState({
state: _currentId
}, siteTitle, state)));
}, Object.defineProperty(Site, "instance", {
get: function() {
return _instance;
}
}), Object.defineProperty(p, "currentState", {
get: function() {
return _currentState;
}
}), Object.defineProperty(p, "currentPage", {
get: function() {
return _currentPage;
}
}), p.refresh = function(async, params) {
}, p.refresh = function(async, params) {
async = async === undefined ? !0 : async, async ? this._updatePageContent(_currentState, params) : document.location.reload(!0);
}, p._fixInternalLinks = function() {
$("a").internalLink(this), Forms.setup(this, "true" === this.parameters.debugForms);
Expand All @@ -255,19 +244,20 @@
})) : Debug.warn("The page your trying to add needs to extend Canteen.Page");
}, p._enterPage = function() {
var page = this.getPageByUri(_currentState);
page && (_currentPage = page.content, _currentPage.uri = _currentState, _currentPage.active = !0,
_currentPage.enter(), this.resize()), this.trigger(Site.ENTER, _currentState);
page && (this.currentPage = _currentPage = page.content, _currentPage.uri = _currentState,
_currentPage.active = !0, _currentPage.enter(), this.resize()), this.trigger(Site.ENTER, _currentState);
}, p.getPageByUri = function(uri) {
var len = _pages.length, i = 0, pg = null;
if (0 === len) return null;
for (i = 0; len > i; i++) if (pg = _pages[i], pg.uri === uri || pg.uri instanceof RegExp && pg.uri.test(uri)) return pg;
return null;
}, p._updatePageContent = function(uri, params) {
var site = this, options = this.options, page = this.getPageByUri(uri), url = Canteen.settings.baseUrl + uri;
return this.trigger(Site.EXIT, _currentState), _currentState = uri, page && page.content === _currentPage && !page.content.refresh(uri) ? void (page.content.uri = uri) : (_currentPage && (_currentPage.exit(),
_currentPage.active = !1, _currentPage = null), Forms.destroy(), _lastRequest = uri,
params = params === undefined ? {} : params, params.async = !0, this.trigger(Site.LOADING),
$(options.pageLoadingId).removeClass(options.loadingClass).addClass(options.loadingClass),
return this.trigger(Site.EXIT, _currentState), this.currentState = _currentState = uri,
page && page.content === _currentPage && !page.content.refresh(uri) ? void (page.content.uri = uri) : (_currentPage && (_currentPage.exit(),
_currentPage.active = !1, this.currentPage = _currentPage = null), Forms.destroy(),
_lastRequest = uri, params = params === undefined ? {} : params, params.async = !0,
this.trigger(Site.LOADING), $(options.pageLoadingId).removeClass(options.loadingClass).addClass(options.loadingClass),
Debug.log("Update Page Content : " + uri), void $.post(url, params, function(response) {
if (uri == _lastRequest) {
if (_lastRequest = null, site.trigger(Site.LOADING_DONE), $(options.pageLoadingId).removeClass(options.loadingClass),
Expand Down
73 changes: 29 additions & 44 deletions lib/canteen.js
Original file line number Diff line number Diff line change
Expand Up @@ -1197,7 +1197,21 @@
*/
loadingClass : 'loading'
};


/**
* The current state URI
* @property {String} currentState
* @readOnly
*/
p.currentState = null;

/**
* Get the current page object
* @property {Canteen.Page} currentPage
* @readOnly
*/
p.currentPage = null;

/**
* The instancee of the gateway
* @property {Gateway} gateway
Expand Down Expand Up @@ -1253,7 +1267,15 @@
* @property {String} VERSION
* @readOnly
*/
Site.VERSION = "1.1.4";
Site.VERSION = "1.1.5";

/**
* Get the singleton instance of the site
* @property {Site} instance
* @static
* @readOnly
*/
Site.instance = null;

/**
* Constructor for the site
Expand All @@ -1265,7 +1287,7 @@
throw "Site has already been created. Use Canteen.Site.instance";
}

_instance = this;
Site.instance = _instance = this;

var opts = this.options = _defaultOptions;

Expand All @@ -1283,7 +1305,7 @@

// Setup history
_currentId = 1;
_currentState = Canteen.settings.uriRequest;
this.currentState = _currentState = Canteen.settings.uriRequest;
this._enableHistory(true);
this._fixInternalLinks();

Expand Down Expand Up @@ -1362,43 +1384,6 @@
}
};

/**
* Get the singleton instance of the site
* @property {Site} instance
* @static
* @readOnly
*/
Object.defineProperty(Site, "instance", {
get: function()
{
return _instance;
}
});

/**
* The current state URI
* @property {String} currentState
* @readOnly
*/
Object.defineProperty(p, "currentState", {
get: function()
{
return _currentState;
}
});

/**
* Get the current page object
* @property {Canteen.Page} currentPage
* @readOnly
*/
Object.defineProperty(p, "currentPage", {
get: function()
{
return _currentPage;
}
});

/**
* Do a refresh of the page content
* @method refresh
Expand Down Expand Up @@ -1520,7 +1505,7 @@
var page = this.getPageByUri(_currentState);
if (page)
{
_currentPage = page.content;
this.currentPage = _currentPage = page.content;
_currentPage.uri = _currentState;
_currentPage.active = true;
_currentPage.enter();
Expand Down Expand Up @@ -1576,7 +1561,7 @@
this.trigger(Site.EXIT, _currentState);

// Update the current uri
_currentState = uri;
this.currentState = _currentState = uri;

// Special-case if we're already on the current page
// but only the content needs to update
Expand All @@ -1591,7 +1576,7 @@
{
_currentPage.exit();
_currentPage.active = false;
_currentPage = null;
this.currentPage = _currentPage = null;
}

// Form cleanup
Expand Down
2 changes: 1 addition & 1 deletion lib/canteen.min.js

Large diffs are not rendered by default.

71 changes: 28 additions & 43 deletions src/Canteen/Site.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,21 @@
*/
loadingClass : 'loading'
};


/**
* The current state URI
* @property {String} currentState
* @readOnly
*/
p.currentState = null;

/**
* Get the current page object
* @property {Canteen.Page} currentPage
* @readOnly
*/
p.currentPage = null;

/**
* The instancee of the gateway
* @property {Gateway} gateway
Expand Down Expand Up @@ -173,6 +187,14 @@
* @readOnly
*/
Site.VERSION = "${version}";

/**
* Get the singleton instance of the site
* @property {Site} instance
* @static
* @readOnly
*/
Site.instance = null;

/**
* Constructor for the site
Expand All @@ -184,7 +206,7 @@
throw "Site has already been created. Use Canteen.Site.instance";
}

_instance = this;
Site.instance = _instance = this;

var opts = this.options = _defaultOptions;

Expand All @@ -202,7 +224,7 @@

// Setup history
_currentId = 1;
_currentState = Canteen.settings.uriRequest;
this.currentState = _currentState = Canteen.settings.uriRequest;
this._enableHistory(true);
this._fixInternalLinks();

Expand Down Expand Up @@ -281,43 +303,6 @@
}
};

/**
* Get the singleton instance of the site
* @property {Site} instance
* @static
* @readOnly
*/
Object.defineProperty(Site, "instance", {
get: function()
{
return _instance;
}
});

/**
* The current state URI
* @property {String} currentState
* @readOnly
*/
Object.defineProperty(p, "currentState", {
get: function()
{
return _currentState;
}
});

/**
* Get the current page object
* @property {Canteen.Page} currentPage
* @readOnly
*/
Object.defineProperty(p, "currentPage", {
get: function()
{
return _currentPage;
}
});

/**
* Do a refresh of the page content
* @method refresh
Expand Down Expand Up @@ -439,7 +424,7 @@
var page = this.getPageByUri(_currentState);
if (page)
{
_currentPage = page.content;
this.currentPage = _currentPage = page.content;
_currentPage.uri = _currentState;
_currentPage.active = true;
_currentPage.enter();
Expand Down Expand Up @@ -495,7 +480,7 @@
this.trigger(Site.EXIT, _currentState);

// Update the current uri
_currentState = uri;
this.currentState = _currentState = uri;

// Special-case if we're already on the current page
// but only the content needs to update
Expand All @@ -510,7 +495,7 @@
{
_currentPage.exit();
_currentPage.active = false;
_currentPage = null;
this.currentPage = _currentPage = null;
}

// Form cleanup
Expand Down

0 comments on commit 2543e56

Please sign in to comment.