Skip to content

Instantly share code, notes, and snippets.

@linssen
Created April 27, 2012 15:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save linssen/2510363 to your computer and use it in GitHub Desktop.
Save linssen/2510363 to your computer and use it in GitHub Desktop.
Chosen in Django admin JavaScript
var $chosens = {};
/**
* Hijacking the pop up script and overwriting it
*/
function showAddAnotherPopup(triggeringLink) {
var name = triggeringLink.id.replace(/^add_/, '');
name = id_to_windowname(name);
href = triggeringLink.href
if (href.indexOf('?') == -1) {
href += '?_popup=1';
} else {
href += '&_popup=1';
}
var win = window.open(href, name, 'height=500,width=800,resizable=yes,scrollbars=yes');
win.focus();
/**
* Also adding an interval to listen for when the window is closed
* then we can fire an update on the chosen objects
*/
var unloadInterval = setInterval(function() {
if (!win || win.closed) {
clearInterval(unloadInterval);
$chosens.trigger('liszt:updated');
}
}, 250);
return false;
}
$(document).ready(function() {
$chosens = $("select[multiple='multiple']");
var $add_another = $('a.add-another');
if ($chosens.length < 1) return false
$chosens
.width('50%')
.chosen();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment