Skip to content

Commit

Permalink
Merge pull request #3 from cjsewell/patch-2
Browse files Browse the repository at this point in the history
Use .empty().append() instead of .html()
  • Loading branch information
Mark Guinn committed Oct 30, 2014
2 parents b30e8c0 + d10a890 commit a58683b
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions javascript/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@
// handle ajax responses ///////////////////////////////////////////////////////////////////////////////////////

var replaceRegion = function(html, key) {
var $region = $(html),
var $foundRegion = false,
$region = $(html),
explicit = $('[data-ajax-region="' + key + '"]'),
explicit2 = $('[data-ajax-region^="' + key + ':"]'),
id = $region.length > 0 ? $region.prop('id') : '',
Expand All @@ -137,15 +138,19 @@
// If there is one (or more) element with a data-ajax-region attribute it
// means we know for sure it's a match to this region, usually because the
// watch was set up on that particular element.
explicit.html(html=='' ? html : $region.html());
$foundRegion = explicit;
} else if (explicit2.length > 0) {
explicit2.html(html=='' ? html : $region.html());
$foundRegion = explicit2;
} else if (id) {
// second best is if the root element of the new content contains an id
$('#' + id).html($region.html());
$foundRegion = $('#' + id);
} else if (classes.length > 0) {
// otherwise, we try to match by css classes
$('.' + classes.join('.')).html($region.html());
$foundRegion = $('.' + classes.join('.'));
}

if ($foundRegion && $foundRegion.length){
$foundRegion.empty().append($region.html());
} else {
// finally we fail silently but leave a warning for the developer
if (typeof(console) != 'undefined' && typeof(console.warn) == 'function') {
Expand Down

0 comments on commit a58683b

Please sign in to comment.