3 function show(id) { delClass( id, 'hidden' ) }
4 function hide(id) { addClass( id, 'hidden' ) }
6 function hideshow(id) { return toggleVisibility( id ) }
7 function toggleVisibility(id) {
8 var e = jQuery('#' + id);
10 if ( e.hasClass('hidden') ) {
11 e.removeClass('hidden');
20 function setVisibility(id, visibility) {
21 if ( visibility ) show(id);
25 function switchVisibility(id1, id2) {
26 // Show both and then hide the one we want
33 function toggle_upgrade_history(widget, selector) {
34 jQuery(selector).toggle();
35 jQuery(widget).toggleClass("rolled-up");
39 function jQueryWrap( id ) {
40 return typeof id == 'object' ? jQuery(id) : jQuery('#'+id);
43 function addClass(id, value) {
44 jQueryWrap(id).addClass(value);
47 function delClass(id, value) {
48 jQueryWrap(id).removeClass(value);
54 var e = jQueryWrap(id);
57 if (e.hasClass('hidden')) {
58 set_rollup_state(e,e2,'shown');
59 createCookie(id,1,365);
62 set_rollup_state(e,e2,'hidden');
63 createCookie(id,0,365);
68 function set_rollup_state(e,e2,state) {
70 if (state == 'shown') {
72 delClass( e2, 'rolled-up' );
74 else if (state == 'hidden') {
76 addClass( e2, 'rolled-up' );
83 function setCheckbox(input, name, val) {
84 if (val == null) val = input.checked;
86 // Find inputs within the current form or collection list, whichever is closest.
87 var container = jQuery(input).closest("form, table.collection-as-table").get(0);
88 var myfield = container.getElementsByTagName('input');
89 for ( var i = 0; i < myfield.length; i++ ) {
90 if ( myfield[i].type != 'checkbox' ) continue;
92 if ( name instanceof RegExp ) {
93 if ( ! myfield[i].name.match( name ) ) continue;
96 if ( myfield[i].name != name ) continue;
101 myfield[i].checked = val;
105 /* apply callback to nodes or elements */
107 function walkChildNodes(parent, callback)
109 if( !parent || !parent.childNodes ) return;
110 var list = parent.childNodes;
111 for( var i = 0; i < list.length; i++ ) {
116 function walkChildElements(parent, callback)
118 walkChildNodes( parent, function(node) {
119 if( node.nodeType != 1 ) return;
120 return callback( node );
124 /* shredder things */
126 function showShredderPluginTab( plugin )
128 var plugin_tab_id = 'shredder-plugin-'+ plugin +'-tab';
129 var root = jQuery('#shredder-plugin-tabs');
131 root.children(':not(.hidden)').addClass('hidden');
132 root.children('#' + plugin_tab_id).removeClass('hidden');
135 show('shredder-submit-button');
137 hide('shredder-submit-button');
141 function checkAllObjects()
143 var check = jQuery('#shredder-select-all-objects-checkbox').prop('checked');
144 var elements = jQuery('#shredder-search-form :checkbox[name=WipeoutObject]');
147 elements.prop('checked', true);
149 elements.prop('checked', false);
153 function checkboxToInput(target,checkbox,val){
154 var tar = jQuery('#' + escapeCssSelector(target));
155 var box = jQuery('#' + escapeCssSelector(checkbox));
156 if(box.prop('checked')){
161 tar.val( val+', '+ tar.val() );
165 tar.val(tar.val().replace(val+', ',''));
166 tar.val(tar.val().replace(val,''));
168 jQuery('#UpdateIgnoreAddressCheckboxes').val(true);
171 // ahah for back compatibility as plugins may still use it
172 function ahah( url, id ) {
173 jQuery('#'+id).load(url);
176 // only for back compatibility, please JQuery() instead
177 function doOnLoad( js ) {
183 dateFormat: 'yy-mm-dd',
184 constrainInput: false,
185 showButtonPanel: true,
188 showOtherMonths: true,
189 selectOtherMonths: true
191 jQuery(".datepicker:not(.withtime)").datepicker(opts);
192 jQuery(".datepicker.withtime").datetimepicker( jQuery.extend({}, opts, {
194 // We fake this by snapping below for the minute slider
199 timeFormat: 'HH:mm:ss'
200 }) ).each(function(index, el) {
201 var tp = jQuery.datepicker._get( jQuery.datepicker._getInst(el), 'timepicker');
204 // Hook after _injectTimePicker so we can modify the minute_slider
205 // right after it's first created
206 tp._base_injectTimePicker = tp._injectTimePicker;
207 tp._injectTimePicker = function() {
208 this._base_injectTimePicker.apply(this, arguments);
210 // Now that we have minute_slider, modify it to be stepped for mouse movements
211 var slider = jQuery.data(this.minute_slider[0], "ui-slider");
212 slider._base_normValueFromMouse = slider._normValueFromMouse;
213 slider._normValueFromMouse = function() {
214 var value = this._base_normValueFromMouse.apply(this, arguments);
215 var old_step = this.options.step;
216 this.options.step = 5;
217 var aligned = this._trimAlignValue( value );
218 this.options.step = old_step;
225 function textToHTML(value) {
226 return value.replace(/&/g, "&")
227 .replace(/</g, "<")
228 .replace(/>/g, ">")
229 .replace(/-- \n/g,"-- \n")
230 .replace(/\n/g, "\n<br />");
233 CKEDITOR_BASEPATH=RT.Config.WebPath + "/static/RichText/";
234 function ReplaceAllTextareas() {
235 var sAgent = navigator.userAgent.toLowerCase();
236 if (!CKEDITOR.env.isCompatible ||
237 sAgent.indexOf('iphone') != -1 ||
238 sAgent.indexOf('ipad') != -1 ||
239 sAgent.indexOf('android') != -1 )
242 // replace all content and signature message boxes
243 var allTextAreas = document.getElementsByTagName("textarea");
245 for (var i=0; i < allTextAreas.length; i++) {
246 var textArea = allTextAreas[i];
247 if (jQuery(textArea).hasClass("messagebox richtext")) {
248 // Turn the original plain text content into HTML
249 var type = jQuery("#"+textArea.name+"Type");
250 if (type.val() != "text/html")
251 textArea.value = textToHTML(textArea.value);
254 type.val("text/html");
256 CKEDITOR.replace(textArea.name,{ width: '100%', height: RT.Config.MessageBoxRichTextHeight });
258 jQuery("#" + textArea.name + "___Frame").addClass("richtext-editor");
263 function toggle_addprincipal_validity(input, good, title) {
265 jQuery(input).nextAll(".warning").hide();
266 jQuery("#acl-AddPrincipal input[type=checkbox]").removeAttr("disabled");
268 jQuery(input).nextAll(".warning").css("display", "block");
269 jQuery("#acl-AddPrincipal input[type=checkbox]").attr("disabled", "disabled");
273 title = jQuery(input).val();
275 update_addprincipal_title( title );
278 function update_addprincipal_title(title) {
279 var h3 = jQuery("#acl-AddPrincipal h3");
280 h3.text( h3.text().replace(/: .*$/,'') + ": " + title );
283 // when a value is selected from the autocompleter
284 function addprincipal_onselect(ev, ui) {
286 // if principal link exists, we shall go there instead
287 var principal_link = jQuery(ev.target).closest('form').find('ul.ui-tabs-nav a[href="#acl-' + ui.item.id + '"]:first');
288 if (principal_link.size()) {
289 jQuery(this).val('').blur();
290 update_addprincipal_title( '' ); // reset title to blank for #acl-AddPrincipal
291 principal_link.click();
295 // pass the item's value along as the title since the input's value
296 // isn't actually updated yet
297 toggle_addprincipal_validity(this, true, ui.item.value);
300 // when the input is actually changed, through typing or autocomplete
301 function addprincipal_onchange(ev, ui) {
302 // if we have a ui.item, then they selected from autocomplete and it's good
304 var input = jQuery(this);
305 // Check using the same autocomplete source if the value typed would
306 // have been autocompleted and is therefore valid
308 url: input.autocomplete("option", "source"),
314 success: function(data) {
316 toggle_addprincipal_validity(input, data.length ? true : false );
318 toggle_addprincipal_validity(input, true);
322 toggle_addprincipal_validity(this, true);
327 function escapeCssSelector(str) {
328 return str.replace(/([^A-Za-z0-9_-])/g,'\\$1');
333 jQuery(".user-accordion").each(function(){
334 jQuery(this).accordion({
335 active: (jQuery(this).find("h3").length == 1 ? 0 : false),
337 heightStyle: "content",
339 }).find("h3 a.user-summary").click(function(ev){
340 ev.stopPropagation();
344 ReplaceAllTextareas();