PageSourceSearch

https://blakeresnick.com/wp-content/themes/bresnick/assets/js/jquery.open-close.js?ver=1.1

js blakeresnick.com collected 2026-10-07 18:27:26 UTC 7,142 bytes, 203 lines download raw bytes

1/*open-close init example
2
3$('div.open-close').openClose({
4    activeClass: 'active',
5    opener: '.opener',
6    slider: '.slide',
7    animSpeed: 400,
8    effect: 'slide'
9});*/
10
11/*
12 * jQuery Open/Close plugin
13 */
14;(function ($) {
15    function OpenClose(options) {
16        this.options = $.extend({
17            addClassBeforeAnimation: true,
18            hideOnClickOutside: false,
19            activeClass: 'active',
20            opener: '.opener',
21            slider: '.slide',
22            animSpeed: 400,
23            effect: 'slide',
24            event: 'click',
25            accordion: false,
26            scroll: false,
27            scrollSpeed: 400,
28            animEnd: function () {
29                if (this.options.scroll && this.holder.hasClass(this.options.activeClass)) {
30                    $('html,body').animate({
31                        scrollTop: $(this.holder).offset().top
32                    }, this.options.scrollSpeed);
33                }
34            }
35        }, options);
36        this.init();
37    }
38
39    OpenClose.prototype = {
40        init: function () {
41            if (this.options.holder) {
42                this.findElements();
43                this.attachEvents();
44                this.makeCallback('onInit');
45            }
46        },
47        findElements: function () {
48            this.holder = $(this.options.holder);
49            this.opener = this.holder.find(this.options.opener);
50            this.slider = this.holder.find(this.options.slider);
51        },
52        attachEvents: function () {
53            // add handler
54            var self = this;
55            this.eventHandler = function (e) {
56                e.preventDefault();
57                if (self.slider.hasClass(slideHiddenClass)) {
58                    self.showSlide();
59                } else {
60                    self.hideSlide();
61                }
62            };
63            self.opener.bind(self.options.event, this.eventHandler);
64
65            // hover mode handler
66            if (self.options.event === 'over') {
67                self.opener.bind('mouseenter', function () {
68                    self.showSlide();
69                });
70                self.holder.bind('mouseleave', function () {
71                    self.hideSlide();
72                });
73            }
74
75            // outside click handler
76            self.outsideClickHandler = function (e) {
77                if (self.options.hideOnClickOutside) {
78                    var target = $(e.target);
79                    if (!target.is(self.holder) && !target.closest(self.holder).length) {
80                        self.hideSlide();
81                    }
82                }
83            };
84
85            // set initial styles
86            if (this.holder.hasClass(this.options.activeClass)) {
87                $(document).bind('click touchstart', self.outsideClickHandler);
88            } else {
89                this.slider.addClass(slideHiddenClass);
90            }
91        },
92        showSlide: function () {
93            var self = this;
94            if (self.options.addClassBeforeAnimation) {
95                self.holder.addClass(self.options.activeClass);
96            }
97            self.slider.removeClass(slideHiddenClass);
98            $(document).bind('click touchstart', self.outsideClickHandler);
99
100            self.makeCallback('animStart', true);
101            toggleEffects[self.options.effect].show({
102                box: self.slider,
103                speed: self.options.animSpeed,
104                complete: function () {
105                    if (!self.options.addClassBeforeAnimation) {
106                        self.holder.addClass(self.options.activeClass);
107                    }
108                    self.makeCallback('animEnd', true);
109                }
110            });
111
112            if (self.options.accordion) {
113                self.holder.siblings().each(function () {
114                    if ($(this).data('OpenClose'))
115                        $(this).data('OpenClose').hideSlide(true);
116                })
117            }
118        },
119        hideSlide: function (ghost, callback) {
120            var self = this;
121            if (self.options.addClassBeforeAnimation) {
122                self.holder.removeClass(self.options.activeClass);
123            }
124            $(document).unbind('click touchstart', self.outsideClickHandler);
125
126            self.makeCallback('animStart', false);
127            toggleEffects[self.options.effect].hide({
128                box: self.slider,
129                speed: self.options.animSpeed,
130                complete: function () {
131                    if (!self.options.addClassBeforeAnimation) {
132                        self.holder.removeClass(self.options.activeClass);
133                    }
134                    self.slider.addClass(slideHiddenClass);
135                    if (!ghost) self.makeCallback('animEnd', false);
136                    if (callback) callback();
137                }
138            });
139        },
140        destroy: function () {
141            this.slider.removeClass(slideHiddenClass).css({display: ''});
142            this.opener.unbind(this.options.event, this.eventHandler);
143            this.holder.removeClass(this.options.activeClass).removeData('OpenClose');
144            $(document).unbind('click touchstart', this.outsideClickHandler);
145        },
146        makeCallback: function (name) {
147            if (typeof this.options[name] === 'function') {
148                var args = Array.prototype.slice.call(arguments);
149                args.shift();
150                this.options[name].apply(this, args);
151            }
152        }
153    };
154
155    // add stylesheet for slide on DOMReady
156    var slideHiddenClass = 'js-slide-hidden';
157    $(function () {
158        var tabStyleSheet = $('<style type="text/css">')[0];
159        var tabStyleRule = '.' + slideHiddenClass;
160        tabStyleRule += '{position:absolute !important;left:-9999px !important;top:-9999px !important;display:block !important}';
161        if (tabStyleSheet.styleSheet) {
162            tabStyleSheet.styleSheet.cssText = tabStyleRule;
163        } else {
164            tabStyleSheet.appendChild(document.createTextNode(tabStyleRule));
165        }
166        $('head').append(tabStyleSheet);
167    });
168
169    // animation effects
170    var toggleEffects = {
171        slide: {
172            show: function (o) {
173                o.box.stop(true).hide().slideDown(o.speed, o.complete);
174            },
175            hide: function (o) {
176                o.box.stop(true).slideUp(o.speed, o.complete);
177            }
178        },
179        fade: {
180            show: function (o) {
181                o.box.stop(true).hide().fadeIn(o.speed, o.complete);
182            },
183            hide: function (o) {
184                o.box.stop(true).fadeOut(o.speed, o.complete);
185            }
186        },
187        none: {
188            show: function (o) {
189                o.box.hide().show(0, o.complete);
190            },
191            hide: function (o) {
192                o.box.hide(0, o.complete);
193            }
194        }
195    };
196
197    // jQuery plugin interface
198    $.fn.openClose = function (opt) {
199        return this.each(function () {
200            jQuery(this).data('OpenClose', new OpenClose($.extend(opt, {holder: this})));
201        });
202    };
203}(jQuery));

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.