if (typeof Prototype == 'undefined') { warning = "ActiveScaffold Error: Prototype could not be found. Please make sure that your application's layout includes prototype.js (e.g. <%= javascript_include_tag :defaults %>) *before* it includes active_scaffold.js (e.g. <%= active_scaffold_includes %>)."; alert(warning); } if (Prototype.Version.substring(0, 8) == '1.5.0_rc') { warning = "ActiveScaffold Error: Prototype 1.5.0_rc is not supported. Please update prototype.js (rake rails:update:javascripts)."; alert(warning); } /* * Simple utility methods */ var ActiveScaffold = { stripe: function(tableBody) { var even = false; var tableBody = $(tableBody); var tableRows = tableBody.down("tr"); var length = tableBody.rows.length; for (var i = 0; i < length; i++) { var tableRow = tableBody.rows[i]; //Make sure to skip rows that are create or edit rows or messages if (!tableRow.hasClassName("create") && !tableRow.hasClassName("update") && !tableRow.hasClassName("inline-adapter") && !tableRow.hasClassName("active-scaffold-calculations")) { if (even) { tableRow.addClassName("even-record"); } else { tableRow.removeClassName("even-record"); } even = !even; } } }, toggleEmptyMessage: function(tableBody, emptyMessageElement) { // Check to see if this was the last element in the list if ($(tableBody).rows.length == 0) { $(emptyMessageElement).show(); } else { $(emptyMessageElement).hide(); } }, removeSortClasses: function(scaffold_id) { $$('#' + scaffold_id + ' td.sorted').each(function(element) { element.removeClassName("sorted"); }); $$('#' + scaffold_id + ' th.sorted').each(function(element) { element.removeClassName("sorted"); element.removeClassName("asc"); element.removeClassName("desc"); }); }, decrement_record_count: function(scaffold_id) { count = $$('#' + scaffold_id + ' span.active-scaffold-records').first(); count.innerHTML = parseInt(count.innerHTML) - 1; }, increment_record_count: function(scaffold_id) { count = $$('#' + scaffold_id + ' span.active-scaffold-records').first(); count.innerHTML = parseInt(count.innerHTML) + 1; }, server_error_response: '', report_500_response: function(active_scaffold_id) { messages_container = $(active_scaffold_id).down('td.messages-container'); new Insertion.Top(messages_container, this.server_error_response); } } /* * Add-ons/Patches to Prototype */ /* patch to support replacing TR/TD/TBODY in Internet Explorer, courtesy of http://dev.rubyonrails.org/ticket/4273 */ Element.replace = function(element, html) { element = $(element); if (element.outerHTML) { try { element.outerHTML = html.stripScripts(); } catch (e) { var tn = element.tagName; if(tn=='TBODY' || tn=='TR' || tn=='TD') { var tempDiv = document.createElement("div"); tempDiv.innerHTML = '
'; element.parentNode.replaceChild(tempDiv.getElementsByTagName(tn).item(0), element); } else throw e; } } else { var range = element.ownerDocument.createRange(); /* patch to fix