Permalink
Browse files

added foundation for toolbar widget

  • Loading branch information...
1 parent 63ca661 commit 864b85addb0c425f15950375ec201773b30b137e @aaronj1335 aaronj1335 committed Apr 30, 2012
View
@@ -0,0 +1,19 @@
+define([
+ 'path!gloss:widgets/widget',
+ 'path!gloss:tmpl!widgets/toolbar/toolbar.mtpl',
+ 'path!gloss:css!widgets/toolbar/toolbar.css'
+], function(Widget, template) {
+
+ return Widget.extend({
+
+ defaults: {
+ tabs: [] // list of strings
+ },
+
+ nodeTemplate: template,
+
+ create: function() {
+ this.$node.addClass('toolbar');
+ }
+ });
+});
@@ -0,0 +1,13 @@
+/*global test, asyncTest, ok, equal, deepEqual, start, module, strictEqual, notStrictEqual, raises*/
+require([
+ 'path!vendor:jquery',
+ 'path!gloss:widgets/toolbar'
+], function($, ToolBar) {
+ test('instantiating toolbar using default template', function() {
+ ToolBar(undefined, {
+ tabs: ['Dishwasher', 'Plausible Deniability']
+ }).prependTo('body');
+ });
+
+ start();
+});

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -0,0 +1,26 @@
+@height: 40px;
+
+.toolbar {
+ border-bottom: 1px solid black;
+ height: @height;
+}
+
+.toolbar .tabs {
+ display: inline-block;
+}
+
+.toolbar .controls {
+ float: right;
+ height: @height;
+}
+
+.toolbar .tabs .tab {
+ display: inline-block;
+}
+
+.toolbar .logo, .toolbar .app-logo {
+ width: 150px;
+ height: @height;
+ display: inline-block;
+ background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJYAAAAtCAYAAABMDJJUAAAM70lEQVR4nO2bbXBUVZ7Gf//OC5eXhG5eQgJiugnDJiyLJOJqYJQQ15GOMzrJMkPBTEqIhQKuKzirNcZZVLYMu04JWJRhKWqIFmOYnWEJIJPoWoS4OgkKJnGGNalxoRMdTCSO3RBiLknTZz/c7qSTdN7TUsvc35fcOuf0Oefe89z/ec65J6KUwsRkrLFc7w6Y3JiYwjIJC6awTMKCKSyTsGAKyyQsmMIyCQumsEzCgiks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w7cHs/NtlGe0Trg1jv6mDZjTszF6WC4z6Y3N/DOlboVKqIVkpx2pI2w1rjsC2f4E0lHL0FNVEv7m0WqXPR0yLP7pEaSKpQ54XRUQTkWoRaRcRpxhms9CfvWao9QxGxRdBg3aV5lePk3KvMWVqUYG+tFHHS0bEJnaGHYCW030XCL3vYdX5LSRF5HN0hmO4R2h8AGgsW7r4Y0fcpB7mPW7uQud4QYMOAoab8XH9Pltx7LJ2+bA/lu0eTj+Gy5idxxKhiaDtCYPv5yh1pETkSjFM6rUEfvmgUo8PKgwR2UFff1cHZKo+kXJ0PJ4hyyd04NleqXpsU6xeIqnzgX8OSpfHveXYWpfz2hTbYGIRR7YVjuiDfZvs87u4BfHfnj+tKSIozdfZ0dBxzeeyREQ7oqMsdgCUXf+fpa96vowmHhpRzyVKyPrWt+xn1nTDi717d5Y6caJsOP0ZDmN4HsvrhsggYXkB8T/Idh0m9SrfMaQ3Vyn1hIi8iLHrrgF1Sg3dowyHl0OYeoCDvYQGgC1yORf2FQ0lAilXycgO+nW26TANAJ/P57FYLFZLVLRdi/JHHcCnX6767PxrOV9O+ofl3La4GBKRn51zU/5Epqo8WgMgjnUaf/dCIbNmGqL6urwunKKCG/QEabiRR1sPM/1itnouKWRkGEumzZqVHOP7Wnc1uRtEHNrMmR12iYqyReLl0qW2Orfb3b05GxyRAK62GhF9XEz3C+9r1DlgTwj3qVZTWENAnPuzaf/IQ6dD547NrxDjTuXoFMdwVnffFOI8ms2i+woZF9nLlnjhwpEitW9l3jfSD1NYAyNrG3dgT+z2eN46D0fmp4zFWflwIov/KZnJsQ6uaTqdTTqf76oZrscbVfumsPpHlvxnKplZ5Vzz6nRcbOLc67vVkdEd/flLwRSWSVi4Yf+v0OT6YgrLJCyYwjIJC6awTMKCKSyTsPB/eFalMUbXGnoAAAAASUVORK5CYII=");
+}
@@ -0,0 +1,16 @@
+<div>
+ <div class=controls>
+ <div class=app-logo></div>
+ </div>
+
+ <a href="<%= data.logoHref || '/' %>" class=logo></a>
+
+ <div class=tabs>
+ <% _.each(data.tabs, function(tab) { %>
+ <a href="<%= _.isObject(tab)? tab.href : 'javascript:void(0)' %>" class=tab>
+ <%= _.isFunction(tab)? tab() : _.isObject(tab)? tab.content : tab %>
+ </a>
+ <% }); %>
+ </div>
+
+</div>
View
@@ -247,8 +247,9 @@ define([
nodeTemplate: '<div>',
init: function(node) {
+ var html;
if (node == null) {
- this.$node = $(this.nodeTemplate);
+ this.$node = $(this._compiledHtml());
} else {
this.$node = $(node);
}
@@ -261,6 +262,12 @@ define([
this.node = this.$node.get(0);
},
+ _compiledHtml: function() {
+ return _.isFunction(this.nodeTemplate)?
+ this.nodeTemplate(this.options || this.defaults || {}) :
+ this.nodeTemplate;
+ },
+
hide: function(params) {
this.$node.addClass('hidden');
return this;
@@ -323,6 +330,11 @@ define([
this.$node.appendTo(obj);
}
return this;
+ },
+
+ prependTo: function(obj) {
+ this.$node.prependTo(obj.$node? obj.$node : obj);
+ return this;
}
});
@@ -353,46 +365,49 @@ define([
},
init: function(node, options, extension) {
- var name, value, parentWidget, $tmpl, classes, i;
+ var name, value, parentWidget, $tmpl, classes, i, opts, $node;
if (extension != null) {
_.extend(this, extension);
}
+ this.options = opts = recursiveMerge({}, this.defaults, options);
+
BaseWidget.prototype.init.call(this, node);
- this.id = this.$node.attr('id');
+ $node = this.$node;
+
+ this.id = $node.attr('id');
if (this.id == null) {
this.id = _.uniqueId('widget');
- this.$node.attr('id', this.id);
+ $node.attr('id', this.id);
}
- this.options = recursiveMerge({}, this.defaults, options);
- if (this.defaults.bindOnMethodHandlers) {
- for (name in this.options) {
- if (this.options.hasOwnProperty(name)) {
- value = this.options[name];
+ if (opts.bindOnMethodHandlers) {
+ for (name in opts) {
+ if (opts.hasOwnProperty(name)) {
+ value = opts[name];
if (name.substr(0, 2) === 'on' && $.isFunction(value)) {
- this.$node.on(name.substr(2).toLowerCase(), value);
+ $node.on(name.substr(2).toLowerCase(), value);
}
}
}
}
- if (this.options.populateEmptyNode && !this.$node.children().length && node) {
- $tmpl = $(this.nodeTemplate);
+ if (opts.populateEmptyNode && !$node.children().length && node) {
+ $tmpl = $(this._compiledHtml());
classes = $tmpl.attr('class').split(' ');
for (i = classes.length-1; i >= 0; i--) {
- this.$node.addClass(classes[i]);
+ $node.addClass(classes[i]);
}
- this.$node.html($tmpl.html());
+ $node.html($tmpl.html());
}
- if (this.options.bindAll) {
+ if (opts.bindAll) {
_.bindAll(this);
}
- parentWidget = this.options.parentWidget;
- delete this.options.parentWidget;
+ parentWidget = opts.parentWidget;
+ delete opts.parentWidget;
if (parentWidget) {
registry.add(this, parentWidget, []);
} else {

0 comments on commit 864b85a

Please sign in to comment.