Merge pull request #216 from ilvalle/ajax_title

Set document title when an ajax fragment has got a <title> element
This commit is contained in:
mdipierro
2013-09-19 12:09:01 -07:00
3 changed files with 45 additions and 18 deletions

View File

@@ -303,12 +303,7 @@
},
'complete': function (xhr, status) {
web2py.fire(element, 'ajax:complete', [xhr, status], target);
var html = xhr.responseText;
var content = xhr.getResponseHeader('web2py-component-content');
var t = $('#' + target);
if(content == 'prepend') t.prepend(html);
else if(content == 'append') t.append(html);
else if(content != 'hide') t.html(html);
web2py.updatePage(xhr, target); /* Parse and load the html received */
web2py.trap_form(action, target);
web2py.trap_link(target);
web2py.ajax_init('#' + target);
@@ -378,6 +373,20 @@
}
});
},
updatePage: function (xhr, target) {
var t = $('#' + target);
var html = $.parseHTML(xhr.responseText, document, true);
var title_elements = $(html).filter('title').add($(html).find('title'));
var title = title_elements.last().text();
if (title) {
title_elements.remove(); /* Remove any title elements from the response */
document.title = $.trim(title); /* Set the new document title */
}
var content = xhr.getResponseHeader('web2py-component-content');
if(content == 'prepend') t.prepend(xhr.responseText);
else if(content == 'append') t.append(xhr.responseText);
else if(content != 'hide') t.html(html);
},
calc_entropy: function (mystring) {
/* calculate a simple entropy for a given string */
var csets = new Array(

View File

@@ -303,12 +303,7 @@
},
'complete': function (xhr, status) {
web2py.fire(element, 'ajax:complete', [xhr, status], target);
var html = xhr.responseText;
var content = xhr.getResponseHeader('web2py-component-content');
var t = $('#' + target);
if(content == 'prepend') t.prepend(html);
else if(content == 'append') t.append(html);
else if(content != 'hide') t.html(html);
web2py.updatePage(xhr, target); /* Parse and load the html received */
web2py.trap_form(action, target);
web2py.trap_link(target);
web2py.ajax_init('#' + target);
@@ -378,6 +373,20 @@
}
});
},
updatePage: function (xhr, target) {
var t = $('#' + target);
var html = $.parseHTML(xhr.responseText, document, true);
var title_elements = $(html).filter('title').add($(html).find('title'));
var title = title_elements.last().text();
if (title) {
title_elements.remove(); /* Remove any title elements from the response */
document.title = $.trim(title); /* Set the new document title */
}
var content = xhr.getResponseHeader('web2py-component-content');
if(content == 'prepend') t.prepend(xhr.responseText);
else if(content == 'append') t.append(xhr.responseText);
else if(content != 'hide') t.html(html);
},
calc_entropy: function (mystring) {
/* calculate a simple entropy for a given string */
var csets = new Array(

View File

@@ -303,12 +303,7 @@
},
'complete': function (xhr, status) {
web2py.fire(element, 'ajax:complete', [xhr, status], target);
var html = xhr.responseText;
var content = xhr.getResponseHeader('web2py-component-content');
var t = $('#' + target);
if(content == 'prepend') t.prepend(html);
else if(content == 'append') t.append(html);
else if(content != 'hide') t.html(html);
web2py.updatePage(xhr, target); /* Parse and load the html received */
web2py.trap_form(action, target);
web2py.trap_link(target);
web2py.ajax_init('#' + target);
@@ -378,6 +373,20 @@
}
});
},
updatePage: function (xhr, target) {
var t = $('#' + target);
var html = $.parseHTML(xhr.responseText, document, true);
var title_elements = $(html).filter('title').add($(html).find('title'));
var title = title_elements.last().text();
if (title) {
title_elements.remove(); /* Remove any title elements from the response */
document.title = $.trim(title); /* Set the new document title */
}
var content = xhr.getResponseHeader('web2py-component-content');
if(content == 'prepend') t.prepend(xhr.responseText);
else if(content == 'append') t.append(xhr.responseText);
else if(content != 'hide') t.html(html);
},
calc_entropy: function (mystring) {
/* calculate a simple entropy for a given string */
var csets = new Array(