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