Meta Tags

by jcreamer898

HTML

<script src="http://ajax.microsoft.com/ajax/jquery.templates/beta1/jquery.tmpl.min.js"></script>
<script src="http://github.com/downloads/SteveSanderson/knockout/knockout-1.2.1.js"></script>
<div id="metaProperties" data-bind="template: { name: 'metaTemplate' }">

</div>

<script id="metaTemplate" type="text/html">
    
    {{each(i, tags) metaTags()}}
        <div>
            <select id="metaTypes" data-bind="options: metaTypes"></select>
            <input type="text" id="value" data-bind="value: value" />
        </div>
    {{/each}}
</script>

<button data-bind="click: function(){ addMeta() }">
    Add Meta
</button>

JavaScript

var metaTag = function(){
    this.type = ko.observable('');
    this.value = ko.observable('');
}
    
var metaViewModel = {
    metaTypes : ko.observableArray([]),
    metaTags : ko.observableArray([])
};
metaViewModel.metaTypes.push('Description');    
metaViewModel.metaTypes.push('Keywords');    

var metaManager = {
    addMeta: function(){
        this.metaTags.push(new metaTag());
    }
};

metaViewModel = $.extend({},metaViewModel, metaManager);

$(function(){
    ko.applyBindings(metaViewModel);   
});