Created
April 27, 2012 15:56
-
-
Save linssen/2510363 to your computer and use it in GitHub Desktop.
Chosen in Django admin JavaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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