Revision b0adfd32
Added by Andreas Kohlbecker almost 8 years ago
modules/cdm_dataportal/js/taxonomic_children.js | ||
---|---|---|
15 | 15 |
|
16 | 16 |
// Default options for the plugin as a simple object |
17 | 17 |
var defaults = { |
18 |
hoverClass: undefined, |
|
19 |
activeClass: undefined |
|
18 | 20 |
}; |
19 | 21 |
|
22 |
// Plugin constructor |
|
23 |
// This is the boilerplate to set up the plugin to keep our actual logic in one place |
|
20 | 24 |
function Plugin(element, options) { |
21 | 25 |
|
22 | 26 |
this.element = element; |
... | ... | |
38 | 42 |
|
39 | 43 |
this._defaults = defaults; |
40 | 44 |
|
41 |
this.container; |
|
42 |
this.children; |
|
43 |
this.loading; |
|
44 |
|
|
45 | 45 |
var meta = this.$el.data(name + '-opts'); |
46 | 46 |
this.opts = $.extend(this._defaults, options, meta); |
47 | 47 |
|
... | ... | |
60 | 60 |
|
61 | 61 |
init: function () { |
62 | 62 |
// Plugin initializer - prepare your plugin |
63 |
this.$el.click(this.createContainer()); |
|
64 |
}, |
|
63 |
this.$el.click(handleShowChildren); |
|
65 | 64 |
|
66 |
createContainer: function () { |
|
67 |
var trigger_position = trigger_element.position(); |
|
68 |
this.log('trigger-position: ' + trigger_position.top + ', ' + trigger_position.left); |
|
69 |
|
|
70 |
container = $('<div class="' + pluginName + ' clearfix"></div>') |
|
71 |
.css('background-color', 'red') |
|
72 |
.css('position', 'absolute') |
|
73 |
.css('top', trigger_position.top) |
|
74 |
.css('left', trigger_position.left); |
|
75 |
children = $('<div>CHILDREN</div><ul class="children"></ul>'); |
|
76 |
loading = $('<i class="fa-spinner fa-2x" />').hide(); |
|
77 |
|
|
78 |
container.append(children).append(loading); |
|
79 |
trigger_element.append(container); |
|
80 |
|
|
81 | 65 |
}, |
82 | 66 |
|
83 | 67 |
log: function (msg) { |
... | ... | |
96 | 80 |
}); |
97 | 81 |
}; |
98 | 82 |
|
83 |
// Private variables |
|
84 |
var container, children, loading; |
|
85 |
|
|
86 |
// Private functions that are only called by the plugin |
|
87 |
var createContainer = function (trigger_el) { |
|
88 |
|
|
89 |
container = $('<div class="' + pluginName + ' clearfix"></div>') |
|
90 |
.css('background-color', 'red') |
|
91 |
.css('position', 'absolute') |
|
92 |
.hide(); |
|
93 |
children = $('<div>CHILDREN</div><ul class="children"></ul>'); |
|
94 |
loading = $('<i class="fa-spinner fa-2x" />').hide(); |
|
95 |
|
|
96 |
container.append(children).append(loading); |
|
97 |
trigger_el.append(container); |
|
98 |
}; |
|
99 |
|
|
100 |
var handleShowChildren = function(){ |
|
101 |
|
|
102 |
var trigger_el = $(this); |
|
103 |
var trigger_position = trigger_el.position(); |
|
104 |
|
|
105 |
if(container == undefined){ |
|
106 |
createContainer(trigger_el); |
|
107 |
} |
|
108 |
|
|
109 |
trigger_el.addClass(this.options.hoverClass); |
|
110 |
container |
|
111 |
.css('top', trigger_position.top + trigger_el.height()) |
|
112 |
.css('left', trigger_position.left) |
|
113 |
.show(); |
|
114 |
loading.hide(); |
|
115 |
}; |
|
116 |
|
|
99 | 117 |
})(jQuery, document, window); |
Also available in: Unified diff
#5790 classification breadcrumb children implemented