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

Commit

Permalink
Fixed issue with Debug.fatalError
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Karl committed May 1, 2014
1 parent ccbfae1 commit 817cf1d
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 35 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "canteen",
"version": "1.1.3",
"version": "1.1.4",
"main": "lib/canteen.min.js",
"dependencies": {
"cloudkid-debug": "*",
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.3
version=1.1.4

output.name=canteen
output.min=${build.dir}/${output.name}.min.js
Expand Down
61 changes: 30 additions & 31 deletions lib/canteen.debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
return target.apply(that, args.concat(Array.prototype.slice.call(arguments)));
};
});
}(), function() {
Debug.fatalError = function(error) {
var result = error.message + "\non " + error.file + " (code: " + error.code + ")\n";
if (error.stackTrace) for (var j = 0; j < error.stackTrace.length; j++) result += "\n #" + (j + 1) + ". " + error.stackTrace[j];
Debug.error(result);
};
}(), function(global, undefined) {
"use strict";
function type(value) {
Expand Down Expand Up @@ -49,10 +55,9 @@
};
return this.each(function() {
var uri, link = $(this), refresh = link.data("refresh"), href = link.attr("href");
if ("undefined" != typeof refresh) return link.untouch().touch(function(e) {
return checkConfirm(link) ? "soft" == refresh ? (e.preventDefault(), site.refresh(),
void 0) : (href ? document.location.href = href : site.refresh(!1), void 0) : void 0;
}), void 0;
if ("undefined" != typeof refresh) return void link.untouch().touch(function(e) {
return checkConfirm(link) ? "soft" == refresh ? (e.preventDefault(), void site.refresh()) : void (href ? document.location.href = href : site.refresh(!1)) : void 0;
});
if (href && 0 === href.indexOf(basePath)) {
uri = href.substr(basePath.length), link.untouch().touch(function(e) {
e.preventDefault(), checkConfirm(link) && site.redirect(uri);
Expand Down Expand Up @@ -125,13 +130,11 @@
for (var params = {}, i = 0, len = formData.length; len > i; i++) params[formData[i].name] = formData[i].value;
return params.form ? !0 : (site.refresh(!0, params), !1);
}, showResponse = function(response, statusText, xhr, form) {
if (-1 == response.search(/^{.*}$/)) return Debug.error(response), void 0;
if (response = JSON.parse(response), "fatalError" == response.type) return Debug.fatalError(response),
void 0;
if (-1 == response.search(/^{.*}$/)) return void Debug.error(response);
if (response = JSON.parse(response), "fatalError" == response.type) return void Debug.fatalError(response);
var refresh = form.find('input[name="refresh"]'), asyncRefresh = refresh.data("async");
return response.redirect !== undefined ? (site.redirect(response.redirect, !1, !0, asyncRefresh),
void 0) : (Debug.log(response.messages.join("\n")), !response.ifError && refresh.length && "true" == refresh.val() ? (site.refresh(asyncRefresh),
void 0) : (Forms.formFeedback(form, response.messages, response.ifError), void 0));
return response.redirect !== undefined ? void site.redirect(response.redirect, !1, !0, asyncRefresh) : (Debug.log(response.messages.join("\n")),
!response.ifError && refresh.length && "true" == refresh.val() ? void site.refresh(asyncRefresh) : void Forms.formFeedback(form, response.messages, response.ifError));
}, options = {
data: {
async: !0
Expand Down Expand Up @@ -172,12 +175,10 @@
var url = this.gatewayUrl + service + "/" + method;
parameters !== undefined && (url += "/" + ($.isArray(parameters) ? parameters.join("/") : String(parameters))),
Debug.log(url), $.get(url, function(response) {
if (!response || "null" == response) return callback(null), void 0;
if (-1 == response.search(/^{.*}$/)) return Debug.error(response), callback(null),
void 0;
if (!response || "null" == response) return void callback(null);
if (-1 == response.search(/^{.*}$/)) return Debug.error(response), void callback(null);
var data = JSON.parse(response);
return "fatalError" == data.type ? (Debug.fatalError(data), callback(null), void 0) : (callback(data),
void 0);
return "fatalError" == data.type ? (Debug.fatalError(data), void callback(null)) : void callback(data);
});
}, p.destroy = function() {
p = null;
Expand All @@ -202,7 +203,7 @@
};
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.3", p.initialize = function() {
Site.VERSION = "1.1.4", p.initialize = function() {
if (_instance) throw "Site has already been created. Use Canteen.Site.instance";
_instance = this;
var opts = this.options = _defaultOptions;
Expand All @@ -216,12 +217,11 @@
var state = Canteen.settings.basePath, siteTitle = $("<div />").html($("title").html()).text();
return replaceInHistory = replaceInHistory === undefined ? !1 : replaceInHistory,
allowRefresh = allowRefresh === undefined ? !1 : allowRefresh, asyncRefresh = asyncRefresh === undefined ? !0 : asyncRefresh,
Canteen.settings.siteIndex != uri && (state += uri), _currentState == uri ? (allowRefresh ? this.refresh(asyncRefresh) : Debug.log("Already on this page! (current: " + _currentState + ", request: " + uri + ")"),
void 0) : (replaceInHistory ? History.replaceState({
Canteen.settings.siteIndex != uri && (state += uri), _currentState == uri ? void (allowRefresh ? this.refresh(asyncRefresh) : Debug.log("Already on this page! (current: " + _currentState + ", request: " + uri + ")")) : void (replaceInHistory ? History.replaceState({
state: _currentId
}, siteTitle, state) : (_currentId++, History.pushState({
state: _currentId
}, siteTitle, state)), void 0);
}, siteTitle, state)));
}, Object.defineProperty(Site, "instance", {
get: function() {
return _instance;
Expand All @@ -240,8 +240,7 @@
$("a").internalLink(this), Forms.setup(this, "true" === this.parameters.debugForms);
}, p._onStateChange = function() {
var state = History.getState(), uri = state.url.split(Canteen.settings.baseUrl)[1];
return _currentState == uri ? (Debug.log("Already on this page! (" + uri + ")"),
void 0) : (this._updatePageContent(uri), void 0);
return _currentState == uri ? void Debug.log("Already on this page! (" + uri + ")") : void this._updatePageContent(uri);
}, p._gatewayReady = function(success) {
success ? Debug.log("Canteen is ready!") : Debug.error("Unable to setup gateway.");
var options = this.options;
Expand All @@ -265,24 +264,24 @@
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) ? (page.content.uri = uri,
void 0) : (_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),
Debug.log("Update Page Content : " + uri), $.post(url, params, function(response) {
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),
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),
!response || "null" == response) return Debug.error("No data for " + uri), void 0;
if (-1 == response.search(/^{.*}$/)) return Debug.error(response), void 0;
!response || "null" == response) return void Debug.error("No data for " + uri);
if (-1 == response.search(/^{.*}$/)) return void Debug.error(response);
var data = JSON.parse(response);
if ("fatalError" == data.type) return Debug.fatalError(data), void 0;
if (data.redirect !== undefined) return site.redirect(data.redirect, !0), void 0;
if ("fatalError" == data.type) return void Debug.fatalError(data);
if (data.redirect !== undefined) return void site.redirect(data.redirect, !0);
$("body").attr("id", data.pageId), $(options.pageTitleId).html(data.title), $(options.contentId).html(data.content),
document.title = $("<div />").html(data.fullTitle).text(), $("meta[name='keywords']").attr("content", data.keywords),
$("meta[name='description']").attr("content", data.description), site._fixInternalLinks(),
site._enterPage();
}
}), void 0);
}));
}, namespace("Canteen").Site = Site, $(function() {
new Site();
});
Expand Down
29 changes: 28 additions & 1 deletion lib/canteen.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,33 @@
return bound;
};

}());
(function(){

/**
* Extend the existing Debug plugin by having a special method to format stack traces
* @class Debug
*/

/**
* Prepare the fatal error and show the stack trace
* @static
* @method fatalError
* @param {Object} error The fatal error from the server
*/
Debug.fatalError = function(error)
{
var result = error.message + "\non " + error.file + " (code: " + error.code + ")\n";
if (error.stackTrace)
{
for(var j=0; j < error.stackTrace.length; j++)
{
result += "\n\t #" + (j+1) + ". " + error.stackTrace[j];
}
}
Debug.error(result);
};

}());
/**
* @module Canteen
Expand Down Expand Up @@ -1226,7 +1253,7 @@
* @property {String} VERSION
* @readOnly
*/
Site.VERSION = "1.1.3";
Site.VERSION = "1.1.4";

/**
* Constructor for the site
Expand Down
Loading

0 comments on commit 817cf1d

Please sign in to comment.