diff --git a/Gruntfile.js b/Gruntfile.js index b024431..477abe5 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -190,7 +190,7 @@ module.exports = function (grunt) { uglify: { options: { - sourceMap: true, + sourceMap: false, sourceMapIncludeSources: true, enclose: { window: "window" }, banner: "/*! <%= pkg.name %> - v<%= pkg.version %> - " + @@ -309,10 +309,8 @@ module.exports = function (grunt) { grunt.registerTask("build", [ "clean:beforeBuild", - "less:production", - "uglify", - "copyBuild", - "processhtml:production" + "concat", + "uglify" ]); grunt.registerTask("release", [ diff --git a/bower.json b/bower.json index 896fd3a..f0a493a 100644 --- a/bower.json +++ b/bower.json @@ -1,7 +1,7 @@ { "name": "angular-title", "description": "Dynamically change the page title when using ngRoute", - "version": "0.0.0", + "version": "0.0.1", "homepage": "https://github.com/thisissoon/angular-title", "license": "MIT", "main": "dist/angular-title.js", @@ -17,12 +17,12 @@ "package.json", "scripts.json" ], - "private": true, + "private": false, "dependencies": { - "angular": "~1.3.5", - "angular-route": "~1.3.5" + "angular": "^1.2.17", + "angular-route": "^1.2.17" }, "devDependencies": { - "angular-mocks": "~1.3.5" + "angular-mocks": "^1.2.17" } } diff --git a/dist/angular-title.js b/dist/angular-title.js new file mode 100644 index 0000000..96f6369 --- /dev/null +++ b/dist/angular-title.js @@ -0,0 +1,119 @@ +/*! angular-title - v0.0.1 - 2015-03-16 */ +"use strict"; +/** + * Angular Title dyamically updates the document title when navigating views + * defined in `ngRoute`'s `$routeProvider`. Simply define the title of the + * page in your `$routeProvider` config using the `title` key. + * + * If you place the name of the site inside the `title` element the directive + * will append this string to the end of the title on each page e.g. + * `My Site Name` would become `pageone - My Site Name`. The + * original string is also used as a fallback if the title attribute for a + * route has not been defined. In that case the title for that route would be + * `My Site Name`. + * + * @example + * $routeProvider + * .when("/pageone", { + * controller: "pageoneCtrl" + * title: "pageone", + * templateUrl: "partials/pageone.html" + * }) + * .when("/pagetwo", { + * controller: "pagetwoCtrl" + * title: "pagetwo", + * templateUrl: "partials/pagetwo.html" + * }) + * @main sn.title + * @module sn.title + * @author SOON_ + */ +angular.module("sn.title", []) + +/** + * Title text to display when $routeChangeError + * event occurs. + * @constant + * @property ROUTE_CHANGE_ERROR_TITLE + * @type {String} + */ +.constant("ROUTE_CHANGE_ERROR_TITLE", "Page Error") + +/** + * Title element directive which updates it's content to + * update the page title. Place the name of you site inside + * the directive and it will be appended to the end of every + * page title. eg. Page Title - My Site Name + * @example + * My Site Name + * @class title + * @module sn.title + * @author SOON_ + */ +.directive("title", [ + "$rootScope", + "ROUTE_CHANGE_ERROR_TITLE", + /** + * @constructor + * @param {Service} $rootScope + * @param {String} ROUTE_CHANGE_ERROR_TITLE + */ + function ($rootScope, ROUTE_CHANGE_ERROR_TITLE) { + return { + restrict: "E", + link: function ($scope, $element) { + + /** + * The name of the site to use to append + * to all page titles. + * @property siteTitle + * @type {String} + * @example + * My Site Name + */ + var siteTitle = $element.html().length > 0 ? $element.html() : undefined ; + + /** + * Update the content of the title element to the value + * of the title key in the object of the current route + * @method onRouteChangeSuccess + * @param {event} $event '$routeChangeSuccess' event from ngRoute service + * @param {Object} current The requested route object + */ + var onRouteChangeSuccess = function onRouteChangeSuccess($event, current){ + + // route title & site title + if (current && current.$$route && current.$$route.title && siteTitle){ + $element.html(current.$$route.title + " - " + siteTitle); + + // route title only + } else if (current && current.$$route && current.$$route.title){ + $element.html(current.$$route.title); + + // site title only + } else if (siteTitle){ + $element.html(siteTitle); + } + }; + + /** + * Update the content of the title element to the value + * of ROUTE_CHANGE_ERROR_TITLE constant when $routeChangeError + * event is triggered. + * @method onRouteChangeError + */ + var onRouteChangeError = function onRouteChangeError(){ + if (siteTitle){ + $element.html(ROUTE_CHANGE_ERROR_TITLE + " - " + siteTitle); + } else { + $element.html(ROUTE_CHANGE_ERROR_TITLE); + } + }; + + $rootScope.$on("$routeChangeSuccess", onRouteChangeSuccess); + $rootScope.$on("$routeChangeError", onRouteChangeError); + + } + }; + } +]); diff --git a/dist/angular-title.min.js b/dist/angular-title.min.js new file mode 100644 index 0000000..cb4aec5 --- /dev/null +++ b/dist/angular-title.min.js @@ -0,0 +1,2 @@ +/*! angular-title - v0.0.1 - 2015-03-16 */ +!function(){"use strict";angular.module("sn.title",[]).constant("ROUTE_CHANGE_ERROR_TITLE","Page Error").directive("title",["$rootScope","ROUTE_CHANGE_ERROR_TITLE",function(a,b){return{restrict:"E",link:function(c,d){var e=d.html().length>0?d.html():void 0,f=function(a,b){b&&b.$$route&&b.$$route.title&&e?d.html(b.$$route.title+" - "+e):b&&b.$$route&&b.$$route.title?d.html(b.$$route.title):e&&d.html(e)},g=function(){d.html(e?b+" - "+e:b)};a.$on("$routeChangeSuccess",f),a.$on("$routeChangeError",g)}}}])}(window); \ No newline at end of file diff --git a/package.json b/package.json index c10ff82..4d5c9ce 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "angular-title", "private": false, - "version": "0.0.0", + "version": "0.0.1", "description": "Dynamically change the page title when using ngRoute", "repository": "https://github.com/thisissoon/angular-title", "license": "MIT",