From b89a7ee8b956c96a1dcee995ea840feddc5d4b27 Mon Sep 17 00:00:00 2001 From: Pierre Frisch Date: Thu, 22 Dec 2011 07:25:50 -0800 Subject: First commit of Ninja to ninja-internal Signed-off-by: Valerio Virgillito --- js/components/menu/menu-item.reel/menu-item.js | 160 +++++++++++++++++++++++++ 1 file changed, 160 insertions(+) create mode 100644 js/components/menu/menu-item.reel/menu-item.js (limited to 'js/components/menu/menu-item.reel/menu-item.js') diff --git a/js/components/menu/menu-item.reel/menu-item.js b/js/components/menu/menu-item.reel/menu-item.js new file mode 100644 index 00000000..64a89a6a --- /dev/null +++ b/js/components/menu/menu-item.reel/menu-item.js @@ -0,0 +1,160 @@ +/* +This file contains proprietary software owned by Motorola Mobility, Inc.
+No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.
+(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. +
*/ + +var Montage = require("montage/core/core").Montage; +var Component = require("montage/ui/component").Component; + +exports.MenuItem = Montage.create(Component, { + + data: { + value: null + }, + + _enabled: { + value: null + }, + + enabled: { + get: function() { + return this._enabled; + }, + set: function(value) { + if(value !== this._enabled) { + this._enabled = value; + this.needsDraw = true; + } + } + }, + + _checked: { + value: null + }, + + checked: { + get: function() { + return this._checked; + }, + set: function(value) { + /* + if( Object.prototype.toString.call( value ) === '[object Array]' ) { + value = value.indexOf(this.data.displayText + "Panel") >= 0; + } + */ + + if(this._checked !== value) { + this._checked = value; + this.needsDraw = true; + } + } + }, + + submenu: { + value: false + }, + + subentries: { + value: [] + }, + + prepareForDraw: { + value: function() { + if(!this.data) return; + + if(this.data.separator) { + this.element.classList.add("itemSeparator"); + this.itemBackground.classList.remove("menubg"); + this.itemBackground.classList.add("separator"); + + return; + + } + + // Binding the checked to the assigned bound property + if(this.data.checked) { + Object.defineBinding(this, "checked", { + boundObject: this.application.ninja.appModel, + boundObjectPropertyPath: this.data.checked.boundProperty + }); + + } + + if(this.data.enabled.boundProperty) { + Object.defineBinding(this, "enabled", { + boundObject: this.application.ninja[this.data.enabled.boundObj], + boundObjectPropertyPath: this.data.enabled.boundProperty + }); + + } else { + this.enabled = this.data.enabled; + } + + if(this.data.submenu) { + this.submenu = true; + + this.subentries = this.data.entries; + + this.subMenu.classList.add("subMenu"); + this.element.addEventListener("mouseover", this, false); + this.element.addEventListener("mouseout", this, false); + + } + + + this.itemText.innerHTML = this.data.displayText; + this.element.addEventListener("mousedown", this, true); + } + }, + + draw: { + value: function() { + + if(this.enabled) { + this.element.classList.remove("disabled"); + } else { + this.element.classList.add("disabled"); + } + + if(this.checked) { + this.itemBackground.classList.add("checked"); + } else { + this.itemBackground.classList.remove("checked"); + } + + if(this.submenu) { + this.itemBackground.classList.add("submenu"); + } + } + }, + + captureMousedown: { + value: function(event) { + + if(this.data.radio && this.checked) return; + + if(this.enabled || !this.submenu) { + if(this.data.action) { + NJevent ( this.data.action ); + } else if(this.checked !== null) { + this.checked = !this.checked; + } + } + + } + }, + + handleMouseover: { + value: function() { + if(this.enabled) this.subMenu.style.display = "block"; + } + }, + + handleMouseout: { + value: function() { + this.subMenu.style.display = "none"; + } + } + +}); \ No newline at end of file -- cgit v1.2.3