Changeset - 4debfe3b50be
[Not reviewed]
beta
0 1 0
Marcin Kuzminski - 13 years ago 2012-08-07 22:10:44
marcin@python-works.com
ie8 fixes for inline comments :/
1 file changed with 37 insertions and 19 deletions:
0 comments (0 inline, 0 general)
rhodecode/public/js/rhodecode.js
Show inline comments
 
@@ -54,48 +54,62 @@ String.prototype.lstrip = function(char)
 
	if(char === undefined){
 
	    char = '\\s';
 
	}
 
	return this.replace(new RegExp('^'+char+'+'),'');
 
}
 
String.prototype.rstrip = function(char) {
 
	if(char === undefined){
 
	    char = '\\s';
 
	}
 
	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;
 
        }
 
    }
 
}
 

	
 

	
 

	
 

	
 
/**
 
 * 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];
 
    	}
 
@@ -462,58 +476,61 @@ var injectInlineForm = function(tr){
 
		  
 
		  var success = function(o){
 
			  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);
 
		  YUD.get('text_'+lineno).focus();
 
		  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 success = function(o){
 
        var n = YUD.get('comment-tr-'+comment_id);
 
        var root = n.previousElementSibling.previousElementSibling;
 
        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){
 
	var url = AJAX_UPDATE_PULLREQUEST;
 
	var postData = {'_method':'put',
 
			        'reviewers_ids': reviewers_ids};
 
	var success = function(o){
 
		window.location.reload();
 
	}
 
	ajaxPOST(url,postData,success);
 
}
 

	
 
var createInlineAddButton = function(tr){
 

	
 
	var label = TRANSLATION_MAP['add another comment'];
 
	
 
	var html_el = document.createElement('div');
 
	YUD.addClass(html_el, 'add-comment');
 
@@ -1213,65 +1230,66 @@ var MentionsAutoComplete = function (div
 
    	var org = msg;
 
    	var re = new RegExp('(?:^@|\s@)([a-zA-Z0-9]{1}[a-zA-Z0-9\-\_\.]+)$')
 
    	var chunks  = [];
 

	
 
		
 
    	// cut first chunk until curret pos
 
		var to_max = msg.substr(0, max_pos);		
 
		var at_pos = Math.max(0,to_max.lastIndexOf('@')-1);
 
		var msg2 = to_max.substr(at_pos);
 

	
 
		chunks.push(org.substr(0,at_pos))// prefix chunk
 
		chunks.push(msg2)                // search chunk
 
		chunks.push(org.substr(max_pos)) // postfix chunk
 

	
 
		// clean up msg2 for filtering and regex match
 
		var msg2 = msg2.lstrip(' ').lstrip('\n');
 

	
 
		if(re.test(msg2)){
 
			var unam = re.exec(msg2)[1];
 
			return [unam, chunks];
 
		}
 
		return [null, null];
 
    };
 
    
 
	ownerAC.textboxKeyUpEvent.subscribe(function(type, args){
 
		
 
		var ac_obj = args[0];
 
		var currentMessage = args[1];
 
		var currentCaretPosition = args[0]._elTextbox.selectionStart;
 

	
 
		var unam = ownerAC.get_mention(currentMessage, currentCaretPosition); 
 
		var curr_search = null;
 
		if(unam[0]){
 
			curr_search = unam[0];
 
		}
 
		
 
		ownerAC.dataSource.chunks = unam[1];
 
		ownerAC.dataSource.mentionQuery = curr_search;
 

	
 
	})
 

	
 
    if (ownerAC.textboxKeyUpEvent){
 
		ownerAC.textboxKeyUpEvent.subscribe(function(type, args){
 
			
 
			var ac_obj = args[0];
 
			var currentMessage = args[1];
 
			var currentCaretPosition = args[0]._elTextbox.selectionStart;
 
	
 
			var unam = ownerAC.get_mention(currentMessage, currentCaretPosition); 
 
			var curr_search = null;
 
			if(unam[0]){
 
				curr_search = unam[0];
 
			}
 
			
 
			ownerAC.dataSource.chunks = unam[1];
 
			ownerAC.dataSource.mentionQuery = curr_search;
 
	
 
		})
 
	}	
 
    return {
 
        ownerDS: ownerDS,
 
        ownerAC: ownerAC,
 
    };
 
}
 

	
 

	
 
var PullRequestAutoComplete = function (divid, cont, users_list, groups_list) {
 
    var myUsers = users_list;
 
    var myGroups = groups_list;
 

	
 
    // Define a custom search function for the DataSource of users
 
    var matchUsers = function (sQuery) {
 
            // Case insensitive matching
 
            var query = sQuery.toLowerCase();
 
            var i = 0;
 
            var l = myUsers.length;
 
            var matches = [];
 

	
 
            // Match against each name of each contact
 
            for (; i < l; i++) {
 
                contact = myUsers[i];
 
                if (((contact.fname+"").toLowerCase().indexOf(query) > -1) || 
 
                   	 ((contact.lname+"").toLowerCase().indexOf(query) > -1) || 
0 comments (0 inline, 0 general)