@@ -35,848 +35,847 @@ String.prototype.format = function() {
return str;
}
// Save a reference of what may already exist under the property native.
// Allows for doing something like: if("".format.native) { /* use native */ }
format.native = String.prototype.format;
// Replace the prototype property
return format;
}();
String.prototype.strip = function(char) {
if(char === undefined){
char = '\\s';
return this.replace(new RegExp('^'+char+'+|'+char+'+$','g'), '');
String.prototype.lstrip = function(char) {
return this.replace(new RegExp('^'+char+'+'),'');
String.prototype.rstrip = function(char) {
return this.replace(new RegExp(''+char+'+$'),'');
if(!Array.prototype.indexOf) {
Array.prototype.indexOf = function(needle) {
for(var i = 0; i < this.length; i++) {
if(this[i] === needle) {
return i;
return -1;
};
// IE(CRAP) doesn't support previousElementSibling
var prevElementSibling = function( el ) {
if( el.previousElementSibling ) {
return el.previousElementSibling;
} else {
while( el = el.previousSibling ) {
if( el.nodeType === 1 ) return el;
var setSelectValue = function(select, val){
var selection = YUD.get(select);
// select element
for(var i=0;i<selection.options.length;i++){
if (selection.options[i].innerHTML == val) {
selection.selectedIndex = i;
break;
/**
* SmartColorGenerator
*
*usage::
* var CG = new ColorGenerator();
* var col = CG.getColor(key); //returns array of RGB
* 'rgb({0})'.format(col.join(',')
* @returns {ColorGenerator}
*/
var ColorGenerator = function(){
this.GOLDEN_RATIO = 0.618033988749895;
this.CURRENT_RATIO = 0.22717784590367374 // this can be random
this.HSV_1 = 0.75;//saturation
this.HSV_2 = 0.95;
this.color;
this.cacheColorMap = {};
ColorGenerator.prototype = {
getColor:function(key){
if(this.cacheColorMap[key] !== undefined){
return this.cacheColorMap[key];
else{
this.cacheColorMap[key] = this.generateColor();
},
_hsvToRgb:function(h,s,v){
if (s == 0.0)
return [v, v, v];
i = parseInt(h * 6.0)
f = (h * 6.0) - i
p = v * (1.0 - s)
q = v * (1.0 - s * f)
t = v * (1.0 - s * (1.0 - f))
i = i % 6
if (i == 0)
return [v, t, p]
if (i == 1)
return [q, v, p]
if (i == 2)
return [p, v, t]
if (i == 3)
return [p, q, v]
if (i == 4)
return [t, p, v]
if (i == 5)
return [v, p, q]
generateColor:function(){
this.CURRENT_RATIO = this.CURRENT_RATIO+this.GOLDEN_RATIO;
this.CURRENT_RATIO = this.CURRENT_RATIO %= 1;
HSV_tuple = [this.CURRENT_RATIO, this.HSV_1, this.HSV_2]
RGB_tuple = this._hsvToRgb(HSV_tuple[0],HSV_tuple[1],HSV_tuple[2]);
function toRgb(v){
return ""+parseInt(v*256)
return [toRgb(RGB_tuple[0]),toRgb(RGB_tuple[1]),toRgb(RGB_tuple[2])];
* GLOBAL YUI Shortcuts
var YUC = YAHOO.util.Connect;
var YUD = YAHOO.util.Dom;
var YUE = YAHOO.util.Event;
var YUQ = YAHOO.util.Selector.query;
// defines if push state is enabled for this browser ?
var push_state_enabled = Boolean(
window.history && window.history.pushState && window.history.replaceState
&& !( /* disable for versions of iOS before version 4.3 (8F190) */
(/ Mobile\/([1-7][a-z]|(8([abcde]|f(1[0-8]))))/i).test(navigator.userAgent)
/* disable for the mercury iOS browser, or at least older versions of the webkit engine */
|| (/AppleWebKit\/5([0-2]|3[0-2])/i).test(navigator.userAgent)
)
);
var _run_callbacks = function(callbacks){
if (callbacks !== undefined){
var _l = callbacks.length;
for (var i=0;i<_l;i++){
var func = callbacks[i];
if(typeof(func)=='function'){
try{
func();
}catch (err){};
* Partial Ajax Implementation
* @param url: defines url to make partial request
* @param container: defines id of container to input partial result
* @param s_call: success callback function that takes o as arg
* o.tId
* o.status
* o.statusText
* o.getResponseHeader[ ]
* o.getAllResponseHeaders
* o.responseText
* o.responseXML
* o.argument
* @param f_call: failure callback
* @param args arguments
function ypjax(url,container,s_call,f_call,args){
var method='GET';
if(args===undefined){
args=null;
// Set special header for partial ajax == HTTP_X_PARTIAL_XHR
YUC.initHeader('X-PARTIAL-XHR',true);
// wrapper of passed callback
var s_wrapper = (function(o){
return function(o){
YUD.get(container).innerHTML=o.responseText;
YUD.setStyle(container,'opacity','1.0');
//execute the given original callback
if (s_call !== undefined){
s_call(o);
})()
YUD.setStyle(container,'opacity','0.3');
YUC.asyncRequest(method,url,{
success:s_wrapper,
failure:function(o){
console.log(o);
YUD.get(container).innerHTML='<span class="error_red">ERROR: {0}</span>'.format(o.status);
cache:false
},args);
var ajaxGET = function(url,success) {
// Set special header for ajax == HTTP_X_PARTIAL_XHR
var sUrl = url;
var callback = {
success: success,
failure: function (o) {
alert("error");
var request = YAHOO.util.Connect.asyncRequest('GET', sUrl, callback);
return request;
var ajaxPOST = function(url,postData,success) {
var toQueryString = function(o) {
if(typeof o !== 'object') {
return false;
var _p, _qs = [];
for(_p in o) {
_qs.push(encodeURIComponent(_p) + '=' + encodeURIComponent(o[_p]));
return _qs.join('&');
var postData = toQueryString(postData);
var request = YAHOO.util.Connect.asyncRequest('POST', sUrl, callback, postData);
* tooltip activate
var tooltip_activate = function(){
yt = YAHOO.yuitip.main;
YUE.onDOMReady(yt.init);
* show more
var show_more_event = function(){
YUE.on(YUD.getElementsByClassName('show_more'),'click',function(e){
var el = e.target;
YUD.setStyle(YUD.get(el.id.substring(1)),'display','');
YUD.setStyle(el.parentNode,'display','none');
});
* show changeset tooltip
var show_changeset_tooltip = function(){
YUE.on(YUD.getElementsByClassName('lazy-cs'), 'mouseover', function(e){
var target = e.currentTarget;
var rid = YUD.getAttribute(target,'raw_id');
var repo_name = YUD.getAttribute(target,'repo_name');
var ttid = 'tt-'+rid;
var success = function(o){
var json = JSON.parse(o.responseText);
YUD.addClass(target,'tooltip')
YUD.setAttribute(target, 'title',json['message']);
YAHOO.yuitip.main.show_yuitip(e, target);
if(rid && !YUD.hasClass(target, 'tooltip')){
YUD.setAttribute(target,'id',ttid);
YUD.setAttribute(target, 'title',_TM['loading...']);
YAHOO.yuitip.main.set_listeners(target);
ajaxGET('/changeset_info/{0}/{1}'.format(repo_name,rid), success)
var onSuccessFollow = function(target){
var f = YUD.get(target.id);
var f_cnt = YUD.get('current_followers_count');
if(YUD.hasClass(f, 'follow')){
f.setAttribute('class','following');
f.setAttribute('title',_TM['Stop following this repository']);
if(f_cnt){
var cnt = Number(f_cnt.innerHTML)+1;
f_cnt.innerHTML = cnt;
f.setAttribute('class','follow');
f.setAttribute('title',_TM['Start following this repository']);
var cnt = Number(f_cnt.innerHTML)-1;
var toggleFollowingUser = function(target,fallows_user_id,token,user_id){
args = 'follows_user_id='+fallows_user_id;
args+= '&auth_token='+token;
if(user_id != undefined){
args+="&user_id="+user_id;
YUC.asyncRequest('POST',TOGGLE_FOLLOW_URL,{
success:function(o){
onSuccessFollow(target);
var toggleFollowingRepo = function(target,fallows_repo_id,token,user_id){
args = 'follows_repo_id='+fallows_repo_id;
* TOOLTIP IMPL.
YAHOO.namespace('yuitip');
YAHOO.yuitip.main = {
$: YAHOO.util.Dom.get,
bgColor: '#000',
speed: 0.3,
opacity: 0.9,
offset: [15,15],
useAnim: false,
maxWidth: 600,
add_links: false,
yuitips: [],
set_listeners: function(tt){
YUE.on(tt, 'mouseover', yt.show_yuitip, tt);
YUE.on(tt, 'mousemove', yt.move_yuitip, tt);
YUE.on(tt, 'mouseout', yt.close_yuitip, tt);
init: function(){
yt._tooltip = '';
yt.tipBox = yt.$('tip-box');
if(!yt.tipBox){
yt.tipBox = document.createElement('div');
document.body.appendChild(yt.tipBox);
yt.tipBox.id = 'tip-box';
YUD.setStyle(yt.tipBox, 'display', 'none');
YUD.setStyle(yt.tipBox, 'position', 'absolute');
if(yt.maxWidth !== null){
YUD.setStyle(yt.tipBox, 'max-width', yt.maxWidth+'px');
var yuitips = YUD.getElementsByClassName('tooltip');
if(yt.add_links === true){
var links = document.getElementsByTagName('a');
var linkLen = links.length;
for(i=0;i<linkLen;i++){
yuitips.push(links[i]);
var yuiLen = yuitips.length;
for(i=0;i<yuiLen;i++){
yt.set_listeners(yuitips[i]);
show_yuitip: function(e, el){
YUE.stopEvent(e);
if(el.tagName.toLowerCase() === 'img'){
yt.tipText = el.alt ? el.alt : '';
yt.tipText = el.title ? el.title : '';
if(yt.tipText !== ''){
// save org title
yt._tooltip = yt.tipText;
YUD.setAttribute(el, 'tt_title', yt.tipText);
// reset title to not show org tooltips
YUD.setAttribute(el, 'title', '');
yt.tipBox.innerHTML = yt.tipText;
YUD.setStyle(yt.tipBox, 'display', 'block');
if(yt.useAnim === true){
YUD.setStyle(yt.tipBox, 'opacity', '0');
var newAnim = new YAHOO.util.Anim(yt.tipBox,
{
opacity: { to: yt.opacity }
}, yt.speed, YAHOO.util.Easing.easeOut
newAnim.animate();
move_yuitip: function(e, el){
var movePos = YUE.getXY(e);
YUD.setStyle(yt.tipBox, 'top', (movePos[1] + yt.offset[1]) + 'px');
YUD.setStyle(yt.tipBox, 'left', (movePos[0] + yt.offset[0]) + 'px');
close_yuitip: function(e, el){
opacity: { to: 0 }
YUD.setAttribute(el,'title', yt._tooltip);
YUD.setAttribute(el,'title', YUD.getAttribute(el, 'tt_title'));
* Quick filter widget
* @param target: filter input target
* @param nodes: list of nodes in html we want to filter.
* @param display_element function that takes current node from nodes and
* does hide or show based on the node
var q_filter = function(target,nodes,display_element){
var nodes = nodes;
var q_filter_field = YUD.get(target);
var F = YAHOO.namespace(target);
YUE.on(q_filter_field,'click',function(){
q_filter_field.value = '';
YUE.on(q_filter_field,'keyup',function(e){
clearTimeout(F.filterTimeout);
F.filterTimeout = setTimeout(F.updateFilter,600);
F.filterTimeout = null;
var show_node = function(node){
YUD.setStyle(node,'display','')
var hide_node = function(node){
YUD.setStyle(node,'display','none');
F.updateFilter = function() {
// Reset timeout
var obsolete = [];
var req = q_filter_field.value.toLowerCase();
var l = nodes.length;
var i;
var showing = 0;
for (i=0;i<l;i++ ){
var n = nodes[i];
var target_element = display_element(n)
if(req && n.innerHTML.toLowerCase().indexOf(req) == -1){
hide_node(target_element);
show_node(target_element);
showing+=1;
// if repo_count is set update the number
var cnt = YUD.get('repo_count');
if(cnt){
YUD.get('repo_count').innerHTML = showing;
var tableTr = function(cls, body){
var _el = document.createElement('div');
var cont = new YAHOO.util.Element(body);
var comment_id = fromHTML(body).children[0].id.split('comment-')[1];
var id = 'comment-tr-{0}'.format(comment_id);
var _html = ('<table><tbody><tr id="{0}" class="{1}">'+
'<td class="lineno-inline new-inline"></td>'+
'<td class="lineno-inline old-inline"></td>'+
'<td>{2}</td>'+
'</tr></tbody></table>').format(id, cls, body);
_el.innerHTML = _html;
return _el.children[0].children[0].children[0];
/** comments **/
var removeInlineForm = function(form) {
form.parentNode.removeChild(form);
var createInlineForm = function(parent_tr, f_path, line) {
var tmpl = YUD.get('comment-inline-form-template').innerHTML;
tmpl = tmpl.format(f_path, line);
var form = tableTr('comment-form-inline',tmpl)
// create event for hide button
form = new YAHOO.util.Element(form);
var form_hide_button = new YAHOO.util.Element(YUD.getElementsByClassName('hide-inline-form',null,form)[0]);
form_hide_button.on('click', function(e) {
var newtr = e.currentTarget.parentNode.parentNode.parentNode.parentNode.parentNode;
if(YUD.hasClass(newtr.nextElementSibling,'inline-comments-button')){
YUD.setStyle(newtr.nextElementSibling,'display','');
removeInlineForm(newtr);
YUD.removeClass(parent_tr, 'form-open');
YUD.removeClass(parent_tr, 'hl-comment');
return form
* Inject inline comment for on given TR this tr should be always an .line
* tr containing the line. Code will detect comment, and always put the comment
* block at the very bottom
var injectInlineForm = function(tr){
if(!YUD.hasClass(tr, 'line')){
return
var submit_url = AJAX_COMMENT_URL;
var _td = YUD.getElementsByClassName('code',null,tr)[0];
if(YUD.hasClass(tr,'form-open') || YUD.hasClass(tr,'context') || YUD.hasClass(_td,'no-comment')){
YUD.addClass(tr,'form-open');
YUD.addClass(tr,'hl-comment');
var node = YUD.getElementsByClassName('full_f_path',null,tr.parentNode.parentNode.parentNode)[0];
var f_path = YUD.getAttribute(node,'path');
var lineno = getLineNo(tr);
var form = createInlineForm(tr, f_path, lineno, submit_url);
var parent = tr;
while (1){
var n = parent.nextElementSibling;
// next element are comments !
if(YUD.hasClass(n,'inline-comments')){
parent = n;
YUD.insertAfter(form,parent);
var f = YUD.get(form);
var overlay = YUD.getElementsByClassName('overlay',null,f)[0];
var _form = YUD.getElementsByClassName('inline-form',null,f)[0];
YUE.on(YUD.get(_form), 'submit',function(e){
YUE.preventDefault(e);
//ajax submit
var text = YUD.get('text_'+lineno).value;
var postData = {
'text':text,
'f_path':f_path,
'line':lineno
if(lineno === undefined){
alert('missing line !');
if(f_path === undefined){
alert('missing file path !');
if(text == ""){
YUD.removeClass(tr, 'form-open');
removeInlineForm(f);
var json_data = JSON.parse(o.responseText);
renderInlineComment(json_data);
if (YUD.hasClass(overlay,'overlay')){
var w = _form.offsetWidth;
var h = _form.offsetHeight;
YUD.setStyle(overlay,'width',w+'px');
YUD.setStyle(overlay,'height',h+'px');
YUD.addClass(overlay, 'submitting');
ajaxPOST(submit_url, postData, success);
setTimeout(function(){
// callbacks
tooltip_activate();
MentionsAutoComplete('text_'+lineno, 'mentions_container_'+lineno,
_USERS_AC_DATA, _GROUPS_AC_DATA);
var _e = YUD.get('text_'+lineno);
if(_e){
_e.focus();
},10)
var deleteComment = function(comment_id){
var url = AJAX_COMMENT_DELETE_URL.replace('__COMMENT_ID__',comment_id);
var postData = {'_method':'delete'};
var n = YUD.get('comment-tr-'+comment_id);
var root = prevElementSibling(prevElementSibling(n));
n.parentNode.removeChild(n);
// scann nodes, and attach add button to last one
placeAddButton(root);
ajaxPOST(url,postData,success);
var updateReviewers = function(reviewers_ids){
if (reviewers_ids === undefined){
var reviewers_ids = [];
var ids = YUQ('#review_members input');
for(var i=0; i<ids.length;i++){
var id = ids[i].value
reviewers_ids.push(id);
var url = AJAX_UPDATE_PULLREQUEST;
var postData = {'_method':'put',
'reviewers_ids': reviewers_ids};
window.location.reload();
var createInlineAddButton = function(tr){
var label = TRANSLATION_MAP['add another comment'];
var html_el = document.createElement('div');
YUD.addClass(html_el, 'add-comment');
html_el.innerHTML = '<span class="ui-btn">{0}</span>'.format(label);
var add = new YAHOO.util.Element(html_el);
add.on('click', function(e) {
injectInlineForm(tr);
return add;
var getLineNo = function(tr) {
var line;
var o = tr.children[0].id.split('_');
var n = tr.children[1].id.split('_');
if (n.length >= 2) {
line = n[n.length-1];
} else if (o.length >= 2) {
line = o[o.length-1];
return line
var placeAddButton = function(target_tr){
if(!target_tr){
var last_node = target_tr;
//scann
var n = last_node.nextElementSibling;
last_node = n;
//also remove the comment button from previous
var comment_add_buttons = YUD.getElementsByClassName('add-comment',null,last_node);
for(var i=0;i<comment_add_buttons.length;i++){
var b = comment_add_buttons[i];
b.parentNode.removeChild(b);
var add = createInlineAddButton(target_tr);
// get the comment div
var comment_block = YUD.getElementsByClassName('comment',null,last_node)[0];
// attach add button
YUD.insertAfter(add,comment_block);
* Places the inline comment into the changeset block in proper line position
var placeInline = function(target_container,lineno,html){
var lineid = "{0}_{1}".format(target_container,lineno);
var target_line = YUD.get(lineid);
var comment = new YAHOO.util.Element(tableTr('inline-comments',html))
// check if there are comments already !
var parent = target_line.parentNode;
var root_parent = parent;
// put in the comment at the bottom
YUD.insertAfter(comment,parent);
placeAddButton(root_parent);
return target_line;
* make a single inline comment and place it inside
var renderInlineComment = function(json_data){
var html = json_data['rendered_text'];
var lineno = json_data['line_no'];
var target_id = json_data['target_id'];
placeInline(target_id, lineno, html);
}catch(e){
console.log(e);
* Iterates over all the inlines, and places them inside proper blocks of data
var renderInlineComments = function(file_comments){
for (f in file_comments){
// holding all comments for a FILE
var box = file_comments[f];
var target_id = YUD.getAttribute(box,'target_id');
// actually comments with line numbers
var comments = box.children;
for(var i=0; i<comments.length; i++){
var data = {
'rendered_text': comments[i].outerHTML,
'line_no': YUD.getAttribute(comments[i],'line'),
'target_id': target_id
renderInlineComment(data);
var removeReviewer = function(reviewer_id){
var el = YUD.get('reviewer_{0}'.format(reviewer_id));
if (el.parentNode !== undefined){
el.parentNode.removeChild(el);
updateReviewers();
var fileBrowserListeners = function(current_url, node_list_url, url_base){
var current_url_branch = +"?branch=__BRANCH__";
YUE.on('stay_at_branch','click',function(e){
if(e.target.checked){
var uri = current_url_branch;
uri = uri.replace('__BRANCH__',e.target.value);
window.location = uri;
window.location = current_url;
})
var n_filter = YUD.get('node_filter');
var F = YAHOO.namespace('node_filter');
Status change: