Commits

Rufus Pollock committed df16e39

[app][s]: set title on 'pages' using sammy.title.js plugin.

  • Participants
  • Parent commits 7e0ab0f
  • Branches couchdb

Comments (0)

Files changed (3)

File _attachments/index.html

 <html xmlns="http://www.w3.org/1999/xhtml">
 
 <head>
-  <title>{{blogName}}</title>
+  <title>Comment On It</title>
   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
   <link rel="shortcut icon" href="http://assets.okfn.org/gfx/logo/favicon.ico" type="image/x-icon" />
   <!--
 <script src="script/vendor/jquery-1.4.4.min.js" type="text/javascript" charset="utf-8"></script>
 <script src="/_utils/script/jquery.couch.js?0.8.0"></script>
 <script src="script/vendor/sammy/sammy.js" type="text/javascript" charset="utf-8"></script>
-<script src="script/vendor/sammy/plugins/sammy.mustache.js" type="text/javascript" charset="utf-9"></script>
+<script src="script/vendor/sammy/plugins/sammy.mustache.js" type="text/javascript" charset="utf-8"></script>
+<script src="script/vendor/sammy/plugins/sammy.title.js" type="text/javascript" charset="utf-8"></script>
 <script src="script/app.js" type="text/javascript" charset="utf-8"></script>
 </body>
 </html>

File _attachments/script/app.js

 
 	var app = $.sammy('.entry-content', function() {
 		this.use('Mustache', 'ms');
-		
+		this.use('Title');
+		this.setTitle(function(title) {
+			return [title, ' - Comment On It'].join('');
+		});
+
 		this.get('#/', function(context) {
-			var context = this;
+			this.title('Home');
 			db.view('commentonit/recent-items', {
 				include_docs: true,
 				success: function(resp) {
 		});
 
 		this.get('#/text/:id', function(context) {
+			var self = this;
+			this.title(' - View');
 			docid = this.params['id'];
 			db.openDoc(docid, {
 				success: function(doc) {
+					self.title(doc.title + ' - View');
 					context.partial('templates/text/view.ms', doc);
 				}
 			});

File _attachments/script/vendor/sammy/plugins/sammy.title.js

+(function($) {
+
+  Sammy = Sammy || {};
+
+  // Sammy.Title is a very simple plugin to easily set the document's title.
+  // It supplies a helper for setting the title (`title()`) within routes,
+  // and an app level method for setting the global title (`setTitle()`)
+  Sammy.Title = function() {
+
+    // setTitle allows setting a global title or a function that modifies the
+    // title for each route/page.
+    //
+    // ### Example
+    //
+    //    // setting a title prefix
+    //    $.sammy(function() {
+    //
+    //      this.setTitle('My App -');
+    //
+    //      this.get('#/', function() {
+    //        this.title('Home'); // document's title == "My App - Home"
+    //      });
+    //    });
+    //
+    //    // setting a title with a function
+    //    $.sammy(function() {
+    //
+    //      this.setTitle(function(title) {
+    //        return [title, " /// My App"].join('');
+    //      });
+    //
+    //      this.get('#/', function() {
+    //        this.title('Home'); // document's title == "Home /// My App";
+    //      });
+    //    });
+    //
+    this.setTitle = function(title) {
+      if (!$.isFunction(title)) {
+        this.title_function = function(additional_title) {
+          return [title, additional_title].join(' ');
+        }
+      } else {
+        this.title_function = title;
+      }
+    };
+
+    // *Helper* title() sets the document title, passing it through the function
+    // defined by setTitle() if set.
+    this.helper('title', function() {
+      var new_title = $.makeArray(arguments).join(' ');
+      if (this.app.title_function) {
+        new_title = this.app.title_function(new_title);
+      }
+      document.title = new_title;
+    });
+
+  };
+
+})(jQuery);