concatenation of filter and find for a better <title> discovery

This commit is contained in:
Paolo
2013-09-18 17:33:54 +02:00
parent 9fb5f688ed
commit 28b4badb9a
3 changed files with 33 additions and 14 deletions
+15 -6
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(
+15 -6
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(
+3 -2
View File
@@ -376,9 +376,10 @@
updatePage: function (xhr, target) {
var t = $('#' + target);
var html = $.parseHTML(xhr.responseText, document, true);
var title = $(html).filter('title').last().text();
var title_elements = $(html).filter('title').add($(html).find('title'));
var title = title_elements.last().text();
if (title) {
$(html).find('title').remove(); /* Remove any title elements from the response */
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');