File size: 2,274 Bytes
597ee18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/**

 * Glimpse

 * 

 * A lightweight element wrapper that has no dependencies, no context and 

 * no data binding, but is able to apply a super-simple template.

 * 

 * It's invisible to View, so it's great for creating components, and you 

 * can bind data to it using the `cb-data` attribute to set the data 

 * property of your Glimpse

 * 

 * @class		Glimpse

 * @memberof	conbo

 * @augments	conbo.EventDispatcher

 * @author 		Neil Rackett

 * @param 		{Object} options - Object containing initialisation options

 */
conbo.Glimpse = conbo.EventDispatcher.extend(
/** @lends conbo.Glimpse.prototype */
{
	/**

	 * @member		{*}			data - Arbitrary data

	 * @memberof	conbo.Glimpse.prototype

	 */

	/**

	 * @member		{string}	template - Template to apply to the Glimpse's element

	 * @memberof	conbo.Glimpse.prototype

	 */

	/**

	 * Constructor: DO NOT override! (Use initialize instead)

	 * @param {Object} [options]

	 * @private

	 */
	__construct: function(options)
	{
		this.__setEl(options.el || document.createElement(this.tagName));
		
		if (this.template)
		{
			this.el.innerHTML = this.template;
		}
	},
	
	/**

	 * When a new instance of this class is created without specifying an element,

	 * it will use this tag name (the default is `div`)

	 * @type	{string}

	 */
	get tagName()
	{
		return this.__tagName || 'div';
	},
	
	set tagName(value)
	{
		__definePrivateProperty(this, '__tagName', value);
	},
	
	/**

	 * A reference to this class instance's element

	 * @type	{HTMLElement}

	 */
	get el()
	{
		return this.__el;
	},
	
	toString: function()
	{
		return 'conbo.Glimpse';
	},
	
	/**

	 * Set this View's element

	 * @private

	 */
	__setEl: function(el)
	{
		var attrs = conbo.assign({}, this.attributes);
		
		if (this.id && !el.id) 
		{
			attrs.id = this.id;
		}
		
		el.classList.add('cb-glimpse');
		el.classList.add(this.__className);
		el.cbGlimpse = this;
		
		for (var attr in attrs)
		{
			el.setAttribute(conbo.toKebabCase(attr), attrs[attr]);		
		}		
		
		if (this.style)
		{
			el.style = conbo.assign(el.style, this.style);
		}
		
		__definePrivateProperty(this, '__el', el);
		
		return this;
	}
	
});

__denumerate(conbo.Glimpse.prototype);