From 9fb5f688edf61b7474c3482f3aae56b7288a0616 Mon Sep 17 00:00:00 2001 From: ilvalle Date: Wed, 18 Sep 2013 09:15:06 +0200 Subject: [PATCH 1/2] Set document title if an ajax fragment has a element --- applications/welcome/static/js/web2py.js | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/applications/welcome/static/js/web2py.js b/applications/welcome/static/js/web2py.js index 43cefd02..e8c9f906 100644 --- a/applications/welcome/static/js/web2py.js +++ b/applications/welcome/static/js/web2py.js @@ -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,19 @@ } }); }, + updatePage: function (xhr, target) { + var t = $('#' + target); + var html = $.parseHTML(xhr.responseText, document, true); + var title = $(html).filter('title').last().text(); + if (title) { + $(html).find('title').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( From 28b4badb9a51afe149fcd76163be716ad38232dd Mon Sep 17 00:00:00 2001 From: Paolo <paolo.valleri@gmail.com> Date: Wed, 18 Sep 2013 17:33:54 +0200 Subject: [PATCH 2/2] concatenation of filter and find for a better <title> discovery --- applications/admin/static/js/web2py.js | 21 +++++++++++++++------ applications/examples/static/js/web2py.js | 21 +++++++++++++++------ applications/welcome/static/js/web2py.js | 5 +++-- 3 files changed, 33 insertions(+), 14 deletions(-) diff --git a/applications/admin/static/js/web2py.js b/applications/admin/static/js/web2py.js index 43cefd02..f2485314 100644 --- a/applications/admin/static/js/web2py.js +++ b/applications/admin/static/js/web2py.js @@ -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( diff --git a/applications/examples/static/js/web2py.js b/applications/examples/static/js/web2py.js index 43cefd02..f2485314 100644 --- a/applications/examples/static/js/web2py.js +++ b/applications/examples/static/js/web2py.js @@ -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( diff --git a/applications/welcome/static/js/web2py.js b/applications/welcome/static/js/web2py.js index e8c9f906..f2485314 100644 --- a/applications/welcome/static/js/web2py.js +++ b/applications/welcome/static/js/web2py.js @@ -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');