source: extensions/GrumPluginClasses/js/ui.inputStatusBar.js @ 8961

Last change on this file since 8961 was 8961, checked in by grum, 13 years ago

release 3.4.0
fix bug:1984, bug:2109
js file are minified, remove packed files

  • Property svn:executable set to *
File size: 7.4 KB
Line 
1/**
2 * -----------------------------------------------------------------------------
3 * file: ui.inputStatusBar.js
4 * file version: 1.0.0
5 * date: 2010-11-04
6 *
7 * A jQuery plugin provided by the piwigo's plugin "GrumPluginClasses"
8 *
9 * -----------------------------------------------------------------------------
10 * Author     : Grum
11 *   email    : grum@piwigo.com
12 *   website  : http://photos.grum.fr
13 *   PWG user : http://forum.phpwebgallery.net/profile.php?id=3706
14 *
15 *   << May the Little SpaceFrog be with you ! >>
16 * -----------------------------------------------------------------------------
17 *
18 *
19 *
20 *
21 * :: HISTORY ::
22 *
23 * | release | date       |
24 * | 1.0.0   | 2010/11/04 | first release
25 * |         |            |
26 * |         |            |
27 * |         |            |
28 * |         |            |
29 * |         |            |
30 * |         |            |
31 *
32 */
33
34
35
36(
37  function($)
38  {
39    /*
40     * plugin 'public' functions
41     */
42    var publicMethods =
43    {
44      init : function (opt)
45        {
46          return this.each(function()
47            {
48              // default values for the plugin
49              var $this=$(this),
50                  data = $this.data('options'),
51                  objects = $this.data('objects'),
52                  properties = $this.data('properties'),
53                  options =
54                    {
55                      items:[]
56                    };
57
58              // if options given, merge it
59              // if(opt) $.extend(options, opt); ==> options are set by setters
60
61              $this.data('options', options);
62
63
64              if(!properties)
65              {
66                $this.data('properties',
67                  {
68                    initialized:false,
69                    id:$this.get(0).id
70                  }
71                );
72                properties=$this.data('properties');
73              }
74
75              if(!objects)
76              {
77                objects =
78                  {
79                    table:$('<table/>',
80                            {
81                              'class':'ui-inputStatusBar',
82                              css:{
83                                width:'100%'
84                              }
85                            }
86                          ),
87                    tr:$('<tr/>'),
88                    td:[]
89                  };
90
91                $this
92                  .html('')
93                  .append(objects.table.append(objects.tr));
94                  /*
95                  .bind('resize.inputStatusBar',
96                          function ()
97                          {
98                            privateMethods.setObjectsWidth($this);
99                          }
100                        );
101                  */
102                $this.data('objects', objects);
103              }
104
105              privateMethods.setOptions($this, opt);
106            }
107          );
108        }, // init
109      destroy : function ()
110        {
111          return this.each(
112            function()
113            {
114              // default values for the plugin
115              var $this=$(this),
116                  objects = $this.data('objects');
117              objects.tr.remove();
118              objects.table.remove();
119              $this
120                .unbind('.inputStatusBar')
121                .css(
122                  {
123                    width:'',
124                    height:''
125                  }
126                );
127            }
128          );
129        }, // destroy
130
131      options: function (value)
132        {
133          return(
134            this.each(
135              function()
136              {
137                privateMethods.setOptions($(this), value);
138              }
139            )
140          );
141        }, // options
142
143      items: function (fct, value)
144        {
145          if((fct=='add' || fct=='remove' || fct=='set') && value!=null)
146          {
147            return(
148              this.each(
149                function()
150                {
151                  privateMethods.setItems($(this), fct, value);
152                }
153              )
154            );
155          }
156          else if(fct=='get' && value!=null)
157          {
158            var options=this.data('options');
159            return(options.items[value]);
160          }
161          else
162          {
163            var options=this.data('options');
164            return(options.items);
165          }
166        } // items
167
168
169    }; // methods
170
171
172    /*
173     * plugin 'private' methods
174     */
175    var privateMethods =
176    {
177      setOptions : function (object, value)
178        {
179          var properties=object.data('properties'),
180              options=object.data('options');
181
182          if(!$.isPlainObject(value)) return(false);
183
184          properties.initialized=false;
185
186          privateMethods.setItems(object, 'init', (value.items!=null)?value.items:options.items);
187
188          properties.initialized=true;
189        },
190
191
192      setItems : function (object, fct, value)
193        {
194          var options=object.data('options'),
195              properties=object.data('properties'),
196              objects=object.data('objects'),
197              index=-1;
198
199          if(value.id==null && !$.isArray(value)) return(false);
200
201          if(value.id!=null) index=privateMethods.findItemById(object, value.id);
202
203
204          if(fct=='add' && value.id!=null && index==-1)
205          {
206            if(value.content==null) value.content='&nbsp;';
207            if(value.width==null) value.width='';
208            if(value.title==null) value.title='';
209
210            var td=$('<td/>',
211                      {
212                        id:properties.id+value.id,
213                        html:value.content,
214                        title:value.title,
215                        css:{
216                          width:value.width
217                        }
218                      }
219                    );
220            objects.td.push(
221              {
222                id:value.id,
223                td:td
224              }
225            );
226            objects.tr.append(td);
227            options.items.push(value);
228          }
229          else if(fct=='remove' && value.id!=null && index>-1)
230          {
231            if(index>-1)
232            {
233              objects.td[index].td.remove();
234              objects.td.splice(index,1);
235              options.items.splice(index, 1);
236              delete options.items[value.id];
237            }
238          }
239          else if(fct=='set' && value.id!=null && index>-1 && value.content!=null)
240          {
241            if(value.title==null) value.title='';
242
243            objects.td[index].td.html(value.content).attr('title', value.title);
244          }
245          else if(fct=='init')
246          {
247            for(var i in value)
248            {
249              privateMethods.setItems(object, 'add', value[i]);
250            }
251          }
252
253          return(true);
254        }, //setValue
255
256
257      findItemById : function (object, id)
258        {
259          var objects=object.data('objects');
260
261          for(var i=0;i<objects.td.length;i++)
262          {
263            if(objects.td[i].id==id) return(i);
264          }
265          return(-1);
266        }
267    };
268
269
270    $.fn.inputStatusBar = function(method)
271    {
272      if(publicMethods[method])
273      {
274        return publicMethods[method].apply( this, Array.prototype.slice.call( arguments, 1 ));
275      }
276      else if(typeof method === 'object' || ! method)
277      {
278        return publicMethods.init.apply(this, arguments);
279      }
280      else
281      {
282        $.error( 'Method ' +  method + ' does not exist on jQuery.inputStatusBar' );
283      }
284    } // $.fn.inputStatusBar
285
286  }
287)(jQuery);
288
289
Note: See TracBrowser for help on using the repository browser.