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

Last change on this file since 16012 was 16012, checked in by grum, 12 years ago

feature:2634- compatibility with Piwigo 2.4
+add some objects on js framework

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