adding all weblabels from weblabels.fsf.org
[weblabels.fsf.org.git] / crm-dev.fsf.org / 20131203 / files / static.fsf.org / plone2012 / popupforms.js
1
2 /* - popupforms.js - */
3 /******
4 Set up standard Plone popups
5
6 Provides globals: common_content_filter
7
8 Extends jQuery.tools.overlay.conf to set up common Plone effects and
9 visuals.
10 ******/
11
12
13 var common_content_filter = '#content>*:not(div.configlet),dl.portalMessage.error,dl.portalMessage.info';
14
15 jQuery.extend(jQuery.tools.overlay.conf,
16 {
17 fixed:false,
18 speed:'fast',
19 mask:{color:'#fff',opacity: 0.4,loadSpeed:0,closeSpeed:0}
20 });
21
22
23 (function($) {
24
25 // static constructs
26 $.plonepopups = $.plonepopups || {};
27
28 $.extend($.plonepopups,
29 {
30 // method to show error message in a noform
31 // situation.
32 noformerrorshow: function noformerrorshow(el, noform) {
33 var o = $(el),
34 emsg = o.find('dl.portalMessage.error');
35 if (emsg.length) {
36 o.children().replaceWith(emsg);
37 return false;
38 } else {
39 return noform;
40 }
41 },
42 // After deletes we need to redirect to the target page.
43 redirectbasehref: function redirectbasehref(el, responseText) {
44 var mo = responseText.match(/<base href="(\S+?)"/i);
45 if (mo.length === 2) {
46 return mo[1];
47 }
48 return location;
49 }
50 })
51 })(jQuery);
52
53 jQuery(function($){
54
55 if (jQuery.browser.msie && parseInt(jQuery.browser.version, 10) < 7) {
56 // it's not realistic to think we can deal with all the bugs
57 // of IE 6 and lower. Fortunately, all this is just progressive
58 // enhancement.
59 return;
60 }
61
62 // login form
63 $('#portal-personaltools a[href$="/login"], #portal-personaltools a[href$="/login_form"], .discussion a[href$="/login"], .discussion a[href$="/login_form"]').prepOverlay(
64 {
65 subtype: 'ajax',
66 filter: common_content_filter,
67 formselector: 'form#login_form',
68 noform: function () {
69 if (location.href.search(/pwreset_finish$/) >= 0) {
70 return 'redirect';
71 } else {
72 return 'reload';
73 }
74 },
75 redirect: function () {
76 var href = location.href;
77 if (href.search(/pwreset_finish$/) >= 0) {
78 return href.slice(0, href.length-14) + 'logged_in';
79 } else {
80 return href;
81 }
82 }
83 }
84 );
85
86 // contact form
87 $('#siteaction-contact a').prepOverlay(
88 {
89 subtype: 'ajax',
90 filter: common_content_filter,
91 formselector: 'form[name="feedback_form"]',
92 noform: function(el) {return $.plonepopups.noformerrorshow(el, 'close');}
93 }
94 );
95
96 // comment form
97 $('form[name=reply]').prepOverlay(
98 {
99 subtype: 'ajax',
100 filter: common_content_filter,
101 formselector: 'form:has(input[name="discussion_reply:method"])',
102 noform: function(el) {return $.plonepopups.noformerrorshow(el, 'redirect');},
103 redirect: $.plonepopups.redirectbasehref
104 }
105 );
106
107
108 // display: select content item / change content item
109 $('#contextSetDefaultPage, #folderChangeDefaultPage').prepOverlay(
110 {
111 subtype: 'ajax',
112 filter: common_content_filter,
113 formselector: 'form[name="default_page_form"]',
114 noform: function(el) {return $.plonepopups.noformerrorshow(el, 'reload');},
115 closeselector: '[name=form.button.Cancel]',
116 width:'40%'
117 }
118 );
119
120 // advanced state
121 // This form needs additional JS and CSS for the calendar widget.
122 // The AJAX form doesn't load it from the javascript_head_slot.
123 // $('dl#plone-contentmenu-workflow a#advanced').prepOverlay(
124 // {
125 // subtype: 'ajax',
126 // filter: common_content_filter,
127 // formselector: 'form',
128 // noform: function(el) {return $.plonepopups.noformerrorshow(el, 'reload');},
129 // closeselector: '[name=form.button.Cancel]'
130 // }
131 // );
132
133 // Delete dialog
134 $('dl#plone-contentmenu-actions a#delete').prepOverlay(
135 {
136 subtype: 'ajax',
137 filter: common_content_filter,
138 formselector: '#delete_confirmation',
139 noform: function(el) {return $.plonepopups.noformerrorshow(el, 'redirect');},
140 redirect: $.plonepopups.redirectbasehref,
141 closeselector: '[name=form.button.Cancel]',
142 width:'50%'
143 }
144 );
145
146 // Rename dialog
147 $('dl#plone-contentmenu-actions a#rename').prepOverlay(
148 {
149 subtype: 'ajax',
150 filter: common_content_filter,
151 closeselector: '[name=form.button.Cancel]',
152 width:'40%'
153 }
154 );
155
156 // registration
157 $('#portal-personaltools a[href$="/@@register"]').prepOverlay(
158 {
159 subtype: 'ajax',
160 filter: common_content_filter,
161 formselector: 'form.kssattr-formname-register'
162 }
163 );
164
165 // add new user, group
166 $('form[name=users_add], form[name=groups_add]').prepOverlay(
167 {
168 subtype: 'ajax',
169 filter: common_content_filter,
170 formselector: 'form.kssattr-formname-new-user, form[name="groups"]',
171 noform: function(el) {return $.plonepopups.noformerrorshow(el, 'redirect');},
172 redirect: function () {return location.href;}
173 }
174 );
175
176 // Content history popup
177 $('#content-history a').prepOverlay({
178 subtype: 'ajax',
179 filter: 'h2, #content-history',
180 urlmatch: '@@historyview',
181 urlreplace: '@@contenthistorypopup'
182 });
183
184 });
185
186