PageSourceSearch

https://www.cidect.org/wp-content/themes/Artificial-Reason-WP/js/buttons.js

js cidect.org collected 2026-10-09 22:19:33 UTC 3,606 bytes, 112 lines download raw bytes

1/*! @license
2 *  Project: Buttons
3 *  Description: A highly customizable CSS button library built with Sass and Compass
4 *  Author: Alex Wolfe
5 *  License: Apache License v2.0
6 */
7
8// the semi-colon before function invocation is a safety net against concatenated
9// scripts and/or other plugins which may not be closed properly.
10;(function ( $, window, document, undefined ) {
11    'use strict';
12
13    // undefined is used here as the undefined global variable in ECMAScript 3 is
14    // mutable (ie. it can be changed by someone else). undefined isn't really being
15    // passed in so we can ensure the value of it is truly undefined. In ES5, undefined
16    // can no longer be modified.
17
18    // window and document are passed through as local variable rather than global
19    // as this (slightly) quickens the resolution process and can be more efficiently
20    // minified (especially when both are regularly referenced in your plugin).
21
22    // Create the defaults once
23    var pluginName = "menuButton";
24    var menuClass = ".button-dropdown";
25    var defaults = {
26        propertyName: "value"
27    };
28
29    // The actual plugin constructor
30    function Plugin( element, options ) {
31
32        //SET OPTIONS
33        this.options = $.extend( {}, defaults, options );
34        this._defaults = defaults;
35        this._name = pluginName;
36
37        //REGISTER ELEMENT
38        this.$element = $(element);
39
40        //INITIALIZE
41        this.init();
42    }
43
44    Plugin.prototype = {
45        constructor: Plugin,
46
47        init: function() {
48            // WE DON'T STOP PROPGATION SO CLICKS WILL AUTOMATICALLY
49            // TOGGLE AND REMOVE THE DROPDOWN
50            this.toggle();
51        },
52
53        toggle: function(el, options) {
54            if(this.$element.data('dropdown') === 'show') {
55                this.hideMenu();
56            }
57            else {
58                this.showMenu();
59            }
60        },
61
62        showMenu: function() {
63            this.$element.data('dropdown', 'show');
64            this.$element.find('ul').show();
65        },
66
67        hideMenu: function() {
68            this.$element.data('dropdown', 'hide');
69            this.$element.find('ul').hide();
70        }
71    };
72
73    // A really lightweight plugin wrapper around the constructor,
74    // preventing against multiple instantiations
75    $.fn[pluginName] = function ( options ) {
76        return this.each(function () {
77
78            // TOGGLE BUTTON IF IT EXISTS
79            if ($.data(this, "plugin_" + pluginName)) {
80                $.data(this, "plugin_" + pluginName).toggle();
81            }
82            // OTHERWISE CREATE A NEW INSTANCE
83            else {
84                $.data(this, "plugin_" + pluginName, new Plugin( this, options ));
85            }
86        });
87    };
88
89    //CLOSE OPEN DROPDOWN MENUS IF CLICKED SOMEWHERE ELSE
90    $(document).on('click', function(e) {
91        $.each($('[data-buttons=dropdown]'), function(i, value) {
92            if ($(e.target.offsetParent)[0] != $(this)[0]) {
93                if ($.data(this, "plugin_" + pluginName)) {
94                    $.data(this, "plugin_" + pluginName).hideMenu();
95                    $(this).find('ul').hide();
96                }
97            }
98        });
99    });
100
101    //DELEGATE CLICK EVENT FOR DROPDOWN MENUS
102    $(document).on('click', '[data-buttons=dropdown]', function(e) {
103        var $dropdown = $(e.currentTarget);
104        $dropdown.menuButton();
105    });
106
107    //IGNORE CLICK EVENTS FROM DISPLAY BUTTON IN DROPDOWN
108    $(document).on('click', '[data-buttons=dropdown] > a', function(e) {
109        e.preventDefault();
110    });
111
112})( 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.