Skip to content

Commit

Permalink
History: cached snippets fire before, after and complete queues (thx to
Browse files Browse the repository at this point in the history
  • Loading branch information
vojtech-dobes committed Jan 14, 2014
1 parent ffb6e69 commit 324a28a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
4 changes: 3 additions & 1 deletion history/history.ajax.js
Expand Up @@ -28,9 +28,11 @@ $.nette.ext('history', {
var snippetsExt;
if (this.cache && (snippetsExt = $.nette.ext('snippets'))) {
this.handleUI = function (domCache) {
var snippets = {};
$.each(domCache, function () {
snippetsExt.updateSnippet(this.id, this.html, true);
snippets[this.id] = this.html;
});
snippetsExt.updateSnippets(snippets, true);
$.nette.load();
};
}
Expand Down
35 changes: 17 additions & 18 deletions nette.ajax.js
Expand Up @@ -380,22 +380,8 @@ $.nette.ext('forms', {
// default snippet handler
$.nette.ext('snippets', {
success: function (payload) {
var that = this;
var snippets = [];
var elements = [];
if (payload.snippets) {
for (var i in payload.snippets) {
var $el = this.getElement(i);
if ($el.get(0)) {
elements.push($el.get(0));
}
this.beforeQueue.fire($el);
this.updateSnippet($el, payload.snippets[i]);
this.afterQueue.fire($el);
}
$(elements).promise().done(function () {
that.completeQueue.fire();
});
this.updateSnippets(payload.snippets);
}
}
}, {
Expand All @@ -411,15 +397,28 @@ $.nette.ext('snippets', {
complete: function (callback) {
this.completeQueue.add(callback);
},
updateSnippet: function ($el, html, back) {
if (typeof $el === 'string') {
$el = this.getElement($el);
updateSnippets: function (snippets, back) {
var that = this;
var elements = [];
for (var i in snippets) {
var $el = this.getElement(i);
if ($el.get(0)) {
elements.push($el.get(0));
}
this.updateSnippet($el, snippets[i], back);
}
$(elements).promise().done(function () {
that.completeQueue.fire();
});
},
updateSnippet: function ($el, html, back) {
// Fix for setting document title in IE
if ($el.is('title')) {
document.title = html;
} else {
this.beforeQueue.fire($el);
this.applySnippet($el, html, back);
this.afterQueue.fire($el);
}
},
getElement: function (id) {
Expand Down

0 comments on commit 324a28a

Please sign in to comment.