1 /*
  2  *  Copyright (C) 2008-2009 WaveMaker Software, Inc.
  3  *
  4  *  This file is part of the WaveMaker Client Runtime.
  5  *
  6  *  Licensed under the Apache License, Version 2.0 (the "License");
  7  *  you may not use this file except in compliance with the License.
  8  *  You may obtain a copy of the License at
  9  *
 10  *      http://www.apache.org/licenses/LICENSE-2.0
 11  *
 12  *  Unless required by applicable law or agreed to in writing, software
 13  *  distributed under the License is distributed on an "AS IS" BASIS,
 14  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15  *  See the License for the specific language governing permissions and
 16  *  limitations under the License.
 17  */
 18 dojo.provide("wm.base.widget.dijit.Dijit");
 19 dojo.require("wm.base.widget.Box");
 20 // include tooltip so the master tooltip is created right away
 21 dojo.require("dijit.Tooltip");
 22 
 23 // style dijit a11y node to hidden so that it does not interfere with wm.box
 24 // a11yTestNode is created in dijit.util.wai and if it is changed to be 
 25 // style="visibility: hidden" there then this code can be removed 
 26 // FIXME: make a dojo ticket to make this happen
 27 // hide master tooltip node also
 28 dojo.addOnLoad(function() {
 29 	var invisible = function(inId) {
 30 		var n = dojo.byId(inId);
 31 		n&&(n.style.visibility='hidden');
 32 	}
 33 	invisible('a11yTestNode');
 34 });
 35 
 36 // Note: dijit events and properties must be exposed manually.
 37 // This gives finer control over what is exposed via our API.
 38 /**
 39 	Wrapper class to contain a Dijit.
 40 	@name wm.Dijit
 41 	@class
 42 	@extends wm.Box
 43 */
 44 dojo.declare("wm.Dijit", wm.Box, {
 45 	/** @lends wm.Dijit.prototype */
 46 	dijitClass: null,
 47 	// FIXME: ignore props not intended for dijit
 48 	nonDijitProps: {
 49 		name: 1,
 50 		flex: 1,
 51 		box: 1,
 52 		left: 1,
 53 		top: 1,
 54 		width: 1,
 55 		height: 1,
 56 		owner: 1,
 57 		parent: 1,
 58 		publishClass: 1,
 59 		dijitClass: 1,
 60 		domNode: 1,
 61 		id: 1
 62 	},
 63 	prepare: function(inProps) {
 64 		this.dijitProps = {};
 65 		for (var i in inProps)
 66 			if (!(i in this.nonDijitProps))
 67 				this.dijitProps[i] = inProps[i];
 68 		this.inherited(arguments);
 69 	},
 70 	destroy: function() {
 71 		this.dijit.destroy();
 72 		this.inherited(arguments);
 73 	},
 74 	setDomNode: function(inDomNode) {
 75 		inDomNode = this.initDijit(inDomNode);
 76 		this.inherited(arguments);
 77 	},
 78 	initDijit: function(inDomNode) {
 79 		var n = document.createElement('div');
 80 		inDomNode.appendChild(n);
 81 		var p = dojo.mixin({srcNodeRef: n}, this.getProperties());
 82 		this.dijit = this.dijitClass ? new this.dijitClass(p) : null;
 83 		this.setEvents();
 84 		return inDomNode;
 85 	},
 86 	// return properties intended for the dijit
 87 	getProperties: function() {
 88 		return this.dijitProps;
 89 	},
 90 	// connect our events to dijit events of the same name
 91 	setEvents: function() {
 92 		for (var n in this.dijit) {
 93 			// only if n starts with "on" (indexOf == 0)
 94 			if (!n.indexOf("on")) {
 95 				// we match "_on<Event>" first
 96 				var e = '_' + n;
 97 				if (!this[e])
 98 					// we match "on<Event>" second
 99 					e = n;
100 				// connect our facade event to the dijit event
101 				if (this[e])
102 					this.connect(this.dijit, n, this, e);
103 			}
104 		}
105 	}
106 });
107 
108 wm.Object.extendSchema(wm.Dijit, {
109 	/*dojoAttachEvent: {ignore: 1},
110 	dojoAttachPoint: {ignore: 1},
111 	baseClass: {ignore: 1},
112 	widgetsInTemplate: {ignore: 1},
113 	templateString: {ignore: 1},
114 	alt: {ignore: 1},
115 	dir: {ignore: 1},
116 	type: {ignore: 1},
117 	waiRole: {ignore: 1},
118 	waiState: {ignore: 1},
119 	intermediateChanges:  {ignore: 1},*/
120 	box: {ignore: 1}
121 });
122 
123 dojo.declare("wm.DijitWrapper", wm.Dijit, {
124 });
125