(function($) {
	var ID_CLOSED = 5, ID_REJECTED = 6;
	if ($) {
		// redmine uses jQuery so use it.
		$(document).ready(function() {
			var s = $('#issue_status_id');
			if (s.length === 0) {
				return;
			}
			var options = s.get(0).childNodes;
			var needCloseButton = false;
			for (var i = options.length - 1; i >= 0; i--) {
				var option = options[i];
				var v = parseInt(option.value, 10);
				if (v === ID_REJECTED) {
					if (option.selected) {
						needCloseButton = false;
						break;
					}
				}
				if (v === ID_CLOSED) {
					if (option.selected) {
						needCloseButton = false;
						break;
					} else {
						needCloseButton = true;
					}
				}
			}
			if (!needCloseButton) {
				return;
			}
			var f = $('#issue-form');
			var areas = $('div#content>div.contextual:has(a.icon)');
			if (f.length === 0 || areas.length === 0) {
				return;
			}
			var done_ratio = $('#issue_done_ratio');
			var closer = function(e) {
				s.val(ID_CLOSED);
				done_ratio.val(100);
				f.submit();
			};
			var closeButtonTemplate = $('a.redmine-close-button');
			areas.each(function() {
				var closeButton = closeButtonTemplate
					.clone()
					.css('display', 'inline')
					.click(closer);

				var delButton = $(this).find('a.icon-del');
				if (delButton.length > 0) {
					closeButton.insertBefore(delButton);
				} else {
					$(this).append(closeButton);
				}
			});
		});
	} else {
		// redmine uses prototype so use it.
		document.observe('dom:loaded', function() {
			var s = $('issue_status_id');
			if (s === null) {
				return;
			}
			var options = s.childNodes;
			var needCloseButton = false;
			for (var i = options.length - 1; i >= 0; i--) {
				var option = options[i];
				var v = parseInt(option.value, 10);
				if (v === ID_REJECTED) {
					if (option.selected) {
						needCloseButton = false;
						break;
					}
				}
				if (v === ID_CLOSED) {
					if (option.selected) {
						needCloseButton = false;
						break;
					} else {
						needCloseButton = true;
					}
				}
			}
			if (!needCloseButton) {
				return;
			}
			var f = $('issue-form');
			var all_areas = $$('div#content>div.contextual');
			var areas = [];
			for (var ai = 0; ai < all_areas.length; ai++) {
				if (all_areas[ai].select('a.icon').length > 0) {
					areas.push(all_areas[ai]);
				}
			}
			all_areas = null;
			if (f === null || areas.length === 0) {
				return;
			}
			var done_ratio = $('issue_done_ratio');
			var closer = function(e) {
				s.value = ID_CLOSED;
				if (done_ratio) {
					done_ratio.value = 100;
				}
				f.submit();
			};
			var closeButtonTemplate = $$('a.redmine-close-button')[0];
			for (ai = 0; ai < areas.length; ai++) {
				var area = areas[ai];
				var closeButton = closeButtonTemplate.cloneNode(true);
				closeButton.style.display = 'inline';
				closeButton.observe('click', closer);
				var delButton = area.select('a.icon-del');
				if (delButton.length > 0) {
					delButton[0].insert({ before: closeButton });
				} else {
					area.appendChild(closeButton);
				}
			}
		});
	}
})(jQuery);


@@ -3,21 +3,20 @@
 unction(
-$
 ) %7B%0A
+
 %09var ID_
@@ -49,17 +49,22 @@
 6;%0A%09if (
-$
+jQuery
 ) %7B%0A%09%09//
@@ -97,17 +97,22 @@
 e it.%0A%09%09
-$
+jQuery
 (documen
@@ -125,32 +125,51 @@
 dy(function() %7B%0A
+%09%09%09var $ = jQuery;%0A
 %09%09%09var s = $('#i
@@ -3064,18 +3064,12 @@
 ;%0A%09%7D%0A%7D)(
-jQuery
 );%0A%0A

Fix $ redeclaration for Prototype.