Revision bf66e84a
Added by Andreas Kohlbecker almost 8 years ago
modules/cdm_dataportal/js/taxonomic_children.js | ||
---|---|---|
1 |
/** |
|
2 |
* Expected dom structure: |
|
3 |
* <span data-cdm-taxon-uuid="{taxon-uuid}"> ... </span> |
|
4 |
*/ |
|
5 |
|
|
6 |
// see also https://github.com/geetarista/jquery-plugin-template/blob/master/jquery.plugin-template.js |
|
7 |
|
|
8 |
// the semi-colon before function invocation is a safety net against concatenated |
|
9 |
// scripts and/or other plugins which may not be closed properly. |
|
10 |
;(function($, document, window, undefined) { |
|
11 |
|
|
12 |
|
|
13 |
// Name the plugin so it's only in one place |
|
14 |
var pluginName = 'taxonomic_children'; |
|
15 |
|
|
16 |
// Default options for the plugin as a simple object |
|
17 |
var defaults = { |
|
18 |
}; |
|
19 |
|
|
20 |
function Plugin(element, options) { |
|
21 |
|
|
22 |
this.element = element; |
|
23 |
|
|
24 |
// firebug console stub (avoids errors if firebug is not active) |
|
25 |
if (typeof console === "undefined") { |
|
26 |
console = { |
|
27 |
log: function () { |
|
28 |
} |
|
29 |
}; |
|
30 |
} |
|
31 |
|
|
32 |
// Merge the options given by the user with the defaults |
|
33 |
this.options = $.extend({}, defaults, options); |
|
34 |
|
|
35 |
// Attach data to the element |
|
36 |
this.$el = $(element); |
|
37 |
this.$el.data(name, this); |
|
38 |
|
|
39 |
this._defaults = defaults; |
|
40 |
|
|
41 |
this.container; |
|
42 |
this.children; |
|
43 |
this.loading; |
|
44 |
|
|
45 |
var meta = this.$el.data(name + '-opts'); |
|
46 |
this.opts = $.extend(this._defaults, options, meta); |
|
47 |
|
|
48 |
// Initialization code to get the ball rolling |
|
49 |
// If your plugin is simple, this may not be necessary and |
|
50 |
// you could place your implementation here |
|
51 |
this.init(); |
|
52 |
} |
|
53 |
|
|
54 |
Plugin.prototype = { |
|
55 |
// Public functions accessible to users |
|
56 |
// Prototype methods are shared across all elements |
|
57 |
// You have access to this.options and this.element |
|
58 |
// If your plugin is complex, you can split functionality into more |
|
59 |
// methods like this one |
|
60 |
|
|
61 |
init: function () { |
|
62 |
// Plugin initializer - prepare your plugin |
|
63 |
this.$el.click(this.createContainer()); |
|
64 |
}, |
|
65 |
|
|
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 |
}, |
|
82 |
|
|
83 |
log: function (msg) { |
|
84 |
console.log('[' + pluginName + '] ' + msg); |
|
85 |
} |
|
86 |
|
|
87 |
}; |
|
88 |
|
|
89 |
$.fn[pluginName] = function(options) { |
|
90 |
// Iterate through each DOM element and return it |
|
91 |
return this.each(function() { |
|
92 |
// prevent multiple instantiations |
|
93 |
if (!$.data(this, 'plugin_' + pluginName)) { |
|
94 |
$.data(this, 'plugin_' + pluginName, new Plugin(this, options)); |
|
95 |
} |
|
96 |
}); |
|
97 |
}; |
|
98 |
|
|
99 |
})(jQuery, document, window); |
Also available in: Unified diff
initial commit for breadcrumb-children feature