MTrackWeb/templates/images/js/mtrack.js
[web.mtrack] / MTrackWeb / templates / images / js / mtrack.js
1 //<Script type="text/javascript">
2
3 /**
4  * The way JQuery is used, we need to continually re-apply the css handlers whenever a new segment is loaded.
5  * 
6  * to solve this, we will use a simple mtrack.registry - all code get's added to it, 
7  * then whenever html is loaded via AJAX, we can run run through the handlers and add them.
8  * 
9  */
10  
11  
12 MTrack = {
13     
14     registry : [],
15     /**
16      * usage:
17      * MTrack.register('a.changeset-link', 'click', function() ....)
18      * 
19      */
20     register : function( selector, event, handler) 
21     {
22         MTrack.registry.push( {
23             selector : selector,
24             event : event,
25             handler : handler
26         });
27     },
28     
29     addHandlers : function (toWhat) 
30     {
31         // forEach? - no IE support?
32         toWhat = toWhat || document.body; // 
33         // run the main registry
34         MTrack.registry.forEach(function(cfg) {
35             
36             $(toWhat).find(cfg.selector)[cfg.event](cfg.handler);
37         });
38         // any other weird crap goes here.
39         
40         if ($.browser.mozilla) {
41             $(toWhat).find("form").attr("autocomplete", "off");
42         }
43         // time ago 
44         jQuery.timeago.settings.allowFuture = true;
45         $(toWhat).find('abbr.timeinterval').timeago();
46         
47         // multipe select addon
48         $(toWhat).find("select[multiple]").asmSelect({
49             addItemTarget: 'bottom',
50             animate: false,
51             highlight: false,
52             removeLabel: '[x]',
53             sortable: false
54         });
55       
56     },
57     
58     keepLoggedIn()
59     {
60         
61         
62     }
63     
64 }
65
66 $(document).ready(function() {
67     MTrack.addHandlers(); // adds to main body..
68     // change project.
69     $('#banner select').change( function(e) {
70         // ajax change project, and refresh body..
71         jQuery.ajax({
72             url : baseURL + '/Project.html',
73             data : { active_project_id : this.value },
74             success : function() {
75                 // what if it's false..currentURL = false;
76                 MTrack.ajaxLoad(MTrack.currentURL, true);
77                 
78             }
79             
80         })
81          
82     });
83         
84         
85 });
86
87 // any date picers.. - on milestones?
88 MTrack.register('.dateinput', 'datepicker', {
89     // minDate: 0,
90     dateFormat: 'yy-mm-dd' // nice and compatible..
91 });
92
93
94 //// ------------------- OLD STUFF NEEDS TIDY UP ----------------------
95
96
97
98
99 $(document).ready(function() {
100     
101      
102     
103   
104   $("textarea.wiki").markItUp({
105     nameSpace:          "wiki",
106     previewParserPath:  baseURL + "/Preview",
107     root: rootURL + "/js",
108     onShiftEnter:       {keepDefault:false, replaceWith:'\\n\\n'},
109     markupSet:  [
110       {
111         name:'Heading 1', key:'1',
112         openWith:'== ', closeWith:' ==', placeHolder:'Your title here...'
113       },
114       {
115         name:'Heading 2', key:'2',
116         openWith:'=== ', closeWith:' ===', placeHolder:'Your title here...'
117       },
118       {
119         name:'Heading 3', key:'3',
120         openWith:'==== ', closeWith:' ====', placeHolder:'Your title here...'
121       },
122       {
123         name:'Heading 4', key:'4',
124         openWith:'===== ', closeWith:' =====', placeHolder:'Your title here...'
125       },
126       {
127         name:'Heading 5', key:'5',
128         openWith:'====== ', closeWith:' ======',
129         placeHolder:'Your title here...'
130       },
131       {separator:'---------------' },
132       {name:'Bold', key:'B', openWith:"'''", closeWith:"'''"},
133       {name:'Italic', key:'I', openWith:"''", closeWith:"''"},
134       {name:'Stroke through', key:'S', openWith:'~~', closeWith:'~~'},
135       {separator:'---------------' },
136       {name:'Bulleted list', openWith:' * '},
137       {name:'Numeric list', openWith:' 1. '},
138       {separator:'---------------' },
139       {name:'Quotes', openWith:'(!(> |!|>)!)'},
140       {name:'Code', openWith:'{{{\\n', closeWith:'\\n}}}'},
141       {separator:'---------------' },
142       {name:'Preview', call:'preview', className:'preview'}
143     ]
144   });
145
146   $.tablesorter.addParser({
147     id: 'ticket',
148     is: function(s) {
149       return /^#\d+/.test(s);
150     },
151     format: function(s) {
152       return $.tablesorter.formatFloat(s.replace(new RegExp(/#/g), ''));
153     },
154     type: 'numeric'
155   });
156  
157   $.tablesorter.addParser({
158     id: 'mtrackdate',
159     is: function(s) {
160       // don't auto-detect
161       return false;
162     },
163     format: function(s) {
164       // relies on the textExtraction routine below to pull a
165       // date/time string out of the title portion of the abbr tag
166       return $.tablesorter.formatFloat(new Date(s).getTime());
167     },
168     type: 'numeric'
169   });
170   
171   
172   
173   $("table.report, table.wiki").tablesorter({
174     textExtraction: function(node) {
175       var kid = node.childNodes[0];
176       if (kid && kid.tagName == 'ABBR') {
177         // assuming that this abbr is of class='timeinterval'
178         return kid.title;
179       }
180       // default 'simple' behavior
181       if (kid && kid.hasChildNodes()) {
182         return kid.innerHTML;
183       }
184       return node.innerHTML;
185     }
186   });
187   
188   
189   $('input.search[type=text]').each(function () {
190     if ($.browser.webkit) {
191       this.type = 'search';
192       ///$(this).attr('autosave', ABSWEB+'/');
193       $(this).attr('results', 5);
194     } else {
195       $(this).addClass('roundsearch');
196     }
197   });
198   // Convert links that are styled after buttons into actual buttons
199   $('a.button[href]').each(function () {
200     var href = $(this).attr('href');
201     var but = $('<button type="button"/>');
202     but.text($(this).text());
203     $(this).replaceWith(but);
204     but.click(function () {
205       document.location.href = href;
206       return false;
207     });
208   });
209
210   $.fn.mtrackWatermark = function () {
211     this.each(function () {
212       var ph = $(this).attr('title');
213       if ($.browser.webkit) {
214         // Use native safari placeholder for watermark
215         $(this).attr('placeholder', ph);
216       } else {
217         // http://plugins.jquery.com/files/jquery.tinywatermark-2.0.0.js.txt
218         var w;
219         var me = $(this);
220         me.focus(function () {
221           if (w) {
222             w = 0;
223             me.removeClass('watermark').data('w', 0).val('');
224           }
225         })
226         .blur(function () {
227           if (!me.val()) {
228             w = 1;
229             me.addClass('watermark').data('w', 1).val(ph);
230           }
231         })
232         .closest('form').submit(function () {
233           if (w) {
234             me.val('');
235           }
236         });
237         me.blur();
238       }
239     });
240   };
241   // Watermarking -??? what??
242   $('input[title!=""]').mtrackWatermark();
243  
244
245   // Arrange for the footer to sink to the bottom of the window, if the window
246   // contents are not very tall
247   var last_dh = 0;
248   var last_wh = 0;
249   function mtrack_footer_position(force) {
250     var ele = $('#footer');
251     if (!force &&
252         (last_dh != $(document).height() || last_wh != $(window).height)) {
253       force = true;
254     }
255     if (force) {
256       // Force a from-scratch layout assessment; put the footer back in
257       // it's natural location in the doc
258       ele.css({
259         position: "relative",
260         "margin-top": "3em",
261         top: 0
262       });
263     }
264     if ($(document).height() <= $(window).height()) {
265       ele.css({
266         position: "absolute",
267         "margin-top": "0",
268         top: (
269             $(window).scrollTop() +
270             $(window).height() -
271             ele.height() - 1
272           )+"px"
273       });
274     } else {
275       ele.css({
276         position: "relative",
277         "margin-top": "3em"
278       });
279     }
280     last_dh = $(document).height();
281     last_wh = $(window).height();
282   }
283   window.mtrack_footer_position = mtrack_footer_position;
284   $(window)
285     .scroll(mtrack_footer_position)
286     .resize(mtrack_footer_position);
287   function mtrack_footer_set_and_wait() {
288     mtrack_footer_position();
289     setTimeout(function () {
290       mtrack_footer_set_and_wait();
291     }, 1500);
292   }
293   mtrack_footer_set_and_wait();
294 });
295  
296
297 // from file.php
298
299
300 // from head -- probably for reports only..
301
302  
303 $(document).ready(function() {
304          
305       $.tablesorter.addParser({
306         id: 'priority',
307         is: function(s) {
308           // don't auto-detect
309           return false;
310         },
311         format: function(s) {
312             if (typeof(priorities[s]) != 'undefined') {
313                 return priorities[s];
314             }
315             return s;
316         },
317         type: 'numeric'
318       });
319       
320       $.tablesorter.addParser({
321         id: 'severity',
322         is: function(s) {
323           // don't auto-detect
324           return false;
325         },
326         format: function(s) {
327             if (typeof(severities[s]) != 'undefined') {
328                 return severities[s];
329             }
330             return s;
331         },
332         type: 'numeric'
333     });
334 });
335
336 // from wiki..
337
338 $(document).ready(function(){
339   $('ul.wikitree').treeview({
340     collapsed: true,
341     persist: "location"
342   });
343 });
344