ink_ui_rails 2.1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.md +21 -0
- data/README.md +39 -0
- data/lib/ink_ui_rails.rb +8 -0
- data/lib/ink_ui_rails/version.rb +3 -0
- data/vendor/assets/fonts/font/FontAwesome.otf +0 -0
- data/vendor/assets/fonts/font/fontawesome-webfont.eot +0 -0
- data/vendor/assets/fonts/font/fontawesome-webfont.svg +399 -0
- data/vendor/assets/fonts/font/fontawesome-webfont.ttf +0 -0
- data/vendor/assets/fonts/font/fontawesome-webfont.woff +0 -0
- data/vendor/assets/fonts/font/ubuntu-b-webfont.eot +0 -0
- data/vendor/assets/fonts/font/ubuntu-b-webfont.svg +245 -0
- data/vendor/assets/fonts/font/ubuntu-b-webfont.ttf +0 -0
- data/vendor/assets/fonts/font/ubuntu-b-webfont.woff +0 -0
- data/vendor/assets/fonts/font/ubuntu-bi-webfont.eot +0 -0
- data/vendor/assets/fonts/font/ubuntu-bi-webfont.svg +245 -0
- data/vendor/assets/fonts/font/ubuntu-bi-webfont.ttf +0 -0
- data/vendor/assets/fonts/font/ubuntu-bi-webfont.woff +0 -0
- data/vendor/assets/fonts/font/ubuntu-c-webfont.eot +0 -0
- data/vendor/assets/fonts/font/ubuntu-c-webfont.svg +245 -0
- data/vendor/assets/fonts/font/ubuntu-c-webfont.ttf +0 -0
- data/vendor/assets/fonts/font/ubuntu-c-webfont.woff +0 -0
- data/vendor/assets/fonts/font/ubuntu-l-webfont.eot +0 -0
- data/vendor/assets/fonts/font/ubuntu-l-webfont.svg +245 -0
- data/vendor/assets/fonts/font/ubuntu-l-webfont.ttf +0 -0
- data/vendor/assets/fonts/font/ubuntu-l-webfont.woff +0 -0
- data/vendor/assets/fonts/font/ubuntu-li-webfont.eot +0 -0
- data/vendor/assets/fonts/font/ubuntu-li-webfont.svg +245 -0
- data/vendor/assets/fonts/font/ubuntu-li-webfont.ttf +0 -0
- data/vendor/assets/fonts/font/ubuntu-li-webfont.woff +0 -0
- data/vendor/assets/fonts/font/ubuntu-m-webfont.eot +0 -0
- data/vendor/assets/fonts/font/ubuntu-m-webfont.svg +245 -0
- data/vendor/assets/fonts/font/ubuntu-m-webfont.ttf +0 -0
- data/vendor/assets/fonts/font/ubuntu-m-webfont.woff +0 -0
- data/vendor/assets/fonts/font/ubuntu-mi-webfont.eot +0 -0
- data/vendor/assets/fonts/font/ubuntu-mi-webfont.svg +245 -0
- data/vendor/assets/fonts/font/ubuntu-mi-webfont.ttf +0 -0
- data/vendor/assets/fonts/font/ubuntu-mi-webfont.woff +0 -0
- data/vendor/assets/fonts/font/ubuntu-r-webfont.eot +0 -0
- data/vendor/assets/fonts/font/ubuntu-r-webfont.svg +245 -0
- data/vendor/assets/fonts/font/ubuntu-r-webfont.ttf +0 -0
- data/vendor/assets/fonts/font/ubuntu-r-webfont.woff +0 -0
- data/vendor/assets/fonts/font/ubuntu-ri-webfont.eot +0 -0
- data/vendor/assets/fonts/font/ubuntu-ri-webfont.svg +245 -0
- data/vendor/assets/fonts/font/ubuntu-ri-webfont.ttf +0 -0
- data/vendor/assets/fonts/font/ubuntu-ri-webfont.woff +0 -0
- data/vendor/assets/fonts/font/ubuntumono-b-webfont.eot +0 -0
- data/vendor/assets/fonts/font/ubuntumono-b-webfont.svg +242 -0
- data/vendor/assets/fonts/font/ubuntumono-b-webfont.ttf +0 -0
- data/vendor/assets/fonts/font/ubuntumono-b-webfont.woff +0 -0
- data/vendor/assets/fonts/font/ubuntumono-bi-webfont.eot +0 -0
- data/vendor/assets/fonts/font/ubuntumono-bi-webfont.svg +242 -0
- data/vendor/assets/fonts/font/ubuntumono-bi-webfont.ttf +0 -0
- data/vendor/assets/fonts/font/ubuntumono-bi-webfont.woff +0 -0
- data/vendor/assets/fonts/font/ubuntumono-r-webfont.eot +0 -0
- data/vendor/assets/fonts/font/ubuntumono-r-webfont.svg +242 -0
- data/vendor/assets/fonts/font/ubuntumono-r-webfont.ttf +0 -0
- data/vendor/assets/fonts/font/ubuntumono-r-webfont.woff +0 -0
- data/vendor/assets/fonts/font/ubuntumono-ri-webfont.eot +0 -0
- data/vendor/assets/fonts/font/ubuntumono-ri-webfont.svg +242 -0
- data/vendor/assets/fonts/font/ubuntumono-ri-webfont.ttf +0 -0
- data/vendor/assets/fonts/font/ubuntumono-ri-webfont.woff +0 -0
- data/vendor/assets/images/img/SAPOlogo.png +0 -0
- data/vendor/assets/images/img/favicon.ico +0 -0
- data/vendor/assets/images/img/home_bkg.png +0 -0
- data/vendor/assets/images/img/home_logo_IE.jpg +0 -0
- data/vendor/assets/images/img/icon_Sprite.png +0 -0
- data/vendor/assets/images/img/ink-favicon.ico +0 -0
- data/vendor/assets/images/img/logo_home.png +0 -0
- data/vendor/assets/images/img/shot_ink.png +0 -0
- data/vendor/assets/images/img/shot_intra.png +0 -0
- data/vendor/assets/images/img/shot_livebots.png +0 -0
- data/vendor/assets/images/img/shot_meo.png +0 -0
- data/vendor/assets/images/img/shot_musicbox.png +0 -0
- data/vendor/assets/images/img/shot_pessoa.png +0 -0
- data/vendor/assets/images/img/splash.1024x748.png +0 -0
- data/vendor/assets/images/img/splash.320x460.png +0 -0
- data/vendor/assets/images/img/splash.768x1004.png +0 -0
- data/vendor/assets/images/img/touch-icon.114.png +0 -0
- data/vendor/assets/images/img/touch-icon.16.png +0 -0
- data/vendor/assets/images/img/touch-icon.256.png +0 -0
- data/vendor/assets/images/img/touch-icon.57.png +0 -0
- data/vendor/assets/images/img/touch-icon.72.png +0 -0
- data/vendor/assets/javascripts/autoload.js +85 -0
- data/vendor/assets/javascripts/example.json +1174 -0
- data/vendor/assets/javascripts/holder.js +440 -0
- data/vendor/assets/javascripts/html5shiv-printshiv.js +496 -0
- data/vendor/assets/javascripts/html5shiv.js +298 -0
- data/vendor/assets/javascripts/ink-all.js +18015 -0
- data/vendor/assets/javascripts/ink-ui.js +7737 -0
- data/vendor/assets/javascripts/ink.aux.js +506 -0
- data/vendor/assets/javascripts/ink.close.js +54 -0
- data/vendor/assets/javascripts/ink.datepicker.js +1194 -0
- data/vendor/assets/javascripts/ink.datepicker.pt.js +32 -0
- data/vendor/assets/javascripts/ink.draggable.js +437 -0
- data/vendor/assets/javascripts/ink.droppable.js +193 -0
- data/vendor/assets/javascripts/ink.formvalidator.js +712 -0
- data/vendor/assets/javascripts/ink.gallery.js +757 -0
- data/vendor/assets/javascripts/ink.imagequery.js +259 -0
- data/vendor/assets/javascripts/ink.js +10278 -0
- data/vendor/assets/javascripts/ink.modal.js +628 -0
- data/vendor/assets/javascripts/ink.pagination.js +473 -0
- data/vendor/assets/javascripts/ink.progressbar.js +110 -0
- data/vendor/assets/javascripts/ink.smoothscroller.js +234 -0
- data/vendor/assets/javascripts/ink.sortablelist.js +338 -0
- data/vendor/assets/javascripts/ink.spy.js +123 -0
- data/vendor/assets/javascripts/ink.sticky.js +254 -0
- data/vendor/assets/javascripts/ink.table.js +621 -0
- data/vendor/assets/javascripts/ink.tabs.js +426 -0
- data/vendor/assets/javascripts/ink.toggle.js +218 -0
- data/vendor/assets/javascripts/ink.treeview.js +179 -0
- data/vendor/assets/javascripts/ink_ui.js +1 -0
- data/vendor/assets/javascripts/modernizr.js +815 -0
- data/vendor/assets/javascripts/prettify.js +28 -0
- data/vendor/assets/stylesheets/ink/_ink-ie7.css +1662 -0
- data/vendor/assets/stylesheets/ink/_ink.css +7496 -0
- data/vendor/assets/stylesheets/ink/ink_ui.scss.css +2 -0
- data/vendor/assets/stylesheets/ink_ui.scss.css +1 -0
- metadata +203 -0
@@ -0,0 +1,426 @@
|
|
1
|
+
/**
|
2
|
+
* @module Ink.UI.Tabs_1
|
3
|
+
* @author inkdev AT sapo.pt
|
4
|
+
* @version 1
|
5
|
+
*/
|
6
|
+
Ink.createModule('Ink.UI.Tabs', '1', ['Ink.UI.Aux_1','Ink.Dom.Event_1','Ink.Dom.Css_1','Ink.Dom.Element_1','Ink.Dom.Selector_1','Ink.Util.Array_1'], function(Aux, Event, Css, Element, Selector, InkArray ) {
|
7
|
+
'use strict';
|
8
|
+
|
9
|
+
/**
|
10
|
+
* Tabs component
|
11
|
+
*
|
12
|
+
* @class Ink.UI.Tabs
|
13
|
+
* @constructor
|
14
|
+
* @version 1
|
15
|
+
* @uses Ink.UI.Aux
|
16
|
+
* @uses Ink.Dom.Event
|
17
|
+
* @uses Ink.Dom.Css
|
18
|
+
* @uses Ink.Dom.Element
|
19
|
+
* @uses Ink.Dom.Selector
|
20
|
+
* @uses Ink.Util.Array
|
21
|
+
* @param {String|DOMElement} selector
|
22
|
+
* @param {Object} [options] Options for the datepicker
|
23
|
+
* @param {Boolean} [options.preventUrlChange] Flag that determines if follows the link on click or stops the event
|
24
|
+
* @param {String} [options.active] ID of the tab to activate on creation
|
25
|
+
* @param {Array} [options.disabled] IDs of the tabs that will be disabled on creation
|
26
|
+
* @param {Function} [options.onBeforeChange] callback to be executed before changing tabs
|
27
|
+
* @param {Function} [options.onChange] callback to be executed after changing tabs
|
28
|
+
* @example
|
29
|
+
* <div class="ink-tabs top"> <!-- replace 'top' with 'bottom', 'left' or 'right' to place navigation -->
|
30
|
+
*
|
31
|
+
* <!-- put navigation first if using top, left or right positioning -->
|
32
|
+
* <ul class="tabs-nav">
|
33
|
+
* <li><a href="#home">Home</a></li>
|
34
|
+
* <li><a href="#news">News</a></li>
|
35
|
+
* <li><a href="#description">Description</a></li>
|
36
|
+
* <li><a href="#stuff">Stuff</a></li>
|
37
|
+
* <li><a href="#more_stuff">More stuff</a></li>
|
38
|
+
* </ul>
|
39
|
+
*
|
40
|
+
* <!-- Put your content second if using top, left or right navigation -->
|
41
|
+
* <div id="home" class="tabs-content"><p>Content</p></div>
|
42
|
+
* <div id="news" class="tabs-content"><p>Content</p></div>
|
43
|
+
* <div id="description" class="tabs-content"><p>Content</p></div>
|
44
|
+
* <div id="stuff" class="tabs-content"><p>Content</p></div>
|
45
|
+
* <div id="more_stuff" class="tabs-content"><p>Content</p></div>
|
46
|
+
* <!-- If you're using bottom navigation, switch the nav block with the content blocks -->
|
47
|
+
*
|
48
|
+
* </div>
|
49
|
+
* <script>
|
50
|
+
* Ink.requireModules( ['Ink.Dom.Selector_1','Ink.UI.Tabs_1'], function( Selector, Tabs ){
|
51
|
+
* var tabsElement = Ink.s('.ink-tabs');
|
52
|
+
* var tabsObj = new Tabs( tabsElement );
|
53
|
+
* });
|
54
|
+
* </script>
|
55
|
+
*/
|
56
|
+
var Tabs = function(selector, options) {
|
57
|
+
|
58
|
+
if (!Aux.isDOMElement(selector)) {
|
59
|
+
selector = Selector.select(selector);
|
60
|
+
if (selector.length === 0) { throw new TypeError('1st argument must either be a DOM Element or a selector expression!'); }
|
61
|
+
this._element = selector[0];
|
62
|
+
} else {
|
63
|
+
this._element = selector;
|
64
|
+
}
|
65
|
+
|
66
|
+
|
67
|
+
this._options = Ink.extendObj({
|
68
|
+
preventUrlChange: false,
|
69
|
+
active: undefined,
|
70
|
+
disabled: [],
|
71
|
+
onBeforeChange: undefined,
|
72
|
+
onChange: undefined
|
73
|
+
}, Element.data(selector));
|
74
|
+
|
75
|
+
this._options = Ink.extendObj(this._options,options || {});
|
76
|
+
|
77
|
+
this._handlers = {
|
78
|
+
tabClicked: Ink.bindEvent(this._onTabClicked,this),
|
79
|
+
disabledTabClicked: Ink.bindEvent(this._onDisabledTabClicked,this),
|
80
|
+
resize: Ink.bindEvent(this._onResize,this)
|
81
|
+
};
|
82
|
+
|
83
|
+
this._init();
|
84
|
+
};
|
85
|
+
|
86
|
+
Tabs.prototype = {
|
87
|
+
|
88
|
+
/**
|
89
|
+
* Init function called by the constructor
|
90
|
+
*
|
91
|
+
* @method _init
|
92
|
+
* @private
|
93
|
+
*/
|
94
|
+
_init: function() {
|
95
|
+
this._menu = Selector.select('.tabs-nav', this._element)[0];
|
96
|
+
this._menuTabs = this._getChildElements(this._menu);
|
97
|
+
this._contentTabs = Selector.select('.tabs-content', this._element);
|
98
|
+
|
99
|
+
//initialization of the tabs, hides all content before setting the active tab
|
100
|
+
this._initializeDom();
|
101
|
+
|
102
|
+
// subscribe events
|
103
|
+
this._observe();
|
104
|
+
|
105
|
+
//sets the first active tab
|
106
|
+
this._setFirstActive();
|
107
|
+
|
108
|
+
//shows the active tab
|
109
|
+
this._changeTab(this._activeMenuLink);
|
110
|
+
|
111
|
+
this._handlers.resize();
|
112
|
+
|
113
|
+
Aux.registerInstance(this, this._element, 'tabs');
|
114
|
+
},
|
115
|
+
|
116
|
+
/**
|
117
|
+
* Initialization of the tabs, hides all content before setting the active tab
|
118
|
+
*
|
119
|
+
* @method _initializeDom
|
120
|
+
* @private
|
121
|
+
*/
|
122
|
+
_initializeDom: function(){
|
123
|
+
for(var i = 0; i < this._contentTabs.length; i++){
|
124
|
+
Css.hide(this._contentTabs[i]);
|
125
|
+
}
|
126
|
+
},
|
127
|
+
|
128
|
+
/**
|
129
|
+
* Subscribe events
|
130
|
+
*
|
131
|
+
* @method _observe
|
132
|
+
* @private
|
133
|
+
*/
|
134
|
+
_observe: function() {
|
135
|
+
InkArray.each(this._menuTabs,Ink.bind(function(elem){
|
136
|
+
var link = Selector.select('a', elem)[0];
|
137
|
+
if(InkArray.inArray(link.getAttribute('href'), this._options.disabled)){
|
138
|
+
this.disable(link);
|
139
|
+
} else {
|
140
|
+
this.enable(link);
|
141
|
+
}
|
142
|
+
},this));
|
143
|
+
|
144
|
+
Event.observe(window, 'resize', this._handlers.resize);
|
145
|
+
},
|
146
|
+
|
147
|
+
/**
|
148
|
+
* Run at instantiation, to determine which is the first active tab
|
149
|
+
* fallsback from window.location.href to options.active to the first not disabled tab
|
150
|
+
*
|
151
|
+
* @method _setFirstActive
|
152
|
+
* @private
|
153
|
+
*/
|
154
|
+
_setFirstActive: function() {
|
155
|
+
var hash = window.location.hash;
|
156
|
+
this._activeContentTab = Selector.select(hash, this._element)[0] ||
|
157
|
+
Selector.select(this._hashify(this._options.active), this._element)[0] ||
|
158
|
+
Selector.select('.tabs-content', this._element)[0];
|
159
|
+
|
160
|
+
this._activeMenuLink = this._findLinkByHref(this._activeContentTab.getAttribute('id'));
|
161
|
+
this._activeMenuTab = this._activeMenuLink.parentNode;
|
162
|
+
},
|
163
|
+
|
164
|
+
/**
|
165
|
+
* Changes to the desired tab
|
166
|
+
*
|
167
|
+
* @method _changeTab
|
168
|
+
* @param {DOMElement} link anchor linking to the content container
|
169
|
+
* @param {boolean} runCallbacks defines if the callbacks should be run or not
|
170
|
+
* @private
|
171
|
+
*/
|
172
|
+
_changeTab: function(link, runCallbacks){
|
173
|
+
if(runCallbacks && typeof this._options.onBeforeChange !== 'undefined'){
|
174
|
+
this._options.onBeforeChange(this);
|
175
|
+
}
|
176
|
+
|
177
|
+
var selector = link.getAttribute('href');
|
178
|
+
Css.removeClassName(this._activeMenuTab, 'active');
|
179
|
+
Css.removeClassName(this._activeContentTab, 'active');
|
180
|
+
Css.addClassName(this._activeContentTab, 'hide-all');
|
181
|
+
|
182
|
+
this._activeMenuLink = link;
|
183
|
+
this._activeMenuTab = this._activeMenuLink.parentNode;
|
184
|
+
this._activeContentTab = Selector.select(selector.substr(selector.indexOf('#')), this._element)[0];
|
185
|
+
|
186
|
+
Css.addClassName(this._activeMenuTab, 'active');
|
187
|
+
Css.addClassName(this._activeContentTab, 'active');
|
188
|
+
Css.removeClassName(this._activeContentTab, 'hide-all');
|
189
|
+
Css.show(this._activeContentTab);
|
190
|
+
|
191
|
+
if(runCallbacks && typeof(this._options.onChange) !== 'undefined'){
|
192
|
+
this._options.onChange(this);
|
193
|
+
}
|
194
|
+
},
|
195
|
+
|
196
|
+
/**
|
197
|
+
* Tab clicked handler
|
198
|
+
*
|
199
|
+
* @method _onTabClicked
|
200
|
+
* @param {Event} ev
|
201
|
+
* @private
|
202
|
+
*/
|
203
|
+
_onTabClicked: function(ev) {
|
204
|
+
Event.stop(ev);
|
205
|
+
|
206
|
+
var target = Event.findElement(ev, 'A');
|
207
|
+
if(target.nodeName.toLowerCase() !== 'a') {
|
208
|
+
return;
|
209
|
+
}
|
210
|
+
|
211
|
+
if( this._options.preventUrlChange.toString() !== 'true'){
|
212
|
+
window.location.hash = target.getAttribute('href').substr(target.getAttribute('href').indexOf('#'));
|
213
|
+
}
|
214
|
+
|
215
|
+
if(target === this._activeMenuLink){
|
216
|
+
return;
|
217
|
+
}
|
218
|
+
this.changeTab(target);
|
219
|
+
},
|
220
|
+
|
221
|
+
/**
|
222
|
+
* Disabled tab clicked handler
|
223
|
+
*
|
224
|
+
* @method _onDisabledTabClicked
|
225
|
+
* @param {Event} ev
|
226
|
+
* @private
|
227
|
+
*/
|
228
|
+
_onDisabledTabClicked: function(ev) {
|
229
|
+
Event.stop(ev);
|
230
|
+
},
|
231
|
+
|
232
|
+
/**
|
233
|
+
* Resize handler
|
234
|
+
*
|
235
|
+
* @method _onResize
|
236
|
+
* @private
|
237
|
+
*/
|
238
|
+
_onResize: function(){
|
239
|
+
var currentLayout = Aux.currentLayout();
|
240
|
+
if(currentLayout === this._lastLayout){
|
241
|
+
return;
|
242
|
+
}
|
243
|
+
|
244
|
+
if(currentLayout === Aux.Layouts.SMALL || currentLayout === Aux.Layouts.MEDIUM){
|
245
|
+
Css.removeClassName(this._menu, 'menu');
|
246
|
+
Css.removeClassName(this._menu, 'horizontal');
|
247
|
+
// Css.addClassName(this._menu, 'pills');
|
248
|
+
} else {
|
249
|
+
Css.addClassName(this._menu, 'menu');
|
250
|
+
Css.addClassName(this._menu, 'horizontal');
|
251
|
+
// Css.removeClassName(this._menu, 'pills');
|
252
|
+
}
|
253
|
+
this._lastLayout = currentLayout;
|
254
|
+
},
|
255
|
+
|
256
|
+
/*****************
|
257
|
+
* Aux Functions *
|
258
|
+
*****************/
|
259
|
+
|
260
|
+
/**
|
261
|
+
* Allows the hash to be passed with or without the cardinal sign
|
262
|
+
*
|
263
|
+
* @method _hashify
|
264
|
+
* @param {String} hash the string to be hashified
|
265
|
+
* @return {String} Resulting hash
|
266
|
+
* @private
|
267
|
+
*/
|
268
|
+
_hashify: function(hash){
|
269
|
+
if(!hash){
|
270
|
+
return "";
|
271
|
+
}
|
272
|
+
return hash.indexOf('#') === 0? hash : '#' + hash;
|
273
|
+
},
|
274
|
+
|
275
|
+
/**
|
276
|
+
* Returns the anchor with the desired href
|
277
|
+
*
|
278
|
+
* @method _findLinkBuHref
|
279
|
+
* @param {String} href the href to be found on the returned link
|
280
|
+
* @return {String|undefined} [description]
|
281
|
+
* @private
|
282
|
+
*/
|
283
|
+
_findLinkByHref: function(href){
|
284
|
+
href = this._hashify(href);
|
285
|
+
var ret;
|
286
|
+
InkArray.each(this._menuTabs,Ink.bind(function(elem){
|
287
|
+
var link = Selector.select('a', elem)[0];
|
288
|
+
if( (link.getAttribute('href').indexOf('#') !== -1) && ( link.getAttribute('href').substr(link.getAttribute('href').indexOf('#')) === href ) ){
|
289
|
+
ret = link;
|
290
|
+
}
|
291
|
+
},this));
|
292
|
+
return ret;
|
293
|
+
},
|
294
|
+
|
295
|
+
/**
|
296
|
+
* Returns the child elements of a given parent element
|
297
|
+
*
|
298
|
+
* @method _getChildElements
|
299
|
+
* @param {DOMElement} parent DOMElement to fetch the child elements from.
|
300
|
+
* @return {Array} Child elements of the given parent.
|
301
|
+
* @private
|
302
|
+
*/
|
303
|
+
_getChildElements: function(parent){
|
304
|
+
var childNodes = [];
|
305
|
+
var children = parent.children;
|
306
|
+
for(var i = 0; i < children.length; i++){
|
307
|
+
if(children[i].nodeType === 1){
|
308
|
+
childNodes.push(children[i]);
|
309
|
+
}
|
310
|
+
}
|
311
|
+
return childNodes;
|
312
|
+
},
|
313
|
+
|
314
|
+
/**************
|
315
|
+
* PUBLIC API *
|
316
|
+
**************/
|
317
|
+
|
318
|
+
/**
|
319
|
+
* Changes to the desired tag
|
320
|
+
*
|
321
|
+
* @method changeTab
|
322
|
+
* @param {String|DOMElement} selector the id of the desired tab or the link that links to it
|
323
|
+
* @public
|
324
|
+
*/
|
325
|
+
changeTab: function(selector) {
|
326
|
+
var element = (selector.nodeType === 1)? selector : this._findLinkByHref(this._hashify(selector));
|
327
|
+
if(!element || Css.hasClassName(element, 'ink-disabled')){
|
328
|
+
return;
|
329
|
+
}
|
330
|
+
this._changeTab(element, true);
|
331
|
+
},
|
332
|
+
|
333
|
+
/**
|
334
|
+
* Disables the desired tag
|
335
|
+
*
|
336
|
+
* @method disable
|
337
|
+
* @param {String|DOMElement} selector the id of the desired tab or the link that links to it
|
338
|
+
* @public
|
339
|
+
*/
|
340
|
+
disable: function(selector){
|
341
|
+
var element = (selector.nodeType === 1)? selector : this._findLinkByHref(this._hashify(selector));
|
342
|
+
if(!element){
|
343
|
+
return;
|
344
|
+
}
|
345
|
+
Event.stopObserving(element, 'click', this._handlers.tabClicked);
|
346
|
+
Event.observe(element, 'click', this._handlers.disabledTabClicked);
|
347
|
+
Css.addClassName(element, 'ink-disabled');
|
348
|
+
},
|
349
|
+
|
350
|
+
/**
|
351
|
+
* Enables the desired tag
|
352
|
+
*
|
353
|
+
* @method enable
|
354
|
+
* @param {String|DOMElement} selector the id of the desired tab or the link that links to it
|
355
|
+
* @public
|
356
|
+
*/
|
357
|
+
enable: function(selector){
|
358
|
+
var element = (selector.nodeType === 1)? selector : this._findLinkByHref(this._hashify(selector));
|
359
|
+
if(!element){
|
360
|
+
return;
|
361
|
+
}
|
362
|
+
Event.stopObserving(element, 'click', this._handlers.disabledTabClicked);
|
363
|
+
Event.observe(element, 'click', this._handlers.tabClicked);
|
364
|
+
Css.removeClassName(element, 'ink-disabled');
|
365
|
+
},
|
366
|
+
|
367
|
+
/***********
|
368
|
+
* Getters *
|
369
|
+
***********/
|
370
|
+
|
371
|
+
/**
|
372
|
+
* Returns the active tab id
|
373
|
+
*
|
374
|
+
* @method activeTab
|
375
|
+
* @return {String} ID of the active tab.
|
376
|
+
* @public
|
377
|
+
*/
|
378
|
+
activeTab: function(){
|
379
|
+
return this._activeContentTab.getAttribute('id');
|
380
|
+
},
|
381
|
+
|
382
|
+
/**
|
383
|
+
* Returns the current active Menu LI
|
384
|
+
*
|
385
|
+
* @method activeMenuTab
|
386
|
+
* @return {DOMElement} Active menu LI.
|
387
|
+
* @public
|
388
|
+
*/
|
389
|
+
activeMenuTab: function(){
|
390
|
+
return this._activeMenuTab;
|
391
|
+
},
|
392
|
+
|
393
|
+
/**
|
394
|
+
* Returns the current active Menu anchorChanges to the desired tag
|
395
|
+
*
|
396
|
+
* @method activeMenuLink
|
397
|
+
* @return {DOMElement} Active menu link
|
398
|
+
* @public
|
399
|
+
*/
|
400
|
+
activeMenuLink: function(){
|
401
|
+
return this._activeMenuLink;
|
402
|
+
},
|
403
|
+
|
404
|
+
/**
|
405
|
+
* Returns the current active Content Tab
|
406
|
+
*
|
407
|
+
* @method activeContentTab
|
408
|
+
* @return {DOMElement} Active Content Tab
|
409
|
+
* @public
|
410
|
+
*/
|
411
|
+
activeContentTab: function(){
|
412
|
+
return this._activeContentTab;
|
413
|
+
},
|
414
|
+
|
415
|
+
/**
|
416
|
+
* Unregisters the component and removes its markup from the DOM
|
417
|
+
*
|
418
|
+
* @method destroy
|
419
|
+
* @public
|
420
|
+
*/
|
421
|
+
destroy: Aux.destroyComponent
|
422
|
+
};
|
423
|
+
|
424
|
+
return Tabs;
|
425
|
+
|
426
|
+
});
|
@@ -0,0 +1,218 @@
|
|
1
|
+
/**
|
2
|
+
00 * @module Ink.UI.Toggle_1
|
3
|
+
* @author inkdev AT sapo.pt
|
4
|
+
* @version 1
|
5
|
+
*/
|
6
|
+
Ink.createModule('Ink.UI.Toggle', '1', ['Ink.UI.Aux_1','Ink.Dom.Event_1','Ink.Dom.Css_1','Ink.Dom.Element_1','Ink.Dom.Selector_1'], function(Aux, Event, Css, Element, Selector ) {
|
7
|
+
'use strict';
|
8
|
+
|
9
|
+
/**
|
10
|
+
* Toggle component
|
11
|
+
*
|
12
|
+
* @class Ink.UI.Toggle
|
13
|
+
* @constructor
|
14
|
+
* @version 1
|
15
|
+
* @uses Ink.UI.Aux
|
16
|
+
* @uses Ink.Dom.Event
|
17
|
+
* @uses Ink.Dom.Css
|
18
|
+
* @uses Ink.Dom.Element
|
19
|
+
* @uses Ink.Dom.Selector
|
20
|
+
* @param {String|DOMElement} selector
|
21
|
+
* @param {Object} [options] Options
|
22
|
+
* @param {String} options.target CSS Selector that specifies the elements that will toggle
|
23
|
+
* @param {String} [options.triggerEvent] Event that will trigger the toggling. Default is 'click'
|
24
|
+
* @param {Boolean} [options.closeOnClick] Flag that determines if, when clicking outside of the toggled content, it should hide it. Default: true.
|
25
|
+
* @example
|
26
|
+
* <div class="ink-dropdown">
|
27
|
+
* <button class="ink-button toggle" data-target="#dropdown">Dropdown <span class="icon-caret-down"></span></button>
|
28
|
+
* <ul id="dropdown" class="dropdown-menu">
|
29
|
+
* <li class="heading">Heading</li>
|
30
|
+
* <li class="separator-above"><a href="#">Option</a></li>
|
31
|
+
* <li><a href="#">Option</a></li>
|
32
|
+
* <li class="separator-above disabled"><a href="#">Disabled option</a></li>
|
33
|
+
* <li class="submenu">
|
34
|
+
* <a href="#" class="toggle" data-target="#submenu1">A longer option name</a>
|
35
|
+
* <ul id="submenu1" class="dropdown-menu">
|
36
|
+
* <li class="submenu">
|
37
|
+
* <a href="#" class="toggle" data-target="#ultrasubmenu">Sub option</a>
|
38
|
+
* <ul id="ultrasubmenu" class="dropdown-menu">
|
39
|
+
* <li><a href="#">Sub option</a></li>
|
40
|
+
* <li><a href="#" data-target="ultrasubmenu">Sub option</a></li>
|
41
|
+
* <li><a href="#">Sub option</a></li>
|
42
|
+
* </ul>
|
43
|
+
* </li>
|
44
|
+
* <li><a href="#">Sub option</a></li>
|
45
|
+
* <li><a href="#">Sub option</a></li>
|
46
|
+
* </ul>
|
47
|
+
* </li>
|
48
|
+
* <li><a href="#">Option</a></li>
|
49
|
+
* </ul>
|
50
|
+
* </div>
|
51
|
+
* <script>
|
52
|
+
* Ink.requireModules( ['Ink.Dom.Selector_1','Ink.UI.Toggle_1'], function( Selector, Toggle ){
|
53
|
+
* var toggleElement = Ink.s('.toggle');
|
54
|
+
* var toggleObj = new Toggle( toggleElement );
|
55
|
+
* });
|
56
|
+
* </script>
|
57
|
+
*/
|
58
|
+
var Toggle = function( selector, options ){
|
59
|
+
|
60
|
+
if( typeof selector !== 'string' && typeof selector !== 'object' ){
|
61
|
+
throw '[Ink.UI.Toggle] Invalid CSS selector to determine the root element';
|
62
|
+
}
|
63
|
+
|
64
|
+
if( typeof selector === 'string' ){
|
65
|
+
this._rootElement = Selector.select( selector );
|
66
|
+
if( this._rootElement.length <= 0 ){
|
67
|
+
throw '[Ink.UI.Toggle] Root element not found';
|
68
|
+
}
|
69
|
+
|
70
|
+
this._rootElement = this._rootElement[0];
|
71
|
+
} else {
|
72
|
+
this._rootElement = selector;
|
73
|
+
}
|
74
|
+
|
75
|
+
this._options = Ink.extendObj({
|
76
|
+
target : undefined,
|
77
|
+
triggerEvent: 'click',
|
78
|
+
closeOnClick: true
|
79
|
+
},Element.data(this._rootElement));
|
80
|
+
|
81
|
+
this._options = Ink.extendObj(this._options,options || {});
|
82
|
+
|
83
|
+
if( typeof this._options.target === 'undefined' ){
|
84
|
+
throw '[Ink.UI.Toggle] Target option not defined';
|
85
|
+
}
|
86
|
+
|
87
|
+
this._childElement = Aux.elOrSelector( this._options.target, 'Target' );
|
88
|
+
// this._childElement = Selector.select( this._options.target, this._rootElement );
|
89
|
+
// if( this._childElement.length <= 0 ){
|
90
|
+
// if( this._childElement.length <= 0 ){
|
91
|
+
// this._childElement = Selector.select( this._options.target, this._rootElement.parentNode );
|
92
|
+
// }
|
93
|
+
|
94
|
+
// if( this._childElement.length <= 0 ){
|
95
|
+
// this._childElement = Selector.select( this._options.target );
|
96
|
+
// }
|
97
|
+
|
98
|
+
// if( this._childElement.length <= 0 ){
|
99
|
+
// return;
|
100
|
+
// }
|
101
|
+
// }
|
102
|
+
// this._childElement = this._childElement[0];
|
103
|
+
|
104
|
+
this._init();
|
105
|
+
|
106
|
+
};
|
107
|
+
|
108
|
+
Toggle.prototype = {
|
109
|
+
|
110
|
+
/**
|
111
|
+
* Init function called by the constructor
|
112
|
+
*
|
113
|
+
* @method _init
|
114
|
+
* @private
|
115
|
+
*/
|
116
|
+
_init: function(){
|
117
|
+
|
118
|
+
this._accordion = ( Css.hasClassName(this._rootElement.parentNode,'accordion') || Css.hasClassName(this._childElement.parentNode,'accordion') );
|
119
|
+
|
120
|
+
Event.observe( this._rootElement, this._options.triggerEvent, Ink.bindEvent(this._onTriggerEvent,this) );
|
121
|
+
if( this._options.closeOnClick.toString() === 'true' ){
|
122
|
+
Event.observe( document, 'click', Ink.bindEvent(this._onClick,this));
|
123
|
+
}
|
124
|
+
},
|
125
|
+
|
126
|
+
/**
|
127
|
+
* Event handler. It's responsible for handling the <triggerEvent> defined in the options.
|
128
|
+
* This will trigger the toggle.
|
129
|
+
*
|
130
|
+
* @method _onTriggerEvent
|
131
|
+
* @param {Event} event
|
132
|
+
* @private
|
133
|
+
*/
|
134
|
+
_onTriggerEvent: function( event ){
|
135
|
+
|
136
|
+
if( this._accordion ){
|
137
|
+
var elms, i, accordionElement;
|
138
|
+
if( Css.hasClassName(this._childElement.parentNode,'accordion') ){
|
139
|
+
accordionElement = this._childElement.parentNode;
|
140
|
+
} else {
|
141
|
+
accordionElement = this._childElement.parentNode.parentNode;
|
142
|
+
}
|
143
|
+
elms = Selector.select('.toggle',accordionElement);
|
144
|
+
for( i=0; i<elms.length; i+=1 ){
|
145
|
+
var
|
146
|
+
dataset = Element.data( elms[i] ),
|
147
|
+
targetElm = Selector.select( dataset.target,accordionElement )
|
148
|
+
;
|
149
|
+
if( (targetElm.length > 0) && (targetElm[0] !== this._childElement) ){
|
150
|
+
targetElm[0].style.display = 'none';
|
151
|
+
}
|
152
|
+
}
|
153
|
+
}
|
154
|
+
|
155
|
+
var finalClass = ( Css.getStyle(this._childElement,'display') === 'none') ? 'show-all' : 'hide-all';
|
156
|
+
var finalDisplay = ( Css.getStyle(this._childElement,'display') === 'none') ? 'block' : 'none';
|
157
|
+
Css.removeClassName(this._childElement,'show-all');
|
158
|
+
Css.removeClassName(this._childElement, 'hide-all');
|
159
|
+
Css.addClassName(this._childElement, finalClass);
|
160
|
+
this._childElement.style.display = finalDisplay;
|
161
|
+
|
162
|
+
if( finalClass === 'show-all' ){
|
163
|
+
Css.addClassName(this._rootElement,'active');
|
164
|
+
} else {
|
165
|
+
Css.removeClassName(this._rootElement,'active');
|
166
|
+
}
|
167
|
+
},
|
168
|
+
|
169
|
+
/**
|
170
|
+
* Click handler. Will handle clicks outside the toggle component.
|
171
|
+
*
|
172
|
+
* @method _onClick
|
173
|
+
* @param {Event} event
|
174
|
+
* @private
|
175
|
+
*/
|
176
|
+
_onClick: function( event ){
|
177
|
+
var
|
178
|
+
tgtEl = Event.element(event),
|
179
|
+
shades
|
180
|
+
;
|
181
|
+
|
182
|
+
if( (this._rootElement === tgtEl) || Element.isAncestorOf( this._rootElement, tgtEl ) || Element.isAncestorOf( this._childElement, tgtEl ) ){
|
183
|
+
return;
|
184
|
+
} else if( (shades = Ink.ss('.ink-shade')).length ) {
|
185
|
+
var
|
186
|
+
shadesLength = shades.length
|
187
|
+
;
|
188
|
+
|
189
|
+
for( var i = 0; i < shadesLength; i++ ){
|
190
|
+
if( Element.isAncestorOf(shades[i],tgtEl) && Element.isAncestorOf(shades[i],this._rootElement) ){
|
191
|
+
return;
|
192
|
+
}
|
193
|
+
}
|
194
|
+
}
|
195
|
+
|
196
|
+
this._dismiss( this._rootElement );
|
197
|
+
},
|
198
|
+
|
199
|
+
/**
|
200
|
+
* Dismisses the toggling.
|
201
|
+
*
|
202
|
+
* @method _dismiss
|
203
|
+
* @private
|
204
|
+
*/
|
205
|
+
_dismiss: function( ){
|
206
|
+
if( ( Css.getStyle(this._childElement,'display') === 'none') ){
|
207
|
+
return;
|
208
|
+
}
|
209
|
+
Css.removeClassName(this._childElement, 'show-all');
|
210
|
+
Css.removeClassName(this._rootElement,'active');
|
211
|
+
Css.addClassName(this._childElement, 'hide-all');
|
212
|
+
this._childElement.style.display = 'none';
|
213
|
+
}
|
214
|
+
};
|
215
|
+
|
216
|
+
return Toggle;
|
217
|
+
|
218
|
+
});
|