select2 icon indicating copy to clipboard operation
select2 copied to clipboard

Select2 & Popup

Open michelreyes opened this issue 14 years ago • 13 comments

I was traying with the non official select2 v3 on my popup plugin, and all going bad. In the previous version (select2 v2.1) I put it on my popup plugin and it works correctly, when i select an option, now in the select2 v3 I select an option and my popup automaticaly close

michelreyes avatar Jul 06 '12 16:07 michelreyes

can you create a jsfiddle please?

ivaynberg avatar Jul 06 '12 16:07 ivaynberg

// // monoPopup.js // flujo_informativo //
// Created by michel on 2012-06-30. // Copyright 2012 michel. All rights reserved. //

// The popups system allows popups and popup menus to easily be created and shown/hidden. var MonoPopup = {

// An array of currently-active popups. popups: {},

// Show a popup. showPopup: function(id, button, options) {

// If this popup is already being shown, hide it.
if (MonoPopup.popups[id]) {
    MonoPopup.hidePopup(id);
    return false;
}


// Hide all other popups.
MonoPopup.hideAllPopups();

// Get the popup element if it exists, or create it if it doesn't.
var popup = $("#"+id);
popup.addClass("popup");

// Position the button's parent element (which should be a popupWrapper div) relatively so the popup within
// it can be positioned accordingly.
if (button.parent().css("position") != "absolute") button.parent().css("position", "relative");
button.parent().addClass("active");

// Make the popup button active.
if (options.callbackOpen && typeof options.callbackOpen == "function") options.callbackOpen.call(popup);

// Show and position the popup.
popup
    .css({position: "absolute", top: button.outerHeight(true) + 20 - parseInt(button.css("marginBottom")) + (options.offset ? options.offset[1] || 0 : 0)})
    .show()
    .data("options", options);
// Alignment & Arrow
switch (options.alignment){
    case "left": {
        var aRight = ( $(window).outerWidth() - (button.offset().left + button.outerWidth()) );
        popup.css({ right: aRight });
    }break;
    case "center": {
        var aCenter = (popup.outerWidth() / 2) - (button.outerWidth() / 2);
        popup.css({ left: -aCenter });
        popup.addClass("center");
    }break;
    default: {
        popup.addClass("right");
    }
}

this.popups[id] = popup;

// Make sure the popup is within the document bounds.
//if (popup.offset().left < 0) popup.css(options.alignment, popup.offset().left);

// Add a click handler to the body to hide the popup (as long as it's not a click on the popup button.)
$(document).unbind("mouseup.popup").bind("mouseup.popup", function(e) {
    if ($(e.target).get(0) != button.get(0) && !button.has(e.target).length) 
        MonoPopup.hidePopup(id);
});

// However, we don't want this acting when the popup itself is clicked on.
popup.bind("mouseup", function(e) { return false; });

},

// Hide a popup. hidePopup: function(id) { var popup = MonoPopup.popups[id]; if (popup) { popup.hide().removeClass("popup"); popup.parent().removeClass("active"); if (typeof popup.data("options").callbackClose == "function") popup.data("options").callbackClose.call(popup); MonoPopup.popups[id] = false; } },

// Hide all popups. hideAllPopups: function() { for (var i in MonoPopup.popups) { MonoPopup.hidePopup(i); } }

};

$.fn.popup = function(options) {

options = options || {};

var button = $(this);
var wrapper = button.parent(".popupWrapper");
var popup = wrapper.find(".popupContent");

// Agregar le id al popupContent
popup.attr("id", "popup-"+button.attr("id"));


// Add a click handler to the popup button to show the popup.
button.click(function(e){
    MonoPopup.showPopup(popup.attr("id"), button, {
        alignment: options.alignment || "right"
    });
    e.preventDefault();

});

return wrapper;

};

michelreyes avatar Jul 06 '12 16:07 michelreyes

can you please make a fiddle here: http://jsfiddle.net/ so i can reproduce the problem...

ivaynberg avatar Jul 06 '12 16:07 ivaynberg

the previous code is my monoPopup.js (I'm spaeak spanish for tha reason my english is not good I'm traying to comunicate as i can) well now a put my css and the html markup for the popup plugin

THE CSS CODE

/* ========================================================================== POPUP ========================================================================== */

.popupContent{ display: none; }

.popup { position: absolute; z-index: 9999; display: none; height: auto; margin-bottom: 20px; min-width: 300px; background: #FFFFFF; border: 1px solid #e5e5e5; color: #333333; padding: 20px 0px;

-webkit-box-shadow: 0 3px 6px rgba(0, 0, 0, 0.15);
     -moz-box-shadow: 0 3px 6px rgba(0, 0, 0, 0.15);
                box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);

}

.popup-inner { max-height: 235px; padding: 0px 20px; margin-bottom: 10px; }

.popup:after, .popup:before{ bottom: 100%; border: solid transparent; content: " "; height: 0; width: 0; position: absolute; pointer-events: none; }

.popup:after { border-bottom-color: #fff; border-width: 9px; right: 11px; margin-left: -9px; }

.popup:before { border-bottom-color: #e5e5e5; border-width: 10px; right: 10px; margin-left: -10px; }

.popup.right:after { left: 17px; }

.popup.right:before { left: 17px; }

.popup.center:after { left: 50%; }

.popup.center:before { left: 50%; }

.popup.search:after { left: 325px; }

.popup.search:before { left: 325px; }


THE HTML MARKUP

Hello I'm a Popup

THE JS CODE TO CALLL A POPUP $(".popupButton").popup({alignment:"left"});

michelreyes avatar Jul 06 '12 17:07 michelreyes

Sorry ivaynberg when a try to put html code it dosen't appear and when a try to put the code in: http://jsfiddle.net i can not access the reponse of my proxy is:

ERROR El URL solicitado no se ha podido conseguir

Se encontró el siguiente error al intentar recuperar la dirección URL: http://jsfiddle.net/

Acceso Denegado

La configuración de control de acceso evita que su solicitud sea permitida en este momento. Por favor, póngase en contacto con su proveedor de servicios si cree que esto es incorrecto.

Su administrador del caché es webmaster.

Sorry but this is just can i do , if you knoe other way i'll tray it.

michelreyes avatar Jul 06 '12 17:07 michelreyes

im guessing your code that closes the popup on click gets invoked...maybe select2 is not killing an event when it should

ivaynberg avatar Jul 06 '12 20:07 ivaynberg

So..and...?

michelreyes avatar Jul 09 '12 10:07 michelreyes

and i am not sure which event it is without being able to reproduce the problem...thus the jsfiddle request...

ivaynberg avatar Jul 09 '12 11:07 ivaynberg

Sorry again, but is imposible to me to access to jsfiddle, in my work i have a white list (it menas that only a bundle of pages i can visit, the other not) I hope my error will fixed in the future, anywhere i'll tray a way to upload my code, thanks a lot.

michelreyes avatar Jul 09 '12 12:07 michelreyes

you dont need to jsfiddle your exact code, just something that reproduces the error.

ivaynberg avatar Jul 09 '12 12:07 ivaynberg

well, i put in the previous post my: popup pluglin, the css code, the js that call the popup and the problem is when i tray tu put the html markup , it dosen't see in the post (maybe the github editor can show as is or i don't know use the editor).

michelreyes avatar Jul 09 '12 14:07 michelreyes

the problem is i cannot run your code without significant amount of work on my part. why dont you put your code into a zip file that has the html/js/css that i can run locally and paste a link where i can download it here. i need something to play with to figure this out, staring at the code is not enough...

ivaynberg avatar Jul 09 '12 14:07 ivaynberg

Hello again, here is the code: https://gist.github.com/3107709 https://gist.github.com/3107532 I hope you can test with this, thanks a lot!

michelreyes avatar Jul 13 '12 21:07 michelreyes