Project

General

Profile

« Previous | Next » 

Revision f5ccb5a3

Added by Andreas Kohlbecker almost 8 years ago

deleting unused js file

View differences:

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
    hoverClass: undefined,
19
    activeClass: undefined
20
  };
21

  
22
  // Plugin constructor
23
  // This is the boilerplate to set up the plugin to keep our actual logic in one place
24
  function Plugin(element, options) {
25

  
26
    this.element = element;
27

  
28
    // firebug console stub (avoids errors if firebug is not active)
29
    if (typeof console === "undefined") {
30
      console = {
31
        log: function () {
32
        }
33
      };
34
    }
35

  
36
    // Merge the options given by the user with the defaults
37
    this.options = $.extend({}, defaults, options);
38

  
39
    // Attach data to the element
40
    this.$el      = $(element);
41
    this.$el.data(name, this);
42

  
43
    this._defaults = defaults;
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(handleShowChildren);
64

  
65
    },
66

  
67
    log: function (msg) {
68
      console.log('[' + pluginName + '] ' + msg);
69
    }
70

  
71
  };
72

  
73
  $.fn[pluginName] = function(options) {
74
    // Iterate through each DOM element and return it
75
    return this.each(function() {
76
      // prevent multiple instantiations
77
      if (!$.data(this, 'plugin_' + pluginName)) {
78
        $.data(this, 'plugin_' + pluginName, new Plugin(this, options));
79
      }
80
    });
81
  };
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

  
117
})(jQuery, document, window);

Also available in: Unified diff