All Downloads are FREE. Search and download functionalities are using the official Maven repository.

META-INF.web-resources.voila-runtime.jquery.src.Plugins.jquery.dropdown.js Maven / Gradle / Ivy

The newest version!
/// 
(function($) {
    $.fn.DhoverClass = function(className) {
        return $(this).hover(function() { $(this).addClass(className); }, function() { $(this).removeClass(className); });
    }
    function getDulyOffset(target, w, h) {
        var pos = target.offset();
        var height = target.outerHeight();
        var newpos = { left: pos.left, top: pos.top + height - 1 }
        var bw = document.documentElement.clientWidth;
        var bh = document.documentElement.clientHeight;
        if ((newpos.left + w) >= bw) {
            newpos.left = bw - w - 2;
        }
        if ((newpos.top + h) >= bh && bw > newpos.top) {
            newpos.top = pos.top - h - 2;
        }
        return newpos;
    }
    function returnfalse() { return false; };
    $.fn.dropdown = function(o) {
        var options = $.extend({
            vinputid: null,
            cssClass: "bbit-dropdown",
            containerCssClass: "dropdowncontainer",
            dropwidth: false,
            dropheight: "auto",
            autoheight: true,
            selectedchange: false,
            items: [],
            selecteditem: false,
            parse: {
                name: "list",
                render: function(parent) {
                    var p = this.target;
                    var ul = $("
    "); if (this.items && this.items.length > 0) { $.each(this.items, function() { var item = this; var d = $("
    ").html(item.text); var li = $("
  • ").DhoverClass("hover").append(d) .click(function() { p.SelectedChanged(item); }); if (item.classes && item.classes != "") { d.addClass(item.classes); } ul.append(li); }); } parent.append(ul); }, items: [], setValue: function(item) { }, target: null } }, o); var me = $(this); var v; if (options.vinputid) { v = $("#" + options.vinputid); } if (options.selecteditem) { me.val(options.selecteditem.text); if (v && options.selecteditem.value) { v.val(options.selecteditem.value); } } var requireCss = { height: 18, "padding-top": "1px", "padding-bottom": "1px" }; me.css(requireCss).addClass(options.cssClass).DhoverClass("hover"); if (!options.dropwidth) { options.dropwidth = me.outerWidth(); } var d = $("
    ").addClass(options.containerCssClass) .css({ position: "absolute", "z-index": "9999", "overflow": "auto", width: options.dropwidth, display: "none", "border": "solid 1px #555", background: "#fff" }) .click(function(event) { event.stopPropagation(); }) .appendTo($("body")); if (options.autoheight) { d.css("max-height", options.dropheight); } else { d.css("height", options.dropheight); } if ($.browser.msie) { if (parseFloat($.browser.version) <= 6) { var ie6hack = $("
    ").css({ position: "absolute", "z-index": "-2", "overflow": "hidden", "height": "100%", width: "100%" }); ie6hack.append($('')); d.append(ie6hack); } } me.click(function() { var m = this; if (d.attr("isinited") != "true") { options.parse.items = options.items; if (options.selecteditem) { options.parse.setValue.call(d, options.selecteditem); } options.parse.render(d); d.attr("isinited", "true"); } var pos = getDulyOffset(me, options.dropwidth, options.dropheight); d.css(pos); d.show(); if ($.browser.msie) { if (parseFloat($.browser.version) <= 6) { var h = d.height(); if (h > options.dropheight) { d.height(options.dropheight); } } } $(document).one("click", function(event) { d.hide(); }); return false; }); me.SelectedChanged = function(t) { var b = true; if (options.selectedchange) { b = options.selectedchange.apply(me, [t]); } if (b != false) { me.val(t.text); if (v && t.value) { v.val(t.value); } } d.hide(); }; me.Cancel = function() { d.hide(); } options.parse.target = me; return me; } })(jQuery);




© 2015 - 2025 Weber Informatics LLC | Privacy Policy