ckald / jquery-pjax

jQuery PJAX with old-school hashes support
Other
109 stars 16 forks source link

Title tag not updated #4

Open ronheywood opened 12 years ago

ronheywood commented 12 years ago

The title tag is not updated - (FF12, and Chrome)

I don't know how to make a patch but for a fix - my git diff looks like this

@@ -258,6 +258,9 @@
     options.context = $container

     options.success = function(data, textStatus, jqXHR){
+        
+      var $data = $(data);
+      
       if ( options.fragment ) {
         // If they specified a fragment, look for it in the response
         // and pull it out.
@@ -275,11 +278,14 @@

       // Make it happen.
       this.html(data);
-
+    
       // If there's a <title> tag in the response, use it as
       // the page's title.
-      var oldTitle = document.title,
-      title = $.trim( this.find('title').remove().text() );
+      var oldTitle = document.title;
+      
+      title= findAll($data, 'title').last().text()
+      //title = $.trim( data.find('title').remove().text() );
+      
       if ( title ) document.title = title;

       var state = {
@@ -363,6 +369,24 @@
     return pjax.xhr;
   }

+    // Internal: Filter and find all elements matching the selector.
+    //
+    // Where $.fn.find only matches descendants, findAll will test all the
+    // top level elements in the jQuery object as well.
+    //
+    // elems - jQuery object of Elements
+    // selector - String selector to match
+    //
+    // Returns a jQuery object.
+    function findAll(elems, selector) {
+      var results = $()
+      elems.each(function() {
+        if ($(this).is(selector))
+          results = results.add(this)
+        results = results.add(selector, this)
+      })
+      return results
+    }

   pjax.defaults = {
     timeout: 650,
@@ -468,4 +492,5 @@
     $(window).hashchange();
   }

+
 })(jQuery);
0x0h commented 12 years ago

$("#content").bind('success.pjax',function() { $('title').text("Title true"); });