Created
October 8, 2014 02:05
-
-
Save carlosrymer/e2c324ade735872badff to your computer and use it in GitHub Desktop.
Factory to Handle Page Metadata in an AngularJS App
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
'use strict'; | |
/** | |
* Page Metadata Factory | |
*/ | |
function PageMetadataFactory() { | |
/** | |
* Metadata object | |
* @type {object} | |
*/ | |
var metadata = { | |
description: null, | |
image: null, | |
keywords: null, | |
noFollow: null, | |
notFound: null, | |
title: null, | |
url: null | |
}; | |
/** | |
* Sets all metadata to null so the default can take place | |
*/ | |
function clear() { | |
metadata.description = null; | |
metadata.image = null; | |
metadata.keywords = null; | |
metadata.noFollow = null; | |
metadata.notFound = null; | |
metadata.title = null; | |
metadata.url = null; | |
} | |
/** | |
* Sets metadata description | |
* @param {string} description | |
*/ | |
function setDescription(description) { | |
metadata.description = description; | |
} | |
/** | |
* Sets metadata image | |
* @param {string} image | |
*/ | |
function setImage(image) { | |
metadata.image = image; | |
} | |
/** | |
* Sets metadata keywords | |
* @param {string} keywords | |
*/ | |
function setKeywords(keywords) { | |
metadata.keywords = keywords; | |
} | |
/** | |
* Sets metadata noFollow | |
* @param {string} noFollow | |
*/ | |
function setNoFollow(noFollow) { | |
metadata.noFollow = noFollow; | |
} | |
/** | |
* Sets metadata notFound | |
* @param {string} notFound | |
*/ | |
function setNotFound(notFound) { | |
metadata.notFound = notFound; | |
} | |
/** | |
* Sets metadata title | |
* @param {string} title | |
*/ | |
function setTitle(title) { | |
metadata.title = title; | |
} | |
/** | |
* Sets metadata url | |
* @param {string} url | |
*/ | |
function setUrl(url) { | |
metadata.url = url; | |
} | |
return { | |
clear: clear, | |
data: metadata, | |
setDescription: setDescription, | |
setImage: setImage, | |
setKeywords: setKeywords, | |
setNoFollow: setNoFollow, | |
setNotFound: setNotFound, | |
setTitle: setTitle, | |
setUrl: setUrl | |
}; | |
} | |
/** | |
* Page Metadata Controller | |
* @param {object} PageMetadata | |
*/ | |
function PageMetadataController(PageMetadata) { | |
/** | |
* Metadata object | |
* @type {object} | |
*/ | |
this.data = PageMetadata.data; | |
} | |
// Inject dependency | |
PageMetadataController.$inject = ['PageMetadata']; | |
// Register module | |
angular.module('app.pageMetadata', []) | |
.controller('PageMetadataCtrl', PageMetadataController) | |
.factory('PageMetadata', PageMetadataFactory); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment