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