From 78e215494d4a47bdb301f4244dc99e52801f2ee4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Fri, 11 Jul 2014 13:10:51 +0200 Subject: [PATCH] javascript to open rel="popup" links in popups (#5111) --- gadjo/static/js/gadjo.js | 43 +++++++++++++++++++++++++++++++++++++++++ gadjo/templates/gadjo/base.html | 1 + 2 files changed, 44 insertions(+) create mode 100644 gadjo/static/js/gadjo.js diff --git a/gadjo/static/js/gadjo.js b/gadjo/static/js/gadjo.js new file mode 100644 index 0000000..23e35d1 --- /dev/null +++ b/gadjo/static/js/gadjo.js @@ -0,0 +1,43 @@ +function displayPopup(event) +{ + var url = $(this).attr('href'); + $.ajax({ + url: url, + success: function(html) { + var form = $(html).find('#content form'); + var title = $(html).find('#appbar h2').text(); + var dialog = $(form).dialog({modal: true, title: title, width: 'auto'}); + var buttons = Array(); + if (! form.prop('action')) { + form.prop('action', url); + } + $(dialog).find('.buttons').hide(); + $(html).find('.buttons button, .buttons a').each(function(idx, elem) { + var button = Object(); + button.text = $(elem).text(); + if ($(elem).hasClass('cancel')) { + button.click = function() { $(this).dialog('destroy'); return false; }; + } else { + button.click = function() { (form).find('button').click(); return false; }; + } + if ($(elem).hasClass('submit-button')) { + button.class = 'submit-button'; + } else if ($(elem).hasClass('delete-button')) { + button.class = 'delete-button'; + } + buttons.push(button); + }); + buttons.reverse(); + $(dialog).dialog('option', 'buttons', buttons); + if ($(dialog).find('input:visible').length) { + $(dialog).find('input:visible')[0].focus(); + } + return false; + } + }); + return false; +} + +$(function() { + $('a[rel=popup]').click(displayPopup); +}); diff --git a/gadjo/templates/gadjo/base.html b/gadjo/templates/gadjo/base.html index 097eaaf..2f2b6d6 100644 --- a/gadjo/templates/gadjo/base.html +++ b/gadjo/templates/gadjo/base.html @@ -12,6 +12,7 @@ {% endblock %} + {% block extrascripts %} {% endblock %} -- 2.0.1