1 <?php # vim:ts=2:sw=2:et:
2 /* For licensing and copyright terms, see the file named LICENSE */
3 include '../inc/common.php';
7 header('Content-Type: text/javascript');
8 header("Cache-Control: public, max-age=$age, pre-check=$age");
9 header('Expires: ' . date(DATE_COOKIE, time() + $age));
13 'jquery-1.4.2.min.js',
14 'jquery-ui-1.8.2.custom.min.js',
15 'jquery.asmselect.js',
16 'jquery.flot.pack.js',
17 'jquery.MultiFile.pack.js',
20 'jquery.tablesorter.js',
27 echo "var ABSWEB = '$ABSWEB';\n";
29 foreach ($scripts as $name) {
37 foreach (MTrackDB::q('select priorityname, value from priorities')
38 ->fetchAll() as $row) {
39 $PRI_SWITCH .= "case '$row[0]': return $row[1];\n";
42 foreach (MTrackDB::q('select sevname, ordinal from severities')
43 ->fetchAll() as $row) {
44 $SEV_SWITCH .= "case '$row[0]': return $row[1];\n";
48 $(document).ready(function() {
49 jQuery.timeago.settings.allowFuture = true;
50 $('abbr.timeinterval').timeago();
51 $("select[multiple]").asmSelect({
52 addItemTarget: 'bottom',
58 if ($.browser.mozilla) {
59 // http://www.ryancramer.com/journal/entries/radio_buttons_firefox/
60 $("form").attr("autocomplete", "off");
62 $("textarea.wiki").markItUp({
64 previewParserPath: "{$ABSWEB}markitup-preview.php",
66 onShiftEnter: {keepDefault:false, replaceWith:'\\n\\n'},
69 name:'Heading 1', key:'1',
70 openWith:'== ', closeWith:' ==', placeHolder:'Your title here...'
73 name:'Heading 2', key:'2',
74 openWith:'=== ', closeWith:' ===', placeHolder:'Your title here...'
77 name:'Heading 3', key:'3',
78 openWith:'==== ', closeWith:' ====', placeHolder:'Your title here...'
81 name:'Heading 4', key:'4',
82 openWith:'===== ', closeWith:' =====', placeHolder:'Your title here...'
85 name:'Heading 5', key:'5',
86 openWith:'====== ', closeWith:' ======',
87 placeHolder:'Your title here...'
89 {separator:'---------------' },
90 {name:'Bold', key:'B', openWith:"'''", closeWith:"'''"},
91 {name:'Italic', key:'I', openWith:"''", closeWith:"''"},
92 {name:'Stroke through', key:'S', openWith:'~~', closeWith:'~~'},
93 {separator:'---------------' },
94 {name:'Bulleted list', openWith:' * '},
95 {name:'Numeric list', openWith:' 1. '},
96 {separator:'---------------' },
97 {name:'Quotes', openWith:'(!(> |!|>)!)'},
98 {name:'Code', openWith:'{{{\\n', closeWith:'\\n}}}'},
99 {separator:'---------------' },
100 {name:'Preview', call:'preview', className:'preview'}
104 $.tablesorter.addParser({
107 return /^#\d+/.test(s);
109 format: function(s) {
110 return $.tablesorter.formatFloat(s.replace(new RegExp(/#/g), ''));
114 $.tablesorter.addParser({
120 format: function(s) {
128 $.tablesorter.addParser({
134 format: function(s) {
142 $.tablesorter.addParser({
148 format: function(s) {
149 // relies on the textExtraction routine below to pull a
150 // date/time string out of the title portion of the abbr tag
151 return $.tablesorter.formatFloat(new Date(s).getTime());
155 $("table.report, table.wiki").tablesorter({
156 textExtraction: function(node) {
157 var kid = node.childNodes[0];
158 if (kid && kid.tagName == 'ABBR') {
159 // assuming that this abbr is of class='timeinterval'
162 // default 'simple' behavior
163 if (kid && kid.hasChildNodes()) {
164 return kid.innerHTML;
166 return node.innerHTML;
169 $('input.search[type=text]').each(function () {
170 if ($.browser.webkit) {
171 this.type = 'search';
172 $(this).attr('autosave', ABSWEB);
173 $(this).attr('results', 5);
175 $(this).addClass('roundsearch');
178 // Convert links that are styled after buttons into actual buttons
179 $('a.button[href]').each(function () {
180 var href = $(this).attr('href');
181 var but = $('<button type="button"/>');
182 but.text($(this).text());
183 $(this).replaceWith(but);
184 but.click(function () {
185 document.location.href = href;
190 $.fn.mtrackWatermark = function () {
191 this.each(function () {
192 var ph = $(this).attr('title');
193 if ($.browser.webkit) {
194 // Use native safari placeholder for watermark
195 $(this).attr('placeholder', ph);
197 // http://plugins.jquery.com/files/jquery.tinywatermark-2.0.0.js.txt
200 me.focus(function () {
203 me.removeClass('watermark').data('w', 0).val('');
209 me.addClass('watermark').data('w', 1).val(ph);
212 .closest('form').submit(function () {
222 $('input[title!=""]').mtrackWatermark();
224 // Toggle line number display in diff visualizations, to make it easier
225 // to copy the diff contents
226 var diff_visible = true;
227 $('.togglediffcopy').click(function () {
228 diff_visible = !diff_visible;
230 $('table.code.diff tr td.lineno').show();
231 $('table.code.diff tr td.linelink').show();
233 $('table.code.diff tr td.lineno').hide();
234 $('table.code.diff tr td.linelink').hide();
238 // Syntax highlighting
239 var hl_color_scheme = 'wezterm';
240 function applyhl(name) {
241 if (hl_color_scheme != '') {
242 $('.source-code').removeClass(hl_color_scheme);
245 $('.source-code').addClass(name);
247 hl_color_scheme = name;
249 $('.select-hl-scheme').change(function () {
250 applyhl($(this).val());
251 var val = $(this).val();
252 $('.select-hl-scheme').each(function () {
257 // Arrange for the footer to sink to the bottom of the window, if the window
258 // contents are not very tall
261 function mtrack_footer_position(force) {
262 var ele = $('#footer');
264 (last_dh != $(document).height() || last_wh != $(window).height)) {
268 // Force a from-scratch layout assessment; put the footer back in
269 // it's natural location in the doc
271 position: "relative",
276 if ($(document).height() <= $(window).height()) {
278 position: "absolute",
281 $(window).scrollTop() +
288 position: "relative",
292 last_dh = $(document).height();
293 last_wh = $(window).height();
295 window.mtrack_footer_position = mtrack_footer_position;
297 .scroll(mtrack_footer_position)
298 .resize(mtrack_footer_position);
299 function mtrack_footer_set_and_wait() {
300 mtrack_footer_position();
301 setTimeout(function () {
302 mtrack_footer_set_and_wait();
305 mtrack_footer_set_and_wait();