PageSourceSearch

https://hetarena.com/wp-content/plugins/standard-widget-extensions/js/standard-widget-extensions.js?ver=7.1.2

js hetarena.com collected 2026-10-02 03:51:50 UTC 19,448 bytes, 440 lines download raw bytes

1/*
2 standard-widget-extensions.js
3 Copyright 2013, 2014 Hirokazu Matsui (blogger323)
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License, version 2, as
7 published by the Free Software Foundation.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 GNU General Public License for more details.
13
14 */
15/*
16  hm-swe-accordion-head: a class for headings
17  hm-swe-collapsed: a class for headings with collapsed area
18  hm-swe-expanded: a class for headings with expanded area
19 */
20(function ($, window, document, undefined) {
21
22    $(document).ready(function () {
23        var cook = null;
24        var contentid = "#" + swe.maincol_id;
25        var widget = '.' + swe.widget_class;
26        var slide_duration = parseInt(swe.slide_duration, 10);
27
28        var CONDITION = {
29            content_height: 0, /* including margins, borders and paddings */
30            content_top: 0,
31            content_margin_top: 0,
32            window_height: 0,
33            mode: parseInt(swe.scroll_mode, 10), /* 2: switch back */
34            header_space: 0, /* will be set in resizefunc() */
35            direction: 0,
36            prevscrolltop: -1
37        };
38
39        function init_sidebar(sidebar, param_id, percent_width, disable_iflt, float_attr_check_mode) {
40            sidebar.o =  null; // jQuery object
41            sidebar.height = 0; /* include borders and paddings */
42            sidebar.fixed = 0;
43            sidebar.default_offset = { top: 0, left: 0 };
44            sidebar.margin_top = 0;
45            sidebar.margin_left = 0;
46            sidebar.width = 0;
47            sidebar.absolute_adjustment_top = 0;
48            sidebar.absolute_adjustment_left = 0;
49            sidebar.percent_width = 0;
50            sidebar.disable_iflt = 0;
51            sidebar.float_attr_check_mode = parseInt(float_attr_check_mode, 10);
52
53            sidebar.mode = 0; // 0:disabled, 1:long, 2:short
54
55            sidebar.previoustop = 0;
56
57            if (param_id) {
58                sidebar.id = '#' + param_id;
59                if (sidebar.id && $(sidebar.id).length > 0) {
60                    sidebar.o = $(sidebar.id);
61                    sidebar.parent = sidebar.o.parent();
62                    sidebar.margin_top = parseInt(sidebar.o.css('margin-top'), 10);
63                    sidebar.percent_width = parseFloat(percent_width);
64                    sidebar.disable_iflt = parseInt(disable_iflt, 10);
65
66                }
67            }
68        }
69
70        var SIDEBAR1 = {};
71        var SIDEBAR2 = {};
72        var DISABLED_SIDEBAR = 0;
73        var LONG_SIDEBAR     = 1;
74        var SHORT_SIDEBAR    = 2;
75
76        swe.sidebar1 = SIDEBAR1;
77        swe.sidebar2 = SIDEBAR2;
78        swe.condition = CONDITION;
79
80        init_sidebar(SIDEBAR1, swe.sidebar_id, swe.proportional_sidebar, swe.disable_iflt, swe.float_attr_check_mode);
81        init_sidebar(SIDEBAR2, swe.sidebar_id2, swe.proportional_sidebar2, swe.disable_iflt2, swe.float_attr_check_mode2);
82
83        if (swe.accordion_widget) {
84            function init_accordion() {
85
86
87                if (typeof JSON !== "undefined") {
88                    $.cookie.json = true;
89                    cook = $.cookie('hm_swe');
90                }
91
92                var i;
93                for (i = 0; i < swe.custom_selectors.length; i++) {
94
95                    $('body').off('mouseenter', swe.custom_selectors[i] + ' ' + swe.heading_string)
96                        .off('mouseleave', swe.custom_selectors[i] + ' ' + swe.heading_string);  // first remove them
97
98                    // cursor setting
99                    $('body').on('mouseenter', swe.custom_selectors[i] + ' ' + swe.heading_string,
100                        function () {
101                            $(this).css("cursor", "pointer");
102                        })
103                        .on('mouseleave', swe.custom_selectors[i] + ' ' + swe.heading_string,
104                        function () {
105                            $(this).css("cursor", "default");
106                        }
107                    );
108
109                    var headings = $(swe.custom_selectors[i] + ' ' + swe.heading_str
109ing).addClass("hm-swe-accordion-head");
110
111                    // restore status, set heading markers
112                    $(swe.custom_selectors[i]).each(function () {
113                        var heading = $(this).children(swe.heading_string);
114
115                        /*
116                          Priority:
117                          1. cookie
118                          2. initially collapsed setting
119                          3. CSS display = none
120                          4. class attribute hm-swe-expanded/hm-swe-collapsed (in theme files)
121                         */
122                        if ((cook && cook[$(this).attr('id')] == "t") ||
123                            (!cook && !swe.initially_collapsed && heading.next().css('display') !== 'none')) {
124                            if ((! heading.hasClass('hm-swe-expanded')) && (! heading.hasClass('hm-swe-collapsed'))) {
125                                heading.addClass('hm-swe-expanded');
126                            }
127                        }
128                        else {
129                            heading.addClass('hm-swe-collapsed');
130                        }
131
132                    });
133
134                    headings.filter('.hm-swe-expanded').next().show();
135                    headings.filter('.hm-swe-collapsed').next().hide();
136
137                    $('body').off('click', swe.custom_selectors[i] + ' ' + swe.heading_string); // first remove current
138
139                    // click event handler
140                    $('body').on('click', swe.custom_selectors[i] + ' ' + swe.heading_string, function () {
141                        var c = $(this).next();
142                        if (c) {
143                            if (c.is(":hidden")) {
144                                if (swe.single_expansion) {
145                                    $(".hm-swe-accordion-head").not(this).removeClass('hm-swe-expanded').addClass('hm-swe-collapsed');
146                                    $(".hm-swe-accordion-head").not(this).next().slideUp(slide_duration);
147                                }
148
149                                $(this).removeClass('hm-swe-collapsed').addClass('hm-swe-expanded');
150                                c.slideDown(slide_duration, set_widget_status);
151                            }
152                            else {
153                                $(this).removeClass('hm-swe-expanded').addClass('hm-swe-collapsed');
154                                c.slideUp(slide_duration, set_widget_status);
155                            }
156                        }
157                    });
158                } // end of for
159            }  // end of function
160
161            // save current states in cookies
162            function set_widget_status() {
163                if (typeof JSON !== "undefined") {
164                    var c2 = {};
165                    var i;
166                    for (i = 0; i < swe.custom_selectors.length; i++) {
167
168                        $(swe.custom_selectors[i] + ' ' + swe.heading_string).each(function () {
169                            if ($(this).next().is(':visible')) {
170                                c2[$(this).parent().attr('id')] = "t";
171                            }
172                        });
173                        $.cookie('hm_swe', c2, { path: '/' });
174                    } /* for */
175                }
176                if (typeof resizefunc === 'function') {
177                    resizefunc();
178                    /* because the height of the sidebar has changed. */
179                }
180            }
181
182            init_accordion();
183
184        } // if accordion_widget
185
186        if (swe.scroll_stop && $(contentid).length > 0) {
187
188            function scrollfunc() {
189                var curscrolltop = $(window).scrollTop();
190
191                if (SIDEBAR1.o) {
192                    manage_sidebar(SIDEBAR1, curscrolltop);
193                }
194                if (SIDEBAR2.o) {
195                    manage_sidebar(SIDEBAR2, curscrolltop);
196                }
197
198                CONDITION.direction = curscrolltop - CONDITION.prevscrolltop;
199                CONDITION.prevscrolltop = curscrolltop;
200            }
201
202            function manage_sidebar(sidebar, curscrolltop) {
203
204                if (sidebar.mode === DISABLED_SIDEBAR) {
205                    // For z-index based Themes, do not use css("position", "static")
206                    sidebar.o.css("position", "relative");
207                    sidebar.o.css("top", "0");
208                    sidebar.o.css("left", "0");
209                    sidebar.o.css('width', '');
210                    sidebar.o.css('margin-left', '');
211                    return;
212                }
213
214                var sidebar_cur_top = sidebar.o.offset().top;
215                sidebar_cur_top -= sidebar.margin_top;
216
217                if ( !swe.ignore_footer &&
218                    (   (sidebar.mode == LONG_SIDEBAR &&
219                         curscrolltop >= CONDITION.content_top + CONDITION.content_height - CONDITION.window_height) ||
220                        (sidebar.mode == SHORT_SIDEBAR &&
221                         curscrolltop >= CONDITION.content_top + CONDITION.content_height - sidebar.height - CONDITION.header_space)
222                    )) {
223                    // scroll again with footer
224                    sidebar.o.css("position", "absolute");
225                    sidebar.o.css("top", CONDITION.content_top + CONDITION.content_height
226                        - sidebar.height - sidebar.absolute_adjustment_top);
227                    sidebar.o.css("left", sidebar.default_offset.left - sidebar.absolute_adjustment_left);
228                    sidebar.o.css("width", sidebar.width);
229                    sidebar.o.css('margin-left', sidebar.margin_left);
230                    sidebar.fixed = 0;
231                }
232                else if ((CONDITION.mode == 2 || sidebar.mode == SHORT_SIDEBAR) && curscrolltop < sidebar.default_offset.top - CON
232DITION.header_space) {
233                    // For z-index based Themes, do not use css("position", "static")
234                    sidebar.o.css("position", "relative");
235                    sidebar.o.css("top", "0");
236                    sidebar.o.css("left", "0");
237                    sidebar.o.css("width", '');
238                    sidebar.o.css('margin-left', '');
239                    sidebar.fixed = 0;
240                }
241                else if (CONDITION.mode == 2 && sidebar.mode == LONG_SIDEBAR &&  curscrolltop < CONDITION.prevscrolltop &&
242                        curscrolltop < sidebar_cur_top - CONDITION.header_space) {
243                    // FOR MODE2 BLOCK
244                    // at the top of sidebar
245
246                    sidebar.o.css("position", "fixed");
247                    sidebar.o.css("top", CONDITION.header_space); // no need of margin-top
248                    sidebar.o.css("left", sidebar.default_offset.left - $(window).scrollLeft());
249                    sidebar.o.css("width", sidebar.width);
250                    sidebar.o.css('margin-left', sidebar.margin_left);
251                    sidebar.fixed = 1;
252                }
253                else if ((CONDITION.mode == 2 && sidebar.mode == LONG_SIDEBAR && curscrolltop >= sidebar_cur_top + sidebar.height - CONDITION.window_height &&
254                   curscrolltop > CONDITION.prevscrolltop) ||
255                          (CONDITION.mode != 2 && sidebar.mode == LONG_SIDEBAR && curscrolltop >= sidebar.default_offset.top + sidebar.height - CONDITION.window_height)) {
256                    // at the bottom of sidebar
257                    sidebar.o.css("position", "fixed");
258                    sidebar.o.css("top", CONDITION.window_height - sidebar.height);
259                    sidebar.o.css("left", sidebar.default_offset.left - $(window).scrollLeft());
260                    sidebar.o.css("width", sidebar.width);
261                    sidebar.o.css('margin-left', sidebar.margin_left);
262                    sidebar.fixed = 1;
263                }
264                else if (CONDITION.mode == 2 && sidebar.mode == LONG_SIDEBAR && (curscrolltop - CONDITION.prevscrolltop) * CONDITION.direction < 0 && sidebar.fixed) {
265                    // FOR MODE2 BLOCK
266                    // the direction has changed
267                    // mode2 absolute position
268
269                    sidebar.o.css("position", "absolute");
270                    sidebar.o.css("top", sidebar_cur_top - sidebar.absolute_adjustment_top);
271                    sidebar.o.css("left", sidebar.default_offset.left - sidebar.absolute_adjustment_left);
272                    sidebar.o.css("width", sidebar.width);
273                    sidebar.o.css('margin-left', sidebar.margin_left);
274                    sidebar.fixed = 0;
275                }
276                else if (sidebar.mode == SHORT_SIDEBAR) {
277                    // shorter sidebar as fixed
278                    sidebar.o.css("position", "fixed");
279                    sidebar.o.css("top", CONDITION.header_space); // no need of margin-top
280                    sidebar.o.css("left", sidebar.default_offset.left - $(window).scrollLeft());
281                    sidebar.o.css("width", sidebar.width);
282                    sidebar.o.css('margin-left', sidebar.margin_left);
283                    sidebar.fixed = 1;
284                }
285                else if (CONDITION.mode != 2) {
286                    // For z-index based Themes, do not use css("position", "static")
287                    sidebar.o.css("position", "relative");
288                    sidebar.o.css("top", "0");
289                    sidebar.o.css("left", "0");
290                    sidebar.o.css("width", '');
291                    sidebar.o.css('margin-left', '');
292                    sidebar.fixed = 0;
293                }
294                else {
295                    // continue absolute
296                }
297                sidebar.previoustop = sidebar_cur_top;
298
299            }
300
301            function resizefunc(fromTimer) {
302                var c = $(contentid);
303                CONDITION.content_top = c.offset().top;
304                CONDITION.content_margin_top = parseInt(c.css('margin-top'), 10);
305                CONDITION.content_top -= CONDITION.content_margin_top;
306
307                CONDITION.content_height = c.outerHeight(true);
308
309                CONDITION.window_height = $(window).height();
310                CONDITION.prevscrolltop = -1;
311                CONDITION.direction = 0;
312
313                CONDITION.header_space = parseInt(swe.header_space, 
31310);
314                var adminbar = $('#wpadminbar');
315                if (adminbar.length > 0) {
316                    CONDITION.header_space += adminbar.height();
317                }
318
319                if (SIDEBAR1.o) {
320                    resize_sidebar(SIDEBAR1);
321                }
322                if (SIDEBAR2.o) {
323                    resize_sidebar(SIDEBAR2);
324                }
325
326                if (SIDEBAR1.o && SIDEBAR1.mode != DISABLED_SIDEBAR && SIDEBAR2.o && SIDEBAR2.mode != DISABLED_SIDEBAR) {
327                    CONDITION.content_height = Math.max(CONDITION.content_height,
328                        SIDEBAR1.height + SIDEBAR1.default_offset.top - CONDITION.content_top,
329                        SIDEBAR2.height + SIDEBAR2.default_offset.top - CONDITION.content_top);
330                }
331
332                // After the content height fix, we finalize the sidebar mode.
333                if (SIDEBAR1.o) { finalize_sidebarmode(SIDEBAR1); }
334                if (SIDEBAR2.o) { finalize_sidebarmode(SIDEBAR2); }
335
336                scrollfunc();
337
338                if (fromTimer === true && swe.recalc_after > 0 && swe.recalc_count > 0) {
339                    if (swe.recalc_count < 10000) {
340                        swe.recalc_count--;
341                    }
342                    setTimeout( resizefunc, swe.recalc_after * 1000, true);
343                }
344
345            }
346
347            function is_enabled(sidebar) {
348                var f = sidebar.o.css('float');
349                return ( $(window).width() >= sidebar.disable_iflt &&
350                    ( (! sidebar.float_attr_check_mode) || f == 'left' || f == 'right') );
351
352            }
353
354            function resize_sidebar(sidebar) {
355                sidebar.height = sidebar.o.outerHeight(true);
356
357                sidebar.fixed = 0;
358                sidebar.previoustop = 0;
359
360                sidebar.o.css("position", "relative");
361                sidebar.o.css("top", "0");
362                sidebar.o.css("left", "0");
363
364                sidebar.o.css('width', '');
365                sidebar.width = parseFloat(sidebar.o.css('width')); // using css('width') (not width())
366                // Use a fixed width because the parent will change.
367
368                sidebar.o.css('margin-left', '');
369                sidebar.margin_left = parseFloat(sidebar.o.css('margin-left'), 10);  // might be float in responsive themes
370
371                sidebar.default_offset = sidebar.o.offset();
372                if (!sidebar.default_offset) {
373                    return; // something wrong.
374                }
375
376                sidebar.default_offset.top  -= sidebar.margin_top;
377                sidebar.default_offset.left -= sidebar.margin_left;
378
379                // determine the adjustment value for the absolute position
380                // find a parent which has a position other than static
381                var o = sidebar.o.offsetParent();
382                sidebar.absolute_adjustment_top  = o.offset().top;  // TODO: margin adjustment needed?
383                sidebar.absolute_adjustment_left = o.offset().left;
384
385                if ( ! is_enabled(sidebar) ) {
386                    sidebar.mode = DISABLED_SIDEBAR;
387                }
388                else {
389                    sidebar.mode = LONG_SIDEBAR; // Temporarily. We will finalize it after.
390                }
391
392            } // function resize_sidebar
393
394            function finalize_sidebarmode(sidebar) {
395
396                if (sidebar.default_offset.top + sidebar.height >= CONDITION.content_top + CONDITION.content_height ||
397                    ! is_enabled(sidebar)) {
398                    sidebar.mode = DISABLED_SIDEBAR;
399                }
400                else if (sidebar.height + CONDITION.header_space <= CONDITION.window_height) {
401                    sidebar.mode = SHORT_SIDEBAR;
402                }
403                else {
404                    sidebar.mode = LONG_SIDEBAR
405                }
406
407            } // finalize_sidebarmode
408
409            swe.resizeHandler = resizefunc;
410
411            $(window).scroll(scrollfunc);
412            $(window).resize(resizefunc);
413
414
415
416            swe.recalc_after = parseInt(swe.recalc_after, 10);
417            swe.recalc_count = parseInt(swe.recalc_count, 10);
418            resizefunc(true);
419
420        } // if scroll_stop
421
422        function reloadfunc() {
423            if (swe.accordion_widget) {
424                init_accordion();
425            }
426
427            if (swe.scroll_stop && $(contentid).length) {
428                init_sidebar(SIDEBAR1, swe.sidebar_id, swe.proportional_sidebar, swe.disable_iflt, swe.float_attr_check_mode);
429                init_sidebar(SIDEBAR2, swe.sidebar_id2, swe.proportional_sidebar2, swe.disable_iflt2, swe.float_attr_check_mode2);
430                swe.resizeHandler();
431            }
432        }
433
434        swe.reloadHandler = reloadfunc;
435
436        // Tabs (test)
437        //$( "#tabs-sidebar-3" ).tabs();
438
439    }); // ready function
440})(jQuery, window, document);

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.