PageSourceSearch

https://www.socialmotus.com/js/wl_Widget.js

js socialmotus.com collected 2026-10-04 21:14:52 UTC 12,048 bytes, 327 lines download raw bytes

1/*----------------------------------------------------------------------*/
2/* wl_Widget v 1.1 by revaxarts.com
3/* description: handles all function for the widgets
4/* dependency: wl_Store, jquery sortable a.d.
5/*----------------------------------------------------------------------*/
6
7
8$.fn.wl_Widget = function (method) {
9
10    var args = arguments;
11    return this.each(function () {
12
13        var $this = $(this);
14
15        if ($.fn.wl_Widget.methods[method]) {
16            return $.fn.wl_Widget.methods[method].apply(this, Array.prototype.slice.call(args, 1));
17        } else if (typeof method === 'object' || !method) {
18            if ($this.data('wl_Widget')) {
19                var opts = $.extend({}, $this.data('wl_Widget'), method);
20            } else {
21                var opts = $.extend({}, $.fn.wl_Widget.defaults, method, $this.data());
22            }
23        } else {
24            $.error('Method "' + method + '" does not exist');
25        }
26
27
28        if (!$this.data('wl_Widget')) {
29
30            $this.data('wl_Widget', {});
31
32            //find the widgets within the conatainer
33            var $widgets = $this.find('div.widget');
34
35            //iterate thru the widgets
36            $widgets.each(function () 
37            {
38                var $widget = $(this),
39					_opts = $.extend({}, opts, $widget.data()),
40					$handle = $widget.find('h3.handle'),
41					$content = $widget.find('div').eq(0),
42					$container = $widget.parent();
43
44                $widget.data('wl_Widget', {});
45
46                //set an icon
47                if (_opts.icon) {
48                    $handle.addClass('icon');
49                    $('<a>', {
50                        'class': 'icon i_' + _opts.icon
51                    }).appendTo($handle);
52                }
53
54                //if sortable add a class
55                if (_opts.sortable) {
56                    $widget.addClass('sortable');
57                }
58
59                //if collapseable
60                if (_opts.collapseable) {
61                    //add the collapse button
62                    $('<a>', {
63                        'class': 'collapse',
64                        'title': _opts.text.collapse
65                    }).appendTo($handle);
66
67                    //collapse if set
68                    if (_opts.collapsed) {
69                        $content.hide();
70                        $widget.addClass('collapsed');
71                        $handle.find('a.collapse').attr('title', _opts.text.expand);
72                    }
73
74
75                    //handle the collapse button (touchstart is required for iOS devices)
76                    $handle.delegate('a.collapse', 'click.wl_Widget touchstart.wl_Widget', function (event) {
77                        var _opts = $widget.data('wl_Widget') || _opts,
78							_content = $widget.find('div').eq(0);
79
80                        if (_content.is(':hidden')) {
81
82                            //expand hidden content
83                            _content.slideDown(100, function () {
84                                $widget.removeClass('collapsed').data('wl_Widget').collapsed = false;
85                                $handle.find('a.collapse').attr('title', _opts.text.collapse);
86                                //callback
87                                _opts.onExpand.call($widget[0]);
88                                //save
89                                $.fn.wl_Widget.methods.save();
90
91                                //trigger resize for some plugins
92                                $(window).resize();
93                            });
94                        } else {
95
96                            //hide content
97                            $content.slideUp(100, function () {
98                                $widget.addClass('collapsed').data('wl_Widget').collapsed = true;
99                                $handle.find('a.collapse').attr('title', _opts.text.expand);
100                                //callback
101                                _opts.onCollapse.call($widget[0]);
102                                //save
103                                $.fn.wl_Widget.methods.save();
104                            });
105                        }
106                        return false;
107
108                        //doublclick is equal to collapse button
109                    }).bind('dblclick', function () {
110                        $handle.find('a.collapse').trigger('click');
111                        return false;
112                    });
113
114                }
115
116//                //handle the reload button (touchstart is required for iOS devices)
117//                $handle.delegate('a.reload', 'click.wl_Widget touchstart.wl_Widget', function (event) {
118//                    var _opts = $widget.data('wl_Widget') || _opts,
119//						_content = $widget.find('div').eq(0);
120
121//                    $widget.addClass('loading');
122//                    //set height to prevent "jumping"
123//                    _content.height($content.height());
124
125//                    //removeContent and replace it with a loading information
126//                    if (_opts.removeContent) {
127//                        _content.html(_opts.text.loading);
128//                    }
129//                    _content.load(_opts.load, function (response, status, xhr) {
130//                        $widget.removeClass('loading');
131//                        _content.height('auto');
132
133//                        //error occured
134//                        if (status == "error") {
135//                            _content.html(xhr.status + " " + xhr.statusText);
136//                        }
137
138//                        //autoreload is set
139//                        if (_opts.reload) {
140//                            clearTimeout($widget.data('wl_Widget').timeout);
141//                            $widget.data('wl_Widget').timeout = setTimeout(function () {
142//                                $handle.find('a.reload').trigger('click.wl_Widget');
143//                            }, _opts.reload * 1000);
144//                        }
145//                    });
146//                    return false;
147
148//                });
149
150
151
152                //prevent other anochrs to bubble up the DOM
153                $handle.delegate('a', 'click.wl_Widget', function (event) {
154                    event.stopPropagation();
155                    return false;
156                });
157
158//                $handle.bind('click', function () {
159//                    $handle.find('a.collapse').trigger('click');
160//                    return false;
161//                });
162
163                if
164                (_opts) $.extend($widget.data('wl_Widget'), _opts);
165
166                //ajax widgets get a reload button
167                if (_opts.load) {
168                    $('<a>', {
169                        'class': 'reload',
170                        'title': _opts.text.reload
171                    }).appendTo($handle).trigger('click.wl_Widget');
172                }
173            });
174
175
176            //Handling sortable and restoring positions
177
178
179            var $maincontent = $('#content');
180
181            //save the total count of widgets
182            if (!$maincontent.data('wl_Widget')) {
183                $maincontent.data('wl_Widget', {
184                    containercount: $('div.widgets').length,
185                    currentid: 1
186                });
187            }
188
189            //if all widgets are initialized
190            if ($maincontent.data('wl_Widget').currentid++ >= $maincontent.data('wl_Widget').containercount) {
191
192                var $container = $('div.widgets');
193
194                //get data from the storage
195                var wl_Store = new $.wl_Store('wl_' + location.pathname.toString());
196
197                //iterate thru the containers
198                $container.each(function (i, cont) {
199                    var widgets = wl_Store.get('widgets_' + i),
200						$cont = $(this);
201                    if (!widgets) return false;
202
203                    //iterate thru the widgets from the container id i
204                    $.each(widgets, function (widget, options) {
205
206                        var _widget = $('#' + widget);
207
208
209                        //widget should be collpased
210                        (options.collapsed && _widget.data('wl_Widget').collapseable) ? _widget.addClass('collapsed').find('div').eq(0).hide().data('wl_Widget', {
211                            collapsed: true
212                        }) : _widget.removeClass('collapsed').find('div').eq(0).show().data('wl_Widget', {
213                            collapsed: false
214                        });
215
216                        //position handling
217                        if (_widget.length && (_widget.prevAll('div').length != options.position || _widget.parent()[0] !== $cont[0])) {
218                            children = $cont.children('div.widget');
219                            if (children.eq(options.position).length) {
220                                _widget.insertBefore(children.eq(options.position));
221                            } else if (children.length) {
222                                _widget.insertAfter(children.eq(options.position - 1));
223                            } else {
224                                _widget.appendTo($cont);
225                            }
226                        }
227                    });
228                });
229
230
231                //use jQuery UI sortable plugin for the widget sortable function
232                $container.sortable({
233                    items: $container.find('div.widget.sortable'),
234                    containment: '#content',
235                    opacity: 0.8,
236                    distance: 5,
237                    handle: 'h3.handle',
238                    connectWith: $container,
239                    forceHelperSize: true,
240                    placeholder: 'sortable_placeholder',
241                    forcePlaceholderSize: true,
242                    zIndex: 10000,
243                    start: function (event, ui) {
244                        ui.item.data('wl_Widget').onDrag.call(ui.item[0]);
245                    },
246                    stop: function (event, ui) {
247                        ui.item.data('wl_Widget').onDrop.call(ui.item[0]);
248                        $.fn.wl_Widget.methods.save();
249                    }
250                });
251
252
253
254            }
255
256
257        } else {
258
259        }
260        if (opts) $.extend($this.data('wl_Widget'), opts);
261    });
262
263};
264
265$.fn.wl_Widget.defaults = {
266    collapsed: false,
267    load: null,
268    reload: false,
269    removeContent: true,
270    collapseable: true,
271    sortable: true,
272    text: {
273        loading: 'loading...',
274        reload: 'reload',
275        collapse: 'collapse widget',
276        expand: 'expand widget'
277    },
278    onDrag: function () { },
279    onDrop: function () { },
280    onExpand: function () { },
281    onCollapse: function () { }
282};
283$.fn.wl_Widget.version = '1.1';
284
285
286$.fn.wl_Widget.methods = {
287    save: function () {
288
289        var $containers = $('div.widgets'),
290			wl_Store = new $.wl_Store('wl_' + location.pathname.toString());
291
292        //iterate thru the containers
293        $containers.each(function (containerid, e) {
294            var _widgets = {};
295
296            //get info from all widgets from that container
297            $(this).find('div.widget').each(function (pos, e) {
298                var _t = $(this);
299                _widgets[this.id] = {
300                    position: pos,
301                    collapsed: _t.find('div').eq(0).is(':hidden')
302                };
303            });
304
305            //store the info
306            wl_Store.save('widgets_' + containerid, _widgets);
307        });
308
309    },
310    set: function () {
311        var $this = $(this),
312			options = {};
313        if (typeof arguments[0] === 'object') {
314            options = arguments[0];
315        } else if (arguments[0] && arguments[1] !== undefined) {
316            options[arguments[0]] = arguments[1];
317        }
318        $.each(options, function (key, value) {
319            if ($.fn.wl_Widget.defaults[key] !== undefined || $.fn.wl_Widget.defaults[key] == null) {
320                $this.data('wl_Widget')[key] = value;
321            } else {
322                $.error('Key "' + key + '" is not defined');
323            }
324        });
325
326    }
327};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.