comparison rhodecode/public/js/rhodecode.js @ 1421:c6b811f11c94 beta

Javascripts rewrite: updated yui to latest 2.9, simplified ajax loading for multiple pages. Removed YUI dev package
author Marcin Kuzminski <marcin@python-works.com>
date Sat, 09 Jul 2011 20:07:59 +0200
parents
children 91708b96e991
comparison
equal deleted inserted replaced
1420:a2fe0ac8d007 1421:c6b811f11c94
1 /**
2 RhodeCode JS Files
3 **/
4
5 if (typeof console == "undefined" || typeof console.log == "undefined"){
6 console = { log: function() {} }
7 }
8
9
10 function str_repeat(i, m) {
11 for (var o = []; m > 0; o[--m] = i);
12 return o.join('');
13 }
14
15 /**
16 * INJECT .format function into String
17 * Usage: "My name is {0} {1}".format("Johny","Bravo")
18 * Return "My name is Johny Bravo"
19 * Inspired by https://gist.github.com/1049426
20 */
21 String.prototype.format = function() {
22
23 function format() {
24 var str = this;
25 var len = arguments.length+1;
26 var safe = undefined;
27 var arg = undefined;
28
29 // For each {0} {1} {n...} replace with the argument in that position. If
30 // the argument is an object or an array it will be stringified to JSON.
31 for (var i=0; i < len; arg = arguments[i++]) {
32 safe = typeof arg === 'object' ? JSON.stringify(arg) : arg;
33 str = str.replace(RegExp('\\{'+(i-1)+'\\}', 'g'), safe);
34 }
35 return str;
36 }
37
38 // Save a reference of what may already exist under the property native.
39 // Allows for doing something like: if("".format.native) { /* use native */ }
40 format.native = String.prototype.format;
41
42 // Replace the prototype property
43 return format;
44
45 }();
46
47 /**
48 * GLOBAL YUI Shortcuts
49 */
50 var YUC = YAHOO.util.Connect;
51 var YUD = YAHOO.util.Dom;
52 var YUE = YAHOO.util.Event;
53 var YUQ = YAHOO.util.Selector.query;
54
55 // defines if push state is enabled for this browser ?
56 var push_state_enabled = Boolean(
57 window.history && window.history.pushState && window.history.replaceState
58 && !( /* disable for versions of iOS before version 4.3 (8F190) */
59 (/ Mobile\/([1-7][a-z]|(8([abcde]|f(1[0-8]))))/i).test(navigator.userAgent)
60 /* disable for the mercury iOS browser, or at least older versions of the webkit engine */
61 || (/AppleWebKit\/5([0-2]|3[0-2])/i).test(navigator.userAgent)
62 )
63 )
64
65 /**
66 * Partial Ajax Implementation
67 *
68 * @param url: defines url to make partial request
69 * @param container: defines id of container to input partial result
70 * @param s_call: success callback function that takes o as arg
71 * o.tId
72 * o.status
73 * o.statusText
74 * o.getResponseHeader[ ]
75 * o.getAllResponseHeaders
76 * o.responseText
77 * o.responseXML
78 * o.argument
79 * @param f_call: failure callback
80 * @param args arguments
81 */
82 function ypjax(url,container,s_call,f_call,args){
83 var method='GET';
84 if(args===undefined){
85 args=null;
86 }
87
88 // Set special header for partial ajax == HTTP_X_PARTIAL_XHR
89 YUC.initHeader('X-PARTIAL-XHR',true);
90
91 // wrapper of passed callback
92 var s_wrapper = (function(o){
93 return function(o){
94 YUD.get(container).innerHTML=o.responseText;
95 YUD.setStyle(container,'opacity','1.0');
96 //execute the given original callback
97 if (s_call !== undefined){
98 s_call(o);
99 }
100 }
101 })()
102 YUD.setStyle(container,'opacity','0.3');
103 YUC.asyncRequest(method,url,{
104 success:s_wrapper,
105 failure:function(o){
106 //failure
107 window.location = url;
108 }
109 },args);
110
111 }
112
113 /**
114 * tooltip activate
115 */
116 function tooltip_activate(){
117 function toolTipsId(){
118 var ids = [];
119 var tts = YUQ('.tooltip');
120 for (var i = 0; i < tts.length; i++) {
121 // if element doesn't not have and id
122 // autogenerate one for tooltip
123 if (!tts[i].id){
124 tts[i].id='tt'+((i*100)+tts.length);
125 }
126 ids.push(tts[i].id);
127 }
128 return ids
129 };
130 var myToolTips = new YAHOO.widget.Tooltip("tooltip", {
131 context: [[toolTipsId()],"tl","bl",null,[0,5]],
132 monitorresize:false,
133 xyoffset :[0,0],
134 autodismissdelay:300000,
135 hidedelay:5,
136 showdelay:20,
137 });
138 }