Devices: NodesLearnt table integration with FuelUx Datagrid.
[controller.git] / opendaylight / web / root / src / main / resources / js / fuelux / pillbox.js
1 /*
2  * Fuel UX Pillbox
3  * https://github.com/ExactTarget/fuelux
4  *
5  * Copyright (c) 2012 ExactTarget
6  * Licensed under the MIT license.
7  */
8
9 define(['require','jquery'],function(require) {
10         
11         var $ = require('jquery');
12
13
14         // PILLBOX CONSTRUCTOR AND PROTOTYPE
15
16         var Pillbox = function (element, options) {
17                 this.$element = $(element);
18                 this.options = $.extend({}, $.fn.pillbox.defaults, options);
19                 this.$element.on('click', 'li', $.proxy(this.itemclicked, this));
20         };
21
22         Pillbox.prototype = {
23                 constructor: Pillbox,
24
25                 items: function() {
26                         return this.$element.find('li').map(function() {
27                                 var $this = $(this);
28                                 return $.extend({ text: $this.text() }, $this.data());
29                         }).get();
30                 },
31
32                 itemclicked: function (e) {
33                         $(e.currentTarget).remove();
34                         e.preventDefault();
35                 }
36         };
37
38
39         // PILLBOX PLUGIN DEFINITION
40
41         $.fn.pillbox = function (option) {
42                 var methodReturn;
43
44                 var $set = this.each(function () {
45                         var $this = $(this);
46                         var data = $this.data('pillbox');
47                         var options = typeof option === 'object' && option;
48
49                         if (!data) $this.data('pillbox', (data = new Pillbox(this, options)));
50                         if (typeof option === 'string') methodReturn = data[option]();
51                 });
52
53                 return (methodReturn === undefined) ? $set : methodReturn;
54         };
55
56         $.fn.pillbox.defaults = {};
57
58         $.fn.pillbox.Constructor = Pillbox;
59
60
61         // PILLBOX DATA-API
62
63         $(function () {
64                 $('body').on('mousedown.pillbox.data-api', '.pillbox', function (e) {
65                         var $this = $(this);
66                         if ($this.data('pillbox')) return;
67                         $this.pillbox($this.data());
68                 });
69         });
70         
71 });
72