comparison rhodecode/public/js/rhodecode.js @ 4160:4451b2eabf64 rhodecode-2.2.5-gpl

rhodecode.js: more jQuery and general cleanup Mostly replacing YAHOO.util.Dom and Event
author Mads Kiilerich <madski@unity3d.com>
date Wed, 02 Jul 2014 19:03:26 -0400
parents a991e5c57a8d
children f51578556bc2
comparison
equal deleted inserted replaced
4159:a991e5c57a8d 4160:4451b2eabf64
66 return i; 66 return i;
67 } 67 }
68 } 68 }
69 return -1; 69 return -1;
70 }; 70 };
71 }
72
73 // IE(CRAP) doesn't support previousElementSibling
74 var prevElementSibling = function( el ) {
75 if( el.previousElementSibling ) {
76 return el.previousElementSibling;
77 } else {
78 while( el = el.previousSibling ) {
79 if( el.nodeType === 1 ) return el;
80 }
81 }
82 } 71 }
83 72
84 /** 73 /**
85 * A customized version of PyRoutes.JS from https://pypi.python.org/pypi/pyroutes.js/ 74 * A customized version of PyRoutes.JS from https://pypi.python.org/pypi/pyroutes.js/
86 * which is copyright Stephane Klein and was made available under the BSD License. 75 * which is copyright Stephane Klein and was made available under the BSD License.
271 var YUC = YAHOO.util.Connect; 260 var YUC = YAHOO.util.Connect;
272 var YUD = YAHOO.util.Dom; 261 var YUD = YAHOO.util.Dom;
273 var YUE = YAHOO.util.Event; 262 var YUE = YAHOO.util.Event;
274 var YUQ = YAHOO.util.Selector.query; 263 var YUQ = YAHOO.util.Selector.query;
275 264
265 /* Invoke all functions in callbacks */
276 var _run_callbacks = function(callbacks){ 266 var _run_callbacks = function(callbacks){
277 if (callbacks !== undefined){ 267 if (callbacks !== undefined){
278 var _l = callbacks.length; 268 var _l = callbacks.length;
279 for (var i=0;i<_l;i++){ 269 for (var i=0;i<_l;i++){
280 var func = callbacks[i]; 270 var func = callbacks[i];
288 } 278 }
289 279
290 /** 280 /**
291 * turns objects into GET query string 281 * turns objects into GET query string
292 */ 282 */
293 var toQueryString = function(o) { 283 var _toQueryString = function(o) {
294 if(typeof o !== 'object') { 284 if(typeof o !== 'object') {
295 return false; 285 return false;
296 } 286 }
297 var _p, _qs = []; 287 var _p, _qs = [];
298 for(_p in o) { 288 for(_p in o) {
321 function ypjax(url,container,s_call,f_call,args){ 311 function ypjax(url,container,s_call,f_call,args){
322 var method='GET'; 312 var method='GET';
323 if(args===undefined){ 313 if(args===undefined){
324 args=null; 314 args=null;
325 } 315 }
316 $container = $('#' + container);
326 317
327 // Set special header for partial ajax == HTTP_X_PARTIAL_XHR 318 // Set special header for partial ajax == HTTP_X_PARTIAL_XHR
328 YUC.initHeader('X-PARTIAL-XHR',true); 319 YUC.initHeader('X-PARTIAL-XHR',true);
329 320
330 // wrapper of passed callback 321 // wrapper of passed callback
331 var s_wrapper = (function(o){ 322 var s_wrapper = (function(o){
332 return function(o){ 323 return function(o){
333 YUD.get(container).innerHTML=o.responseText; 324 $container.html(o.responseText);
334 YUD.setStyle(container,'opacity','1.0'); 325 $container.css('opacity','1.0');
335 //execute the given original callback 326 //execute the given original callback
336 if (s_call !== undefined){ 327 if (s_call !== undefined){
337 s_call(o); 328 s_call(o);
338 } 329 }
339 } 330 }
340 })() 331 })()
341 YUD.setStyle(container,'opacity','0.3'); 332 $container.css('opacity','0.3');
342 YUC.asyncRequest(method,url,{ 333 YUC.asyncRequest(method,url,{
343 success:s_wrapper, 334 success:s_wrapper,
344 failure:function(o){ 335 failure:function(o){
345 console.log(o); 336 console.log('ypjax failure: '+o);
346 YUD.get(container).innerHTML='<span class="error_red">ERROR: {0}</span>'.format(o.status); 337 $container.html('<span class="error_red">ERROR: {0}</span>'.format(o.status));
347 YUD.setStyle(container,'opacity','1.0'); 338 $container.css('opacity','1.0');
348 }, 339 },
349 cache:false 340 cache:false
350 },args); 341 },args);
351 342
352 }; 343 };
378 success: success, 369 success: success,
379 failure: function (o) { 370 failure: function (o) {
380 alert("error"); 371 alert("error");
381 }, 372 },
382 }; 373 };
383 var postData = toQueryString(postData); 374 var postData = _toQueryString(postData);
384 var request = YAHOO.util.Connect.asyncRequest('POST', sUrl, callback, postData); 375 var request = YAHOO.util.Connect.asyncRequest('POST', sUrl, callback, postData);
385 return request; 376 return request;
386 }; 377 };
387 378
388 379
389 /** 380 /**
390 * tooltip activate 381 * activate .show_more links
391 */ 382 * the .show_more must have an id that is the the id of an element to hide prefixed with _
392 var tooltip_activate = function(){ 383 * the parentnode will be displayed
393 yt = YAHOO.yuitip.main;
394 YUE.onDOMReady(yt.init);
395 };
396
397 /**
398 * show more
399 */ 384 */
400 var show_more_event = function(){ 385 var show_more_event = function(){
401 YUE.on(YUD.getElementsByClassName('show_more'),'click',function(e){ 386 $('.show_more').click(function(e){
402 var el = e.target; 387 var el = e.currentTarget;
403 YUD.setStyle(YUD.get(el.id.substring(1)),'display',''); 388 $('#' + el.id.substring(1)).hide();
404 YUD.setStyle(el.parentNode,'display','none'); 389 $(el.parentNode).show();
405 }); 390 });
406 }; 391 };
407 392
408 /** 393 /**
409 * show changeset tooltip 394 * activate .lazy-cs mouseover for showing changeset tooltip
410 */ 395 */
411 var show_changeset_tooltip = function(){ 396 var show_changeset_tooltip = function(){
412 YUE.on(YUD.getElementsByClassName('lazy-cs'), 'mouseover', function(e){ 397 $('.lazy-cs').mouseover(function(e){
413 var target = e.currentTarget; 398 var $target = $(e.currentTarget);
414 var rid = YUD.getAttribute(target,'raw_id'); 399 var rid = $target.attr('raw_id');
415 var repo_name = YUD.getAttribute(target,'repo_name'); 400 var repo_name = $target.attr('repo_name');
416 var ttid = 'tt-'+rid; 401 if(rid && !$target.hasClass('tooltip')){
417 var success = function(o){ 402 _show_tooltip(e, _TM['loading ...']);
418 var json = JSON.parse(o.responseText); 403 var url = pyroutes.url('changeset_info', {"repo_name": repo_name, "revision": rid});
419 YUD.addClass(target,'tooltip') 404 ajaxGET(url, function(o){
420 YUD.setAttribute(target, 'title',json['message']); 405 var json = JSON.parse(o.responseText);
421 YAHOO.yuitip.main.show_yuitip(e, target); 406 $target.addClass('tooltip')
422 } 407 _show_tooltip(e, json['message']);
423 if(rid && !YUD.hasClass(target, 'tooltip')){ 408 _activate_tooltip($target);
424 YUD.setAttribute(target,'id',ttid); 409 });
425 YUD.setAttribute(target, 'title',_TM['loading ...']);
426 YAHOO.yuitip.main.set_listeners(target);
427 YAHOO.yuitip.main.show_yuitip(e, target);
428 var url = pyroutes.url('changeset_info', {"repo_name":repo_name, "revision": rid});
429 ajaxGET(url, success)
430 } 410 }
431 }); 411 });
432 }; 412 };
433 413
434 var onSuccessFollow = function(target){ 414 var _onSuccessFollow = function(target){
435 var f = YUD.get(target); 415 var $target = $(target);
436 var f_cnt = YUD.get('current_followers_count'); 416 var $f_cnt = $('#current_followers_count');
437 417 if($target.hasClass('follow')){
438 if(YUD.hasClass(f, 'follow')){ 418 $target.attr('class', 'following');
439 f.setAttribute('class','following'); 419 $target.attr('title', _TM['Stop following this repository']);
440 f.setAttribute('title',_TM['Stop following this repository']); 420 if($f_cnt.html()){
441 421 var cnt = Number($f_cnt.html())+1;
442 if(f_cnt){ 422 $f_cnt.html(cnt);
443 var cnt = Number(f_cnt.innerHTML)+1;
444 f_cnt.innerHTML = cnt;
445 } 423 }
446 } 424 }
447 else{ 425 else{
448 f.setAttribute('class','follow'); 426 $target.attr('class', 'follow');
449 f.setAttribute('title',_TM['Start following this repository']); 427 $target.attr('title', _TM['Start following this repository']);
450 if(f_cnt){ 428 if($f_cnt.html()){
451 var cnt = Number(f_cnt.innerHTML)-1; 429 var cnt = Number($f_cnt.html())-1;
452 f_cnt.innerHTML = cnt; 430 $f_cnt.html(cnt);
453 } 431 }
454 } 432 }
455 } 433 }
456 434
457 var toggleFollowingRepo = function(target,fallows_repo_id,token,user_id){ 435 var toggleFollowingRepo = function(target, follows_repo_id, token, user_id){
458 args = 'follows_repo_id='+fallows_repo_id; 436 args = 'follows_repo_id='+follows_repo_id;
459 args+= '&amp;auth_token='+token; 437 args+= '&amp;auth_token='+token;
460 if(user_id != undefined){ 438 if(user_id != undefined){
461 args+="&amp;user_id="+user_id; 439 args+="&amp;user_id="+user_id;
462 } 440 }
463 $.post(TOGGLE_FOLLOW_URL, args, function(data){ 441 $.post(TOGGLE_FOLLOW_URL, args, function(data){
464 onSuccessFollow(target); 442 _onSuccessFollow(target);
465 }); 443 });
466 return false; 444 return false;
467 } 445 };
468 446
469 var showRepoSize = function(target, repo_name, token){ 447 var showRepoSize = function(target, repo_name, token){
470 var args= 'auth_token='+token; 448 var args= 'auth_token='+token;
471 449
472 if(!$("#" + target).hasClass('loaded')){ 450 if(!$("#" + target).hasClass('loaded')){
476 $("#" + target).html(data); 454 $("#" + target).html(data);
477 $("#" + target).addClass('loaded'); 455 $("#" + target).addClass('loaded');
478 }); 456 });
479 } 457 }
480 return false; 458 return false;
481 } 459 };
482 460
483 /** 461 /**
484 * TOOLTIP IMPL. 462 * tooltips
485 */ 463 */
486 YAHOO.namespace('yuitip'); 464
487 YAHOO.yuitip.main = { 465 var tooltip_activate = function(){
488 466 $(document).ready(_init_tooltip);
489 $: YAHOO.util.Dom.get, 467 };
490 468
491 bgColor: '#000', 469 var _activate_tooltip = function($tt){
492 speed: 0.3, 470 $tt.mouseover(_show_tooltip);
493 opacity: 0.9, 471 $tt.mousemove(_move_tooltip);
494 offset: [15,15], 472 $tt.mouseout(_close_tooltip);
495 useAnim: false, 473 };
496 maxWidth: 600, 474
497 add_links: false, 475 var _init_tooltip = function(){
498 yuitips: [], 476 var $tipBox = $('#tip-box');
499 477 if(!$tipBox.length){
500 set_listeners: function(tt){ 478 $tipBox = $('<div id="tip-box"></div>')
501 YUE.on(tt, 'mouseover', yt.show_yuitip, tt); 479 $(document.body).append($tipBox);
502 YUE.on(tt, 'mousemove', yt.move_yuitip, tt); 480 }
503 YUE.on(tt, 'mouseout', yt.close_yuitip, tt); 481
504 }, 482 $tipBox.hide();
505 483 $tipBox.css('position', 'absolute');
506 init: function(){ 484 $tipBox.css('max-width', '600px');
507 yt.tipBox = yt.$('tip-box'); 485
508 if(!yt.tipBox){ 486 _activate_tooltip($('.tooltip'));
509 yt.tipBox = document.createElement('div'); 487 };
510 document.body.appendChild(yt.tipBox); 488
511 yt.tipBox.id = 'tip-box'; 489 var _show_tooltip = function(e, tipText){
512 } 490 e.stopImmediatePropagation();
513 491 var el = e.currentTarget;
514 YUD.setStyle(yt.tipBox, 'display', 'none'); 492 if(tipText){
515 YUD.setStyle(yt.tipBox, 'position', 'absolute'); 493 // just use it
516 if(yt.maxWidth !== null){ 494 } else if(el.tagName.toLowerCase() === 'img'){
517 YUD.setStyle(yt.tipBox, 'max-width', yt.maxWidth+'px'); 495 tipText = el.alt ? el.alt : '';
518 } 496 } else {
519 497 tipText = el.title ? el.title : '';
520 var yuitips = YUD.getElementsByClassName('tooltip'); 498 }
521 499
522 if(yt.add_links === true){ 500 if(tipText !== ''){
523 var links = document.getElementsByTagName('a'); 501 // save org title
524 var linkLen = links.length; 502 $(el).attr('tt_title', tipText);
525 for(i=0;i<linkLen;i++){ 503 // reset title to not show org tooltips
526 yuitips.push(links[i]); 504 $(el).attr('title', '');
527 } 505
528 } 506 var $tipBox = $('#tip-box');
529 507 $tipBox.html(tipText);
530 var yuiLen = yuitips.length; 508 $tipBox.css('display', 'block');
531 509 }
532 for(i=0;i<yuiLen;i++){ 510 };
533 yt.set_listeners(yuitips[i]); 511
534 } 512 var _move_tooltip = function(e){
535 }, 513 e.stopImmediatePropagation();
536 514 var $tipBox = $('#tip-box');
537 show_yuitip: function(e, el){ 515 $tipBox.css('top', (e.pageY + 15) + 'px');
538 YUE.stopEvent(e); 516 $tipBox.css('left', (e.pageX + 15) + 'px');
539 if(el.tagName.toLowerCase() === 'img'){ 517 };
540 yt.tipText = el.alt ? el.alt : ''; 518
541 } else { 519 var _close_tooltip = function(e){
542 yt.tipText = el.title ? el.title : ''; 520 e.stopImmediatePropagation();
543 } 521 var $tipBox = $('#tip-box');
544 522 $tipBox.hide();
545 if(yt.tipText !== ''){ 523 var el = e.currentTarget;
546 // save org title 524 $(el).attr('title', $(el).attr('tt_title'));
547 YUD.setAttribute(el, 'tt_title', yt.tipText); 525 };
548 // reset title to not show org tooltips
549 YUD.setAttribute(el, 'title', '');
550
551 yt.tipBox.innerHTML = yt.tipText;
552 YUD.setStyle(yt.tipBox, 'display', 'block');
553 if(yt.useAnim === true){
554 YUD.setStyle(yt.tipBox, 'opacity', '0');
555 var newAnim = new YAHOO.util.Anim(yt.tipBox,
556 {
557 opacity: { to: yt.opacity }
558 }, yt.speed, YAHOO.util.Easing.easeOut
559 );
560 newAnim.animate();
561 }
562 }
563 },
564
565 move_yuitip: function(e, el){
566 YUE.stopEvent(e);
567 var movePos = YUE.getXY(e);
568 YUD.setStyle(yt.tipBox, 'top', (movePos[1] + yt.offset[1]) + 'px');
569 YUD.setStyle(yt.tipBox, 'left', (movePos[0] + yt.offset[0]) + 'px');
570 },
571
572 close_yuitip: function(e, el){
573 YUE.stopEvent(e);
574
575 if(yt.useAnim === true){
576 var newAnim = new YAHOO.util.Anim(yt.tipBox,
577 {
578 opacity: { to: 0 }
579 }, yt.speed, YAHOO.util.Easing.easeOut
580 );
581 newAnim.animate();
582 } else {
583 YUD.setStyle(yt.tipBox, 'display', 'none');
584 }
585 YUD.setAttribute(el,'title', YUD.getAttribute(el, 'tt_title'));
586 }
587 }
588 526
589 /** 527 /**
590 * Quick filter widget 528 * Quick filter widget
591 * 529 *
592 * @param target: filter input target 530 * @param target: filter input target
593 * @param nodes: list of nodes in html we want to filter. 531 * @param nodes: list of nodes in html we want to filter.
594 * @param display_element function that takes current node from nodes and 532 * @param display_element function that takes current node from nodes and
595 * does hide or show based on the node 533 * does hide or show based on the node
596 *
597 */ 534 */
598 var q_filter = function(target,nodes,display_element){ 535 var q_filter = function(target, nodes, display_element){
599
600 var nodes = nodes; 536 var nodes = nodes;
601 var q_filter_field = YUD.get(target); 537 var $q_filter_field = $('#' + target);
602 var F = YAHOO.namespace(target); 538 var F = YAHOO.namespace(target);
603 539
604 YUE.on(q_filter_field,'keyup',function(e){ 540 $q_filter_field.keyup(function(e){
605 clearTimeout(F.filterTimeout); 541 clearTimeout(F.filterTimeout);
606 F.filterTimeout = setTimeout(F.updateFilter,600); 542 F.filterTimeout = setTimeout(F.updateFilter, 600);
607 }); 543 });
608 544
609 F.filterTimeout = null; 545 F.filterTimeout = null;
610
611 var show_node = function(node){
612 YUD.setStyle(node,'display','')
613 }
614 var hide_node = function(node){
615 YUD.setStyle(node,'display','none');
616 }
617 546
618 F.updateFilter = function() { 547 F.updateFilter = function() {
619 // Reset timeout 548 // Reset timeout
620 F.filterTimeout = null; 549 F.filterTimeout = null;
621 550
622 var obsolete = []; 551 var obsolete = [];
623 552
624 var req = q_filter_field.value.toLowerCase(); 553 var req = $q_filter_field.val().toLowerCase();
625 554
626 var l = nodes.length; 555 var l = nodes.length;
627 var i; 556 var i;
628 var showing = 0; 557 var showing = 0;
629 558
630 for (i=0;i<l;i++ ){ 559 for (i=0; i<l; i++ ){
631 var n = nodes[i]; 560 var n = nodes[i];
632 var target_element = display_element(n) 561 var target_element = display_element(n)
633 if(req && n.innerHTML.toLowerCase().indexOf(req) == -1){ 562 if(req && n.innerHTML.toLowerCase().indexOf(req) == -1){
634 hide_node(target_element); 563 $(target_element).hide();
635 } 564 }
636 else{ 565 else{
637 show_node(target_element); 566 $(target_element).show();
638 showing+=1; 567 showing += 1;
639 } 568 }
640 } 569 }
641 570
642 // if repo_count is set update the number 571 $('#repo_count').html(showing); /* FIXME: don't hardcode */
643 var cnt = YUD.get('repo_count'); 572 }
644 if(cnt){ 573 };
645 YUD.get('repo_count').innerHTML = showing; 574
646 } 575 /* return jQuery expression with a tr with body in 3rd column and class cls and id named after the body */
647 } 576 var _table_tr = function(cls, body){
648 }; 577 // like: <div class="comment" id="comment-8" line="o92"><div class="comment-wrapp">...
649 578 // except new inlines which are different ...
650 var tableTr = function(cls, body){ 579 var comment_id = ($(body).attr('id') || 'comment-new').split('comment-')[1];
651 var _el = document.createElement('div'); 580 var tr_id = 'comment-tr-{0}'.format(comment_id);
652 var cont = new YAHOO.util.Element(body); 581 return $(('<tr id="{0}" class="{1}">'+
653 var comment_id = fromHTML(body).children[0].id.split('comment-')[1];
654 var id = 'comment-tr-{0}'.format(comment_id);
655 var _html = ('<table><tbody><tr id="{0}" class="{1}">'+
656 '<td class="lineno-inline new-inline"></td>'+ 582 '<td class="lineno-inline new-inline"></td>'+
657 '<td class="lineno-inline old-inline"></td>'+ 583 '<td class="lineno-inline old-inline"></td>'+
658 '<td>{2}</td>'+ 584 '<td>{2}</td>'+
659 '</tr></tbody></table>').format(id, cls, body); 585 '</tr>').format(tr_id, cls, body));
660 _el.innerHTML = _html; 586 };
661 return _el.children[0].children[0].children[0]; 587
662 }; 588 /** return jQuery expression with new inline form based on template **/
663 589 var _createInlineForm = function(parent_tr, f_path, line) {
664 var createInlineForm = function(parent_tr, f_path, line) { 590 var $tmpl = $('#comment-inline-form-template').html().format(f_path, line);
665 var tmpl = $('#comment-inline-form-template').html(); 591 var $form = _table_tr('comment-form-inline', $tmpl)
666 tmpl = tmpl.format(f_path, line);
667 var form = tableTr('comment-form-inline',tmpl)
668 592
669 // create event for hide button 593 // create event for hide button
670 form = new YAHOO.util.Element(form); 594 $form.find('.hide-inline-form').click(function(e) {
671 var form_hide_button = new YAHOO.util.Element(YUD.getElementsByClassName('hide-inline-form',null,form)[0]);
672 form_hide_button.on('click', function(e) {
673 var newtr = e.currentTarget.parentNode.parentNode.parentNode.parentNode.parentNode; 595 var newtr = e.currentTarget.parentNode.parentNode.parentNode.parentNode.parentNode;
674 if(YUD.hasClass(newtr.nextElementSibling,'inline-comments-button')){ 596 if($(newtr).next().hasClass('inline-comments-button')){
675 YUD.setStyle(newtr.nextElementSibling,'display',''); 597 $(newtr).next().show();
676 } 598 }
677 removeInlineForm(newtr); 599 $(newtr).remove();
678 YUD.removeClass(parent_tr, 'form-open'); 600 $(parent_tr).removeClass('form-open');
679 YUD.removeClass(parent_tr, 'hl-comment'); 601 $(parent_tr).removeClass('hl-comment');
680
681 }); 602 });
682 603
683 return form 604 return $form
684 }; 605 };
685 606
686 /** 607 /**
687 * Inject inline comment for on given TR this tr should be always an .line 608 * Inject inline comment for an given TR. This tr should always be a .line .
688 * tr containing the line. Code will detect comment, and always put the comment 609 * The form will be inject after any comments.
689 * block at the very bottom
690 */ 610 */
691 var injectInlineForm = function(tr){ 611 var injectInlineForm = function(tr){
692 if(!$(tr).hasClass('line')){ 612 $tr = $(tr);
613 if(!$tr.hasClass('line')){
693 return 614 return
694 } 615 }
695 var submit_url = AJAX_COMMENT_URL; 616 var submit_url = AJAX_COMMENT_URL;
696 var _td = YUD.getElementsByClassName('code',null,tr)[0]; 617 var $td = $tr.find('.code');
697 if($(tr).hasClass('form-open') || $(tr).hasClass('context') || $(_td).hasClass('no-comment')){ 618 if($tr.hasClass('form-open') || $tr.hasClass('context') || $td.hasClass('no-comment')){
698 return 619 return
699 } 620 }
700 $(tr).addClass('form-open hl-comment'); 621 $tr.addClass('form-open hl-comment');
701 var node = YUD.getElementsByClassName('full_f_path',null,tr.parentNode.parentNode.parentNode)[0]; 622 var $node = $tr.parent().parent().parent().find('.full_f_path');
702 var f_path = YUD.getAttribute(node,'path'); 623 var f_path = $node.attr('path');
703 var lineno = getLineNo(tr); 624 var lineno = _getLineNo(tr);
704 var form = createInlineForm(tr, f_path, lineno, submit_url); 625 var $form = _createInlineForm(tr, f_path, lineno, submit_url);
705 626
706 var parent = tr; 627 var $parent = $tr;
707 while (1){ 628 while ($parent.next().hasClass('inline-comments')){
708 var n = parent.nextElementSibling; 629 var $parent = $parent.next();
709 // next element are comments ! 630 }
710 if($(n).hasClass('inline-comments')){ 631 $form.insertAfter($parent);
711 parent = n; 632 var $overlay = $form.find('.overlay');
712 } 633 var $inlineform = $form.find('.inline-form');
713 else{ 634
714 break; 635 $form.submit(function(e){
715 } 636 e.preventDefault();
716 }
717 YUD.insertAfter(form,parent);
718 var f = YUD.get(form);
719 var overlay = YUD.getElementsByClassName('overlay',null,f)[0];
720 var _form = YUD.getElementsByClassName('inline-form',null,f)[0];
721
722 YUE.on(YUD.get(_form), 'submit',function(e){
723 YUE.preventDefault(e);
724
725 //ajax submit
726 var text = YUD.get('text_'+lineno).value;
727 var postData = {
728 'text':text,
729 'f_path':f_path,
730 'line':lineno
731 };
732 637
733 if(lineno === undefined){ 638 if(lineno === undefined){
734 alert('missing line !'); 639 alert('missing line !');
735 return 640 return
736 } 641 }
737 if(f_path === undefined){ 642 if(f_path === undefined){
738 alert('missing file path !'); 643 alert('missing file path !');
739 return 644 return
740 } 645 }
741 646
647 var text = $('#text_'+lineno).val();
742 if(text == ""){ 648 if(text == ""){
743 return 649 return
744 } 650 }
745 651
652 if ($overlay.hasClass('overlay')){
653 $overlay.css('width', $inlineform.offsetWidth + 'px');
654 $overlay.css('height', $inlineform.offsetHeight + 'px');
655 }
656 $overlay.addClass('submitting');
657
746 var success = function(o){ 658 var success = function(o){
747 YUD.removeClass(tr, 'form-open'); 659 $tr.removeClass('form-open');
748 removeInlineForm(f); 660 $form.remove();
749 var json_data = JSON.parse(o.responseText); 661 var json_data = JSON.parse(o.responseText);
750 renderInlineComment(json_data); 662 _renderInlineComment(json_data);
751 }; 663 };
752 664 var postData = {
753 if (YUD.hasClass(overlay,'overlay')){ 665 'text': text,
754 var w = _form.offsetWidth; 666 'f_path': f_path,
755 var h = _form.offsetHeight; 667 'line': lineno
756 YUD.setStyle(overlay,'width',w+'px'); 668 };
757 YUD.setStyle(overlay,'height',h+'px');
758 }
759 YUD.addClass(overlay, 'submitting');
760
761 ajaxPOST(submit_url, postData, success); 669 ajaxPOST(submit_url, postData, success);
762 }); 670 });
763 671
764 YUE.on('preview-btn_'+lineno, 'click', function(e){ 672 $('#preview-btn_'+lineno).click(function(e){
765 var _text = YUD.get('text_'+lineno).value; 673 var text = $('#text_'+lineno).val();
766 if(!_text){ 674 if(!text){
767 return 675 return
768 } 676 }
769 var post_data = {'text': _text}; 677 $('#preview-box_'+lineno).addClass('unloaded');
770 YUD.addClass('preview-box_'+lineno, 'unloaded'); 678 $('#preview-box_'+lineno).html(_TM['Loading ...']);
771 YUD.get('preview-box_'+lineno).innerHTML = _TM['Loading ...']; 679 $('#edit-container_'+lineno).hide();
772 YUD.setStyle('edit-container_'+lineno, 'display', 'none'); 680 $('#preview-container_'+lineno).show();
773 YUD.setStyle('preview-container_'+lineno, 'display', '');
774 681
775 var url = pyroutes.url('changeset_comment_preview', {'repo_name': REPO_NAME}); 682 var url = pyroutes.url('changeset_comment_preview', {'repo_name': REPO_NAME});
776 ajaxPOST(url,post_data,function(o){ 683 var post_data = {'text': text};
777 YUD.get('preview-box_'+lineno).innerHTML = o.responseText; 684 ajaxPOST(url, post_data, function(o){
778 YUD.removeClass('preview-box_'+lineno, 'unloaded'); 685 $('#preview-box_'+lineno).html(o.responseText);
686 $('#preview-box_'+lineno).removeClass('unloaded');
779 }) 687 })
780 }) 688 })
781 YUE.on('edit-btn_'+lineno, 'click', function(e){ 689 $('#edit-btn_'+lineno).click(function(e){
782 YUD.setStyle('edit-container_'+lineno, 'display', ''); 690 $('#edit-container_'+lineno).show();
783 YUD.setStyle('preview-container_'+lineno, 'display', 'none'); 691 $('#preview-container_'+lineno).hide();
784 }) 692 })
785 693
786 setTimeout(function(){ 694 setTimeout(function(){
787 // callbacks 695 // callbacks
788 tooltip_activate(); 696 tooltip_activate();
789 MentionsAutoComplete('text_'+lineno, 'mentions_container_'+lineno, 697 MentionsAutoComplete('text_'+lineno, 'mentions_container_'+lineno,
790 _USERS_AC_DATA, _GROUPS_AC_DATA); 698 _USERS_AC_DATA, _GROUPS_AC_DATA);
791 var _e = YUD.get('text_'+lineno); 699 $('#text_'+lineno).focus();
792 if(_e){
793 _e.focus();
794 }
795 },10) 700 },10)
796 }; 701 };
797 702
798 var deleteComment = function(comment_id){ 703 var deleteComment = function(comment_id){
799 var url = AJAX_COMMENT_DELETE_URL.replace('__COMMENT_ID__',comment_id); 704 var url = AJAX_COMMENT_DELETE_URL.replace('__COMMENT_ID__',comment_id);
800 var postData = {'_method':'delete'}; 705 var postData = {'_method':'delete'};
801 var success = function(o){ 706 var success = function(o){
802 var n = YUD.get('comment-tr-'+comment_id); 707 var $deleted = $('#comment-tr-'+comment_id);
803 var root = prevElementSibling(prevElementSibling(n)); 708 var $prev = $deleted.prev('tr');
804 n.parentNode.removeChild(n); 709 $deleted.remove();
805 710 _placeAddButton($prev);
806 // scann nodes, and attach add button to last one only for TR
807 // which are the inline comments
808 if(root && root.tagName == 'TR'){
809 placeAddButton(root);
810 }
811 } 711 }
812 ajaxPOST(url,postData,success); 712 ajaxPOST(url,postData,success);
813 } 713 }
814 714
815 var createInlineAddButton = function(tr){ 715 var _getLineNo = function(tr) {
816
817 var label = TRANSLATION_MAP['Add another comment'];
818
819 var html_el = document.createElement('div');
820 YUD.addClass(html_el, 'add-comment');
821 html_el.innerHTML = '<span class="ui-btn">{0}</span>'.format(label);
822
823 var add = new YAHOO.util.Element(html_el);
824 add.on('click', function(e) {
825 injectInlineForm(tr);
826 });
827 return add;
828 };
829
830 var getLineNo = function(tr) {
831 var line; 716 var line;
832 var o = tr.children[0].id.split('_'); 717 var o = $(tr).children()[0].id.split('_');
833 var n = tr.children[1].id.split('_'); 718 var n = $(tr).children()[1].id.split('_');
834 719
835 if (n.length >= 2) { 720 if (n.length >= 2) {
836 line = n[n.length-1]; 721 line = n[n.length-1];
837 } else if (o.length >= 2) { 722 } else if (o.length >= 2) {
838 line = o[o.length-1]; 723 line = o[o.length-1];
839 } 724 }
840 725
841 return line 726 return line
842 }; 727 };
843 728
844 var placeAddButton = function(target_tr){ 729 var _placeAddButton = function($line_tr){
845 if(!target_tr){ 730 var $tr = $line_tr;
846 return 731 while ($tr.next().hasClass('inline-comments')){
847 } 732 $tr.find('.add-comment').remove();
848 var last_node = target_tr; 733 $tr = $tr.next();
849 //scann 734 }
850 while (1){ 735 $tr.find('.add-comment').remove();
851 var n = last_node.nextElementSibling; 736 var label = TRANSLATION_MAP['Add another comment'];
852 // next element are comments ! 737 var $html_el = $('<div class="add-comment"><span class="ui-btn">{0}</span></div>'.format(label));
853 if($(n).hasClass('inline-comments')){ 738 $html_el.click(function(e) {
854 last_node = n; 739 injectInlineForm($line_tr);
855 //also remove the comment button from previous 740 });
856 var comment_add_buttons = YUD.getElementsByClassName('add-comment',null,last_node); 741 $tr.find('.comment').after($html_el);
857 for(var i=0;i<comment_add_buttons.length;i++){ 742 };
858 var b = comment_add_buttons[i];
859 b.parentNode.removeChild(b);
860 }
861 }
862 else{
863 break;
864 }
865 }
866
867 var add = createInlineAddButton(target_tr);
868 // get the comment div
869 var comment_block = YUD.getElementsByClassName('comment',null,last_node)[0];
870 // attach add button
871 YUD.insertAfter(add,comment_block);
872 }
873 743
874 /** 744 /**
875 * Places the inline comment into the changeset block in proper line position 745 * Places the inline comment into the changeset block in proper line position
876 */ 746 */
877 var placeInline = function(target_container,lineno,html){ 747 var _placeInline = function(target_id, lineno, html){
878 var lineid = "{0}_{1}".format(target_container,lineno); 748 var $td = $("#{0}_{1}".format(target_id, lineno));
879 var target_line = YUD.get(lineid);
880 var comment = new YAHOO.util.Element(tableTr('inline-comments',html))
881 749
882 // check if there are comments already ! 750 // check if there are comments already !
883 var parent = target_line.parentNode; 751 var $line_tr = $td.parent(); // the tr
884 var root_parent = parent; 752 var $after_tr = $line_tr;
885 while (1){ 753 while ($after_tr.next().hasClass('inline-comments')){
886 var n = parent.nextElementSibling; 754 $after_tr = $after_tr.next();
887 // next element are comments !
888 if($(n).hasClass('inline-comments')){
889 parent = n;
890 }
891 else{
892 break;
893 }
894 } 755 }
895 // put in the comment at the bottom 756 // put in the comment at the bottom
896 YUD.insertAfter(comment,parent); 757 $after_tr.after(_table_tr('inline-comments', html));
897 758
898 // scann nodes, and attach add button to last one 759 // scan nodes, and attach add button to last one
899 placeAddButton(root_parent); 760 _placeAddButton($line_tr);
900
901 return target_line;
902 } 761 }
903 762
904 /** 763 /**
905 * make a single inline comment and place it inside 764 * make a single inline comment and place it inside
906 */ 765 */
907 var renderInlineComment = function(json_data){ 766 var _renderInlineComment = function(json_data){
908 try{ 767 var html = json_data['rendered_text'];
909 var html = json_data['rendered_text']; 768 var lineno = json_data['line_no'];
910 var lineno = json_data['line_no']; 769 var target_id = json_data['target_id'];
911 var target_id = json_data['target_id']; 770 _placeInline(target_id, lineno, html);
912 placeInline(target_id, lineno, html);
913 }catch(e){
914 console.log(e);
915 }
916 } 771 }
917 772
918 /** 773 /**
919 * Iterates over all the inlines, and places them inside proper blocks of data 774 * Iterates over all the inlines, and places them inside proper blocks of data
920 */ 775 */
921 var renderInlineComments = function(file_comments){ 776 var renderInlineComments = function(file_comments){
922 for (f in file_comments){ 777 for (f in file_comments){
923 // holding all comments for a FILE 778 // holding all comments for a FILE
924 var box = file_comments[f]; 779 var box = file_comments[f];
925 780
926 var target_id = YUD.getAttribute(box,'target_id'); 781 var target_id = $(box).attr('target_id');
927 // actually comments with line numbers 782 // actual comments with line numbers
928 var comments = box.children; 783 var comments = box.children;
929 for(var i=0; i<comments.length; i++){ 784 for(var i=0; i<comments.length; i++){
930 var data = { 785 var data = {
931 'rendered_text': comments[i].outerHTML, 786 'rendered_text': comments[i].outerHTML,
932 'line_no': YUD.getAttribute(comments[i],'line'), 787 'line_no': $(comments[i]).attr('line'),
933 'target_id': target_id 788 'target_id': target_id
934 } 789 }
935 renderInlineComment(data); 790 _renderInlineComment(data);
936 } 791 }
937 } 792 }
938 } 793 }
939 794
795 /* activate files.html stuff */
940 var fileBrowserListeners = function(current_url, node_list_url, url_base){ 796 var fileBrowserListeners = function(current_url, node_list_url, url_base){
941 var current_url_branch = +"?branch=__BRANCH__"; 797 var current_url_branch = "?branch=__BRANCH__";
942 798
943 $('#stay_at_branch').on('click',function(e){ 799 $('#stay_at_branch').on('click',function(e){
944 if(e.target.checked){ 800 if(e.currentTarget.checked){
945 var uri = current_url_branch; 801 var uri = current_url_branch;
946 uri = uri.replace('__BRANCH__',e.target.value); 802 uri = uri.replace('__BRANCH__',e.currentTarget.value);
947 window.location = uri; 803 window.location = uri;
948 } 804 }
949 else{ 805 else{
950 window.location = current_url; 806 window.location = current_url;
951 } 807 }
952 }) 808 })
953 809
954 var n_filter = YUD.get('node_filter'); 810 var $node_filter = $('#node_filter');
955 var F = YAHOO.namespace('node_filter'); 811
956 812 var filterTimeout = null;
957 F.filterTimeout = null;
958 var nodes = null; 813 var nodes = null;
959 814
960 F.initFilter = function(){ 815 var initFilter = function(){
961 $('#node_filter_box_loading').css('display',''); 816 $('#node_filter_box_loading').show();
962 $('#search_activate_id').css('display','none'); 817 $('#search_activate_id').hide();
963 $('#add_node_id').css('display','none'); 818 $('#add_node_id').hide();
964 YUC.initHeader('X-PARTIAL-XHR',true); 819 YUC.initHeader('X-PARTIAL-XHR',true);
965 YUC.asyncRequest('GET', node_list_url, { 820 YUC.asyncRequest('GET', node_list_url, {
966 success:function(o){ 821 success:function(o){
967 nodes = JSON.parse(o.responseText).nodes; 822 nodes = JSON.parse(o.responseText).nodes;
968 $('#node_filter_box_loading').css('display','none'); 823 $('#node_filter_box_loading').hide();
969 $('#node_filter_box').css('display',''); 824 $('#node_filter_box').show();
970 n_filter.focus(); 825 $node_filter.focus();
971 if(YUD.hasClass(n_filter,'init')){ 826 if($node_filter.hasClass('init')){
972 n_filter.value = ''; 827 $node_filter.val('');
973 YUD.removeClass(n_filter,'init'); 828 $node_filter.removeClass('init');
974 } 829 }
975 }, 830 },
976 failure:function(o){ 831 failure:function(o){
977 console.log('failed to load'); 832 console.log('failed to load');
978 } 833 }
979 },null); 834 },null);
980 } 835 }
981 836
982 F.updateFilter = function(e) { 837 var updateFilter = function(e) {
983 return function(){ 838 return function(){
984 // Reset timeout 839 // Reset timeout
985 F.filterTimeout = null; 840 filterTimeout = null;
986 var query = e.target.value.toLowerCase(); 841 var query = e.currentTarget.value.toLowerCase();
987 var match = []; 842 var match = [];
988 var matches = 0; 843 var matches = 0;
989 var matches_max = 20; 844 var matches_max = 20;
990 if (query != ""){ 845 if (query != ""){
991 for(var i=0;i<nodes.length;i++){ 846 for(var i=0;i<nodes.length;i++){
1009 match.push('<tr><td>{0}</td><td colspan="5"></td></tr>'.format(_TM['Search truncated'])); 864 match.push('<tr><td>{0}</td><td colspan="5"></td></tr>'.format(_TM['Search truncated']));
1010 } 865 }
1011 } 866 }
1012 } 867 }
1013 if(query != ""){ 868 if(query != ""){
1014 $('#tbody').css('display','none'); 869 $('#tbody').hide();
1015 $('#tbody_filtered').css('display',''); 870 $('#tbody_filtered').show();
1016 871
1017 if (match.length==0){ 872 if (match.length==0){
1018 match.push('<tr><td>{0}</td><td colspan="5"></td></tr>'.format(_TM['No matching files'])); 873 match.push('<tr><td>{0}</td><td colspan="5"></td></tr>'.format(_TM['No matching files']));
1019 } 874 }
1020 875
1021 YUD.get('tbody_filtered').innerHTML = match.join(""); 876 $('#tbody_filtered').html(match.join(""));
1022 } 877 }
1023 else{ 878 else{
1024 $('#tbody').css('display',''); 879 $('#tbody').show();
1025 $('#tbody_filtered').css('display','none'); 880 $('#tbody_filtered').hide();
1026 } 881 }
1027 } 882 }
1028 }; 883 };
1029 884
1030 YUE.on(YUD.get('filter_activate'),'click',function(){ 885 $('#filter_activate').click(function(){
1031 F.initFilter(); 886 initFilter();
1032 })
1033 YUE.on(n_filter,'click',function(){
1034 if(YUD.hasClass(n_filter,'init')){
1035 n_filter.value = '';
1036 YUD.removeClass(n_filter,'init');
1037 }
1038 }); 887 });
1039 YUE.on(n_filter,'keyup',function(e){ 888 $node_filter.click(function(){
1040 clearTimeout(F.filterTimeout); 889 if($node_filter.hasClass('init')){
1041 F.filterTimeout = setTimeout(F.updateFilter(e),600); 890 $node_filter.val('');
891 $node_filter.removeClass('init');
892 }
1042 }); 893 });
1043 }; 894 $node_filter.keyup(function(e){
1044 895 clearTimeout(filterTimeout);
1045 896 filterTimeout = setTimeout(updateFilter(e),600);
1046 var initCodeMirror = function(textAreadId,resetUrl){ 897 });
1047 var myCodeMirror = CodeMirror.fromTextArea(YUD.get(textAreadId),{ 898 };
1048 mode: "null", 899
1049 lineNumbers:true, 900
901 var initCodeMirror = function(textarea_id, resetUrl){
902 var myCodeMirror = CodeMirror.fromTextArea($('#' + textarea_id)[0], {
903 mode: "null",
904 lineNumbers: true,
1050 indentUnit: 4 905 indentUnit: 4
1051 }); 906 });
1052 YUE.on('reset','click',function(e){ 907 $('#reset').click(function(e){
1053 window.location=resetUrl 908 window.location=resetUrl;
1054 }); 909 });
1055 910
1056 YUE.on('file_enable','click',function(){ 911 $('#file_enable').click(function(){
1057 $('#editor_container').css('display',''); 912 $('#editor_container').show();
1058 $('#upload_file_container').css('display','none'); 913 $('#upload_file_container').hide();
1059 $('#filename_container').css('display',''); 914 $('#filename_container').show();
1060 }); 915 });
1061 916
1062 YUE.on('upload_file_enable','click',function(){ 917 $('#upload_file_enable').click(function(){
1063 $('#editor_container').css('display','none'); 918 $('#editor_container').hide();
1064 $('#upload_file_container').css('display',''); 919 $('#upload_file_container').show();
1065 $('#filename_container').css('display','none'); 920 $('#filename_container').hide();
1066 }); 921 });
1067 922
1068 return myCodeMirror 923 return myCodeMirror
1069 }; 924 };
1070 925
1072 codeMirrorInstance.setOption("mode", mode); 927 codeMirrorInstance.setOption("mode", mode);
1073 CodeMirror.autoLoadMode(codeMirrorInstance, mode); 928 CodeMirror.autoLoadMode(codeMirrorInstance, mode);
1074 } 929 }
1075 930
1076 931
1077 var getIdentNode = function(n){ 932 var _getIdentNode = function(n){
1078 //iterate thru nodes untill matched interesting node ! 933 //iterate thrugh nodes until matching interesting node
1079 934
1080 if (typeof n == 'undefined'){ 935 if (typeof n == 'undefined'){
1081 return -1 936 return -1
1082 } 937 }
1083 938
1084 if(typeof n.id != "undefined" && n.id.match('L[0-9]+')){ 939 if(typeof n.id != "undefined" && n.id.match('L[0-9]+')){
1085 return n 940 return n
1086 } 941 }
1087 else{ 942 else{
1088 return getIdentNode(n.parentNode); 943 return _getIdentNode(n.parentNode);
1089 } 944 }
1090 }; 945 };
1091 946
947 /* generate links for multi line selects that can be shown by files.html page_highlights.
948 * This is a mouseup handler for hlcode from CodeHtmlFormatter and pygmentize */
1092 var getSelectionLink = function(e) { 949 var getSelectionLink = function(e) {
1093 //get selection from start/to nodes 950 //get selection from start/to nodes
1094 if (typeof window.getSelection != "undefined") { 951 if (typeof window.getSelection != "undefined") {
1095 s = window.getSelection(); 952 s = window.getSelection();
1096 953
1097 from = getIdentNode(s.anchorNode); 954 from = _getIdentNode(s.anchorNode);
1098 till = getIdentNode(s.focusNode); 955 till = _getIdentNode(s.focusNode);
1099 956
1100 f_int = parseInt(from.id.replace('L','')); 957 f_int = parseInt(from.id.replace('L',''));
1101 t_int = parseInt(till.id.replace('L','')); 958 t_int = parseInt(till.id.replace('L',''));
1102 959
1103 if (f_int > t_int){ 960 var yoffset = 35;
961 var ranges = [parseInt(from.id.replace('L','')), parseInt(till.id.replace('L',''))];
962 if (ranges[0] > ranges[1]){
1104 //highlight from bottom 963 //highlight from bottom
1105 offset = -35; 964 yoffset = -yoffset;
1106 ranges = [t_int,f_int]; 965 ranges = [ranges[1], ranges[0]];
1107 966 }
1108 } 967 var $hl_div = $('div#linktt');
1109 else{
1110 //highligth from top
1111 offset = 35;
1112 ranges = [f_int,t_int];
1113 }
1114 // if we select more than 2 lines 968 // if we select more than 2 lines
1115 if (ranges[0] != ranges[1]){ 969 if (ranges[0] != ranges[1]){
1116 if(YUD.get('linktt') == null){ 970 if ($hl_div.length) {
1117 hl_div = document.createElement('div'); 971 $hl_div.html('');
1118 hl_div.id = 'linktt'; 972 } else {
1119 } 973 $hl_div = $('<div id="linktt" class="hl-tip-box">');
1120 hl_div.innerHTML = ''; 974 $('body').prepend($hl_div);
1121 975 }
1122 anchor = '#L'+ranges[0]+'-'+ranges[1]; 976
1123 var link = document.createElement('a'); 977 $hl_div.append($('<a>').html(_TM['Selection link']).attr('href', location.href.substring(0, location.href.indexOf('#')) + '#L' + ranges[0] + '-'+ranges[1]));
1124 link.href = location.href.substring(0,location.href.indexOf('#'))+anchor; 978 xy = $(till).offset();
1125 link.innerHTML = _TM['Selection link']; 979 $hl_div.css('top', (xy.top + yoffset) + 'px').css('left', xy.left + 'px');
1126 hl_div.appendChild(link); 980 $hl_div.show();
1127 YUD.get('body').appendChild(hl_div);
1128
1129 xy = YUD.getXY(till.id);
1130
1131 YUD.addClass('linktt', 'hl-tip-box');
1132 $('#linktt').css('top',xy[1]+offset+'px');
1133 $('#linktt').css('left',xy[0]+'px');
1134 $('#linktt').css('visibility','visible');
1135
1136 } 981 }
1137 else{ 982 else{
1138 $('#linktt').css('visibility','hidden'); 983 $hl_div.hide();
1139 } 984 }
1140 } 985 }
1141 }; 986 };
1142 987
1143 var deleteNotification = function(url, notification_id,callbacks){ 988 var deleteNotification = function(url, notification_id, callbacks){
1144 var callback = { 989 var callback = {
1145 success:function(o){ 990 success:function(o){
1146 var obj = YUD.get(String("notification_"+notification_id)); 991 $("#notification_"+notification_id).remove();
1147 if(obj.parentNode !== undefined){
1148 obj.parentNode.removeChild(obj);
1149 }
1150 _run_callbacks(callbacks); 992 _run_callbacks(callbacks);
1151 }, 993 },
1152 failure:function(o){ 994 failure:function(o){
1153 alert("error"); 995 alert("error");
1154 }, 996 },
1157 var sUrl = url.replace('__NOTIFICATION_ID__',notification_id); 999 var sUrl = url.replace('__NOTIFICATION_ID__',notification_id);
1158 var request = YAHOO.util.Connect.asyncRequest('POST', sUrl, 1000 var request = YAHOO.util.Connect.asyncRequest('POST', sUrl,
1159 callback, postData); 1001 callback, postData);
1160 }; 1002 };
1161 1003
1162 var readNotification = function(url, notification_id,callbacks){ 1004 var readNotification = function(url, notification_id, callbacks){
1163 var callback = { 1005 var callback = {
1164 success:function(o){ 1006 success:function(o){
1165 var obj = YUD.get(String("notification_"+notification_id)); 1007 var $obj = $("#notification_"+notification_id);
1166 YUD.removeClass(obj, 'unread'); 1008 $obj.removeClass('unread');
1167 var r_button = YUD.getElementsByClassName('read-notification',null,obj.children[0])[0]; 1009 $obj.find('.read-notification').remove();
1168
1169 if(r_button.parentNode !== undefined){
1170 r_button.parentNode.removeChild(r_button);
1171 }
1172 _run_callbacks(callbacks); 1010 _run_callbacks(callbacks);
1173 }, 1011 },
1174 failure:function(o){ 1012 failure:function(o){
1175 alert("error"); 1013 alert("error");
1176 }, 1014 },
1181 callback, postData); 1019 callback, postData);
1182 }; 1020 };
1183 1021
1184 /** MEMBERS AUTOCOMPLETE WIDGET **/ 1022 /** MEMBERS AUTOCOMPLETE WIDGET **/
1185 1023
1186 var MembersAutoComplete = function (divid, cont, users_list, groups_list) { 1024 var _MembersAutoComplete = function (divid, cont, users_list, groups_list) {
1187 var myUsers = users_list; 1025 var myUsers = users_list;
1188 var myGroups = groups_list; 1026 var myGroups = groups_list;
1189 1027
1190 // Define a custom search function for the DataSource of users 1028 // Define a custom search function for the DataSource of users
1191 var matchUsers = function (sQuery) { 1029 var matchUsers = function (sQuery) {
1336 var oData = aArgs[2]; // object literal of selected item's result data 1174 var oData = aArgs[2]; // object literal of selected item's result data
1337 //fill the autocomplete with value 1175 //fill the autocomplete with value
1338 if (oData.nname != undefined) { 1176 if (oData.nname != undefined) {
1339 //users 1177 //users
1340 myAC.getInputEl().value = oData.nname; 1178 myAC.getInputEl().value = oData.nname;
1341 YUD.get('perm_new_member_type_'+nextId).value = 'user'; 1179 $('#perm_new_member_type_'+nextId).val('user');
1342 } else { 1180 } else {
1343 //groups 1181 //groups
1344 myAC.getInputEl().value = oData.grname; 1182 myAC.getInputEl().value = oData.grname;
1345 YUD.get('perm_new_member_type_'+nextId).value = 'users_group'; 1183 $('#perm_new_member_type_'+nextId).val('users_group');
1346 } 1184 }
1347 }; 1185 };
1348 1186
1349 membersAC.itemSelectEvent.subscribe(myHandler); 1187 membersAC.itemSelectEvent.subscribe(myHandler);
1350 if(ownerAC.itemSelectEvent){ 1188 if(ownerAC.itemSelectEvent){
1483 var chunks = myAC.dataSource.chunks 1321 var chunks = myAC.dataSource.chunks
1484 // replace middle chunk(the search term) with actuall match 1322 // replace middle chunk(the search term) with actuall match
1485 chunks[1] = chunks[1].replace('@'+myAC.dataSource.mentionQuery, 1323 chunks[1] = chunks[1].replace('@'+myAC.dataSource.mentionQuery,
1486 '@'+oData.nname+' '); 1324 '@'+oData.nname+' ');
1487 myAC.getInputEl().value = chunks.join('') 1325 myAC.getInputEl().value = chunks.join('')
1488 YUD.get(myAC.getInputEl()).focus(); // Y U NO WORK !? 1326 myAC.getInputEl().focus(); // Y U NO WORK !?
1489 } else { 1327 } else {
1490 //groups 1328 //groups
1491 myAC.getInputEl().value = oData.grname; 1329 myAC.getInputEl().value = oData.grname;
1492 YUD.get('perm_new_member_type').value = 'users_group'; 1330 $('#perm_new_member_type').val('users_group');
1493 } 1331 }
1494 }); 1332 });
1495 } 1333 }
1496 1334
1497 // in this keybuffer we will gather current value of search ! 1335 // in this keybuffer we will gather current value of search !
1547 ownerAC: ownerAC, 1385 ownerAC: ownerAC,
1548 }; 1386 };
1549 } 1387 }
1550 1388
1551 var addReviewMember = function(id,fname,lname,nname,gravatar_link){ 1389 var addReviewMember = function(id,fname,lname,nname,gravatar_link){
1552 var members = YUD.get('review_members');
1553 var tmpl = '<li id="reviewer_{2}">'+ 1390 var tmpl = '<li id="reviewer_{2}">'+
1554 '<div class="reviewers_member">'+ 1391 '<div class="reviewers_member">'+
1555 '<div class="gravatar"><img alt="gravatar" src="{0}"/> </div>'+ 1392 '<div class="gravatar"><img alt="gravatar" src="{0}"/> </div>'+
1556 '<div style="float:left">{1}</div>'+ 1393 '<div style="float:left">{1}</div>'+
1557 '<input type="hidden" value="{2}" name="review_members" />'+ 1394 '<input type="hidden" value="{2}" name="review_members" />'+
1560 '</li>' ; 1397 '</li>' ;
1561 var displayname = "{0} {1} ({2})".format(fname,lname,nname); 1398 var displayname = "{0} {1} ({2})".format(fname,lname,nname);
1562 var element = tmpl.format(gravatar_link,displayname,id); 1399 var element = tmpl.format(gravatar_link,displayname,id);
1563 // check if we don't have this ID already in 1400 // check if we don't have this ID already in
1564 var ids = []; 1401 var ids = [];
1565 var _els = YUQ('#review_members li'); 1402 $('#review_members').find('li').each(function() {
1566 for (el in _els){ 1403 ids.push(this.id);
1567 ids.push(_els[el].id) 1404 });
1568 }
1569 if(ids.indexOf('reviewer_'+id) == -1){ 1405 if(ids.indexOf('reviewer_'+id) == -1){
1570 //only add if it's not there 1406 //only add if it's not there
1571 members.innerHTML += element; 1407 $('#review_members').append(element);
1572 } 1408 }
1573 } 1409 }
1574 1410
1575 var removeReviewMember = function(reviewer_id, repo_name, pull_request_id){ 1411 var removeReviewMember = function(reviewer_id, repo_name, pull_request_id){
1576 var el = YUD.get('reviewer_{0}'.format(reviewer_id)); 1412 $('#reviewer_{0}'.format(reviewer_id)).remove();
1577 if (el.parentNode !== undefined){ 1413 }
1578 el.parentNode.removeChild(el); 1414
1579 } 1415 /* handle "Save Changes" of addReviewMember and removeReviewMember on PR */
1580 }
1581
1582 var updateReviewers = function(reviewers_ids, repo_name, pull_request_id){ 1416 var updateReviewers = function(reviewers_ids, repo_name, pull_request_id){
1583 if (reviewers_ids === undefined){ 1417 if (reviewers_ids === undefined){
1584 var reviewers_ids = []; 1418 var reviewers_ids = [];
1585 var ids = YUQ('#review_members input'); 1419 $('#review_members').find('input').each(function(){
1586 for(var i=0; i<ids.length;i++){ 1420 reviewers_ids.push(this.value);
1587 var id = ids[i].value 1421 });
1588 reviewers_ids.push(id);
1589 }
1590 } 1422 }
1591 var url = pyroutes.url('pullrequest_update', {"repo_name":repo_name, 1423 var url = pyroutes.url('pullrequest_update', {"repo_name":repo_name,
1592 "pull_request_id": pull_request_id}); 1424 "pull_request_id": pull_request_id});
1593 var postData = {'_method':'put', 1425 var postData = {'_method':'put',
1594 'reviewers_ids': reviewers_ids}; 1426 'reviewers_ids': reviewers_ids};
1596 window.location.reload(); 1428 window.location.reload();
1597 } 1429 }
1598 ajaxPOST(url,postData,success); 1430 ajaxPOST(url,postData,success);
1599 } 1431 }
1600 1432
1433 /* activate auto completion of users and groups ... but only used for users as PR reviewers */
1601 var PullRequestAutoComplete = function (divid, cont, users_list, groups_list) { 1434 var PullRequestAutoComplete = function (divid, cont, users_list, groups_list) {
1602 var myUsers = users_list; 1435 var myUsers = users_list;
1603 var myGroups = groups_list; 1436 var myGroups = groups_list;
1604 1437
1605 // Define a custom search function for the DataSource of users 1438 // Define a custom search function for the DataSource of users
1729 var myAC = aArgs[0]; // reference back to the AC instance 1562 var myAC = aArgs[0]; // reference back to the AC instance
1730 var elLI = aArgs[1]; // reference to the selected LI element 1563 var elLI = aArgs[1]; // reference to the selected LI element
1731 var oData = aArgs[2]; // object literal of selected item's result data 1564 var oData = aArgs[2]; // object literal of selected item's result data
1732 1565
1733 //fill the autocomplete with value 1566 //fill the autocomplete with value
1734
1735 if (oData.nname != undefined) { 1567 if (oData.nname != undefined) {
1736 addReviewMember(oData.id, oData.fname, oData.lname, oData.nname, 1568 addReviewMember(oData.id, oData.fname, oData.lname, oData.nname,
1737 oData.gravatar_lnk); 1569 oData.gravatar_lnk);
1738 myAC.dataSource.cache.push(oData.id); 1570 myAC.dataSource.cache.push(oData.id);
1739 YUD.get('user').value = '' 1571 $('#user').val('');
1740 } 1572 }
1741 }); 1573 });
1742 } 1574 }
1743 return {
1744 ownerDS: ownerDS,
1745 reviewerAC: reviewerAC,
1746 };
1747 } 1575 }
1748 1576
1749 /** 1577 /**
1750 * QUICK REPO MENU 1578 * Activate .quick_repo_menu
1751 */ 1579 */
1752 var quick_repo_menu = function(){ 1580 var quick_repo_menu = function(){
1753 YUE.on(YUQ('.quick_repo_menu'),'mouseenter',function(e){ 1581 $(".quick_repo_menu").mouseenter(function(e) {
1754 var menu = e.currentTarget.firstElementChild.firstElementChild; 1582 var $menu = $(e.currentTarget).children().first().children().first();
1755 if(YUD.hasClass(menu,'hidden')){ 1583 if($menu.hasClass('hidden')){
1756 YUD.replaceClass(e.currentTarget,'hidden', 'active'); 1584 $menu.removeClass('hidden').addClass('active');
1757 YUD.replaceClass(menu, 'hidden', 'active'); 1585 $(e.currentTarget).removeClass('hidden').addClass('active');
1758 } 1586 }
1759 }) 1587 })
1760 YUE.on(YUQ('.quick_repo_menu'),'mouseleave',function(e){ 1588 $(".quick_repo_menu").mouseleave(function(e) {
1761 var menu = e.currentTarget.firstElementChild.firstElementChild; 1589 var $menu = $(e.currentTarget).children().first().children().first();
1762 if(YUD.hasClass(menu,'active')){ 1590 if($menu.hasClass('active')){
1763 YUD.replaceClass(e.currentTarget, 'active', 'hidden'); 1591 $menu.removeClass('active').addClass('hidden');
1764 YUD.replaceClass(menu, 'active', 'hidden'); 1592 $(e.currentTarget).removeClass('active').addClass('hidden');
1765 } 1593 }
1766 }) 1594 })
1767 }; 1595 };
1768 1596
1769 1597
1789 return parseInt(out); 1617 return parseInt(out);
1790 } 1618 }
1791 } 1619 }
1792 1620
1793 var get_date = function(node){ 1621 var get_date = function(node){
1794 var date_ = YUD.getAttribute(node.firstElementChild,'date'); 1622 return $(node.firstElementChild).attr('date');
1795 return date_
1796 } 1623 }
1797 1624
1798 var revisionSort = function(a, b, desc, field) { 1625 var revisionSort = function(a, b, desc, field) {
1799 var a_ = fromHTML(a.getData(field)); 1626 var a_ = get_rev(fromHTML(a.getData(field)));
1800 var b_ = fromHTML(b.getData(field)); 1627 var b_ = get_rev(fromHTML(b.getData(field)));
1801 1628
1802 // extract revisions from string nodes 1629 return YAHOO.util.Sort.compare(a_, b_, desc);
1803 a_ = get_rev(a_)
1804 b_ = get_rev(b_)
1805
1806 var comp = YAHOO.util.Sort.compare;
1807 var compState = comp(a_, b_, desc);
1808 return compState;
1809 }; 1630 };
1810 1631
1811 var ageSort = function(a, b, desc, field) { 1632 var ageSort = function(a, b, desc, field) {
1812 var a_ = fromHTML(a.getData(field)); 1633 // data is like: <span class="tooltip" date="2014-06-04 18:18:55.325474" title="Wed, 04 Jun 2014 18:18:55">1 day and 23 hours ago</span>
1813 var b_ = fromHTML(b.getData(field)); 1634 var a_ = $(a.getData(field)).attr('date');
1814 1635 var b_ = $(b.getData(field)).attr('date');
1815 // extract name from table 1636
1816 a_ = get_date(a_) 1637 return YAHOO.util.Sort.compare(a_, b_, desc);
1817 b_ = get_date(b_)
1818
1819 var comp = YAHOO.util.Sort.compare;
1820 var compState = comp(a_, b_, desc);
1821 return compState;
1822 }; 1638 };
1823 1639
1824 var lastLoginSort = function(a, b, desc, field) { 1640 var lastLoginSort = function(a, b, desc, field) {
1825 var a_ = a.getData('last_login_raw') || 0; 1641 var a_ = a.getData('last_login_raw') || 0;
1826 var b_ = b.getData('last_login_raw') || 0; 1642 var b_ = b.getData('last_login_raw') || 0;
1827 1643
1828 var comp = YAHOO.util.Sort.compare; 1644 return YAHOO.util.Sort.compare(a_, b_, desc);
1829 var compState = comp(a_, b_, desc);
1830 return compState;
1831 }; 1645 };
1832 1646
1833 var nameSort = function(a, b, desc, field) { 1647 var nameSort = function(a, b, desc, field) {
1834 var a_ = a.getData('raw_name') || 0; 1648 var a_ = a.getData('raw_name') || 0;
1835 var b_ = b.getData('raw_name') || 0; 1649 var b_ = b.getData('raw_name') || 0;
1836 1650
1837 var comp = YAHOO.util.Sort.compare; 1651 return YAHOO.util.Sort.compare(a_, b_, desc);
1838 var compState = comp(a_, b_, desc);
1839 return compState;
1840 }; 1652 };
1841 1653
1842 var dateSort = function(a, b, desc, field) { 1654 var dateSort = function(a, b, desc, field) {
1843 var a_ = fromHTML(a.getData(field)); 1655 var a_ = get_date(fromHTML(a.getData(field)));
1844 var b_ = fromHTML(b.getData(field)); 1656 var b_ = get_date(fromHTML(b.getData(field)));
1845 1657
1846 // extract name from table 1658 return YAHOO.util.Sort.compare(a_, b_, desc);
1847 a_ = get_date(a_)
1848 b_ = get_date(b_)
1849
1850 var comp = YAHOO.util.Sort.compare;
1851 var compState = comp(a_, b_, desc);
1852 return compState;
1853 }; 1659 };
1854 1660
1855 var addPermAction = function(_html, users_list, groups_list){ 1661 var addPermAction = function(_html, users_list, groups_list){
1856 var elmts = YUD.getElementsByClassName('last_new_member'); 1662 var $last_node = $('.last_new_member').last(); // empty tr between last and add
1857 var last_node = elmts[elmts.length-1]; 1663 var next_id = $('.new_members').length;
1858 if (last_node){ 1664 $last_node.before($('<tr class="new_members">').append(_html.format(next_id)));
1859 var next_id = (YUD.getElementsByClassName('new_members')).length; 1665 _MembersAutoComplete("perm_new_member_name_"+next_id,
1860 _html = _html.format(next_id); 1666 "perm_container_"+next_id, users_list, groups_list);
1861 last_node.innerHTML = _html;
1862 YUD.setStyle(last_node, 'display', '');
1863 YUD.removeClass(last_node, 'last_new_member');
1864 MembersAutoComplete("perm_new_member_name_"+next_id,
1865 "perm_container_"+next_id, users_list, groups_list);
1866 //create new last NODE
1867 var el = document.createElement('tr');
1868 el.id = 'add_perm_input';
1869 YUD.addClass(el,'last_new_member');
1870 YUD.addClass(el,'new_members');
1871 YUD.insertAfter(el, last_node);
1872 }
1873 } 1667 }
1874 1668
1875 function ajaxActionRevokePermission(url, obj_id, obj_type, field_id, extra_data) { 1669 function ajaxActionRevokePermission(url, obj_id, obj_type, field_id, extra_data) {
1876 var callback = { 1670 var callback = {
1877 success: function (o) { 1671 success: function (o) {
1878 var tr = YUD.get(String(field_id)); 1672 $('#' + field_id).remove();
1879 tr.parentNode.removeChild(tr);
1880 }, 1673 },
1881 failure: function (o) { 1674 failure: function (o) {
1882 alert(_TM['Failed to remoke permission'] + ": " + o.status); 1675 alert(_TM['Failed to remoke permission'] + ": " + o.status);
1883 }, 1676 },
1884 }; 1677 };
1900 query_params['user_group_id'] = obj_id; 1693 query_params['user_group_id'] = obj_id;
1901 query_params['obj_type'] = 'user_group'; 1694 query_params['obj_type'] = 'user_group';
1902 } 1695 }
1903 1696
1904 var request = YAHOO.util.Connect.asyncRequest('POST', url, callback, 1697 var request = YAHOO.util.Connect.asyncRequest('POST', url, callback,
1905 toQueryString(query_params)); 1698 _toQueryString(query_params));
1906 }; 1699 };
1907 1700
1908 /* Multi selectors */ 1701 /* Multi selectors */
1909 1702
1910 var MultiSelectWidget = function(selected_id, available_id, form_id){ 1703 var MultiSelectWidget = function(selected_id, available_id, form_id){
1911 //definition of containers ID's 1704 var $availableselect = $('#' + available_id);
1912 var selected_container = selected_id; 1705 var $selectedselect = $('#' + selected_id);
1913 var available_container = available_id; 1706
1914 1707 //fill available only with those not in selected
1915 //temp container for selected storage. 1708 var $selectedoptions = $selectedselect.children('option');
1916 var cache = new Array(); 1709 $availableselect.children('option').filter(function(i, e){
1917 var av_cache = new Array(); 1710 for(var j = 0, node; node = $selectedoptions[j]; j++){
1918 var c = YUD.get(selected_container); 1711 if(node.value == e.value){
1919 var ac = YUD.get(available_container); 1712 return true;
1920 1713 }
1921 //get only selected options for further fullfilment 1714 }
1922 for(var i = 0;node =c.options[i];i++){ 1715 return false;
1923 if(node.selected){ 1716 }).remove();
1924 //push selected to my temp storage left overs :) 1717
1925 cache.push(node); 1718 $('#add_element').click(function(e){
1926 } 1719 $selectedselect.append($availableselect.children('option:selected'));
1927 }
1928
1929 //get all available options to cache
1930 for(var i = 0;node =ac.options[i];i++){
1931 //push selected to my temp storage left overs :)
1932 av_cache.push(node);
1933 }
1934
1935 //fill available only with those not in chosen
1936 ac.options.length=0;
1937 tmp_cache = new Array();
1938
1939 for(var i = 0;node = av_cache[i];i++){
1940 var add = true;
1941 for(var i2 = 0;node_2 = cache[i2];i2++){
1942 if(node.value == node_2.value){
1943 add=false;
1944 break;
1945 }
1946 }
1947 if(add){
1948 tmp_cache.push(new Option(node.text, node.value, false, false));
1949 }
1950 }
1951
1952 for(var i = 0;node = tmp_cache[i];i++){
1953 ac.options[i] = node;
1954 }
1955
1956 function prompts_action_callback(e){
1957
1958 var chosen = YUD.get(selected_container);
1959 var available = YUD.get(available_container);
1960
1961 //get checked and unchecked options from field
1962 function get_checked(from_field){
1963 //temp container for storage.
1964 var sel_cache = new Array();
1965 var oth_cache = new Array();
1966
1967 for(var i = 0;node = from_field.options[i];i++){
1968 if(node.selected){
1969 //push selected fields :)
1970 sel_cache.push(node);
1971 }
1972 else{
1973 oth_cache.push(node)
1974 }
1975 }
1976
1977 return [sel_cache,oth_cache]
1978 }
1979
1980 //fill the field with given options
1981 function fill_with(field,options){
1982 //clear firtst
1983 field.options.length=0;
1984 for(var i = 0;node = options[i];i++){
1985 field.options[i]=new Option(node.text, node.value,
1986 false, false);
1987 }
1988
1989 }
1990 //adds to current field
1991 function add_to(field,options){
1992 for(var i = 0;node = options[i];i++){
1993 field.appendChild(new Option(node.text, node.value,
1994 false, false));
1995 }
1996 }
1997
1998 // add action
1999 if (this.id=='add_element'){
2000 var c = get_checked(available);
2001 add_to(chosen,c[0]);
2002 fill_with(available,c[1]);
2003 }
2004 // remove action
2005 if (this.id=='remove_element'){
2006 var c = get_checked(chosen);
2007 add_to(available,c[0]);
2008 fill_with(chosen,c[1]);
2009 }
2010 // add all elements
2011 if(this.id=='add_all_elements'){
2012 for(var i=0; node = available.options[i];i++){
2013 chosen.appendChild(new Option(node.text,
2014 node.value, false, false));
2015 }
2016 available.options.length = 0;
2017 }
2018 //remove all elements
2019 if(this.id=='remove_all_elements'){
2020 for(var i=0; node = chosen.options[i];i++){
2021 available.appendChild(new Option(node.text,
2022 node.value, false, false));
2023 }
2024 chosen.options.length = 0;
2025 }
2026
2027 }
2028
2029 YUE.addListener(['add_element','remove_element',
2030 'add_all_elements','remove_all_elements'],'click',
2031 prompts_action_callback)
2032 if (form_id !== undefined) {
2033 YUE.addListener(form_id,'submit',function(){
2034 var chosen = YUD.get(selected_container);
2035 for (var i = 0; i < chosen.options.length; i++) {
2036 chosen.options[i].selected = 'selected';
2037 }
2038 }); 1720 });
2039 } 1721 $('#remove_element').click(function(e){
1722 $availableselect.append($selectedselect.children('option:selected'));
1723 });
1724 $('#add_all_elements').click(function(e){
1725 $selectedselect.append($availableselect.children('option'));
1726 });
1727 $('#remove_all_elements').click(function(e){
1728 $availableselect.append($selectedselect.children('option'));
1729 });
1730
1731 $('#'+form_id).submit(function(){
1732 $selectedselect.children('option').each(function(i, e){
1733 e.selected = 'selected';
1734 });
1735 });
2040 } 1736 }
2041 1737
2042 // custom paginator 1738 // custom paginator
2043 var YUI_paginator = function(links_per_page, containers){ 1739 var YUI_paginator = function(links_per_page, containers){
2044 1740
2106 label = p.get('firstPageLinkLabel'), 1802 label = p.get('firstPageLinkLabel'),
2107 title = p.get('firstPageLinkTitle'); 1803 title = p.get('firstPageLinkTitle');
2108 1804
2109 this.link = document.createElement('a'); 1805 this.link = document.createElement('a');
2110 this.span = document.createElement('span'); 1806 this.span = document.createElement('span');
2111 YUD.setStyle(this.span, 'display', 'none'); 1807 $(this.span).hide();
2112 1808
2113 var _pos = this.getPos(p.getCurrentPage(), p.getTotalPages(), 5); 1809 var _pos = this.getPos(p.getCurrentPage(), p.getTotalPages(), 5);
2114 this.leftmost_page = _pos[0]; 1810 this.leftmost_page = _pos[0];
2115 this.rightmost_page = _pos[2]; 1811 this.rightmost_page = _pos[2];
2116 1812
2117 setId(this.link, id_base + '-first-link'); 1813 setId(this.link, id_base + '-first-link');
2118 this.link.href = '#'; 1814 this.link.href = '#';
2119 this.link.className = c; 1815 this.link.className = c;
2120 this.link.innerHTML = label; 1816 this.link.innerHTML = label;
2121 this.link.title = title; 1817 this.link.title = title;
2122 YAHOO.util.Event.on(this.link,'click',this.onClick,this,true); 1818 YUE.on(this.link,'click',this.onClick,this,true);
2123 1819
2124 setId(this.span, id_base + '-first-span'); 1820 setId(this.span, id_base + '-first-span');
2125 this.span.className = c; 1821 this.span.className = c;
2126 this.span.innerHTML = label; 1822 this.span.innerHTML = label;
2127 1823
2150 this.current = this.span; 1846 this.current = this.span;
2151 } 1847 }
2152 } 1848 }
2153 }, 1849 },
2154 destroy : function () { 1850 destroy : function () {
2155 YAHOO.util.Event.purgeElement(this.link); 1851 YUE.purgeElement(this.link);
2156 this.current.parentNode.removeChild(this.current); 1852 this.current.parentNode.removeChild(this.current);
2157 this.link = this.span = null; 1853 this.link = this.span = null;
2158 }, 1854 },
2159 onClick : function (e) { 1855 onClick : function (e) {
2160 YAHOO.util.Event.stopEvent(e); 1856 YUE.stopEvent(e);
2161 this.paginator.setPage(1); 1857 this.paginator.setPage(1);
2162 } 1858 }
2163 }; 1859 };
2164 1860
2165 })(); 1861 })();
2235 this.leftmost_page = _pos[0]; 1931 this.leftmost_page = _pos[0];
2236 this.rightmost_page = _pos[2]; 1932 this.rightmost_page = _pos[2];
2237 1933
2238 this.link = document.createElement('a'); 1934 this.link = document.createElement('a');
2239 this.span = document.createElement('span'); 1935 this.span = document.createElement('span');
2240 YUD.setStyle(this.span, 'display', 'none'); 1936 $(this.span).hide();
2241 1937
2242 this.na = this.span.cloneNode(false); 1938 this.na = this.span.cloneNode(false);
2243 1939
2244 setId(this.link, id_base + '-last-link'); 1940 setId(this.link, id_base + '-last-link');
2245 this.link.href = '#'; 1941 this.link.href = '#';
2246 this.link.className = c; 1942 this.link.className = c;
2247 this.link.innerHTML = label; 1943 this.link.innerHTML = label;
2248 this.link.title = title; 1944 this.link.title = title;
2249 YAHOO.util.Event.on(this.link,'click',this.onClick,this,true); 1945 YUE.on(this.link,'click',this.onClick,this,true);
2250 1946
2251 setId(this.span, id_base + '-last-span'); 1947 setId(this.span, id_base + '-last-span');
2252 this.span.className = c; 1948 this.span.className = c;
2253 this.span.innerHTML = label; 1949 this.span.innerHTML = label;
2254 1950
2293 } 1989 }
2294 this.current.innerHTML = this.paginator.getTotalPages(); 1990 this.current.innerHTML = this.paginator.getTotalPages();
2295 1991
2296 }, 1992 },
2297 destroy : function () { 1993 destroy : function () {
2298 YAHOO.util.Event.purgeElement(this.link); 1994 YUE.purgeElement(this.link);
2299 this.current.parentNode.removeChild(this.current); 1995 this.current.parentNode.removeChild(this.current);
2300 this.link = this.span = null; 1996 this.link = this.span = null;
2301 }, 1997 },
2302 onClick : function (e) { 1998 onClick : function (e) {
2303 YAHOO.util.Event.stopEvent(e); 1999 YUE.stopEvent(e);
2304 this.paginator.setPage(this.paginator.getTotalPages()); 2000 this.paginator.setPage(this.paginator.getTotalPages());
2305 } 2001 }
2306 }; 2002 };
2307 2003
2308 })(); 2004 })();
2324 } 2020 }
2325 2021
2326 2022
2327 // global hooks after DOM is loaded 2023 // global hooks after DOM is loaded
2328 2024
2329 YUE.onDOMReady(function(){ 2025 $(document).ready(function(){
2330 YUE.on(YUQ('.diff-collapse-button'), 'click', function(e){ 2026 $('.diff-collapse-button').click(function(e) {
2331 var button = e.currentTarget; 2027 var $button = $(e.currentTarget);
2332 var t = YUD.get(button).getAttribute('target'); 2028 var $target = $('#' + $button.attr('target'));
2333 console.log(t); 2029 if($target.hasClass('hidden')){
2334 if(YUD.hasClass(t, 'hidden')){ 2030 $target.removeClass('hidden');
2335 YUD.removeClass(t, 'hidden'); 2031 $button.html("&uarr; {0} &uarr;".format(_TM['Collapse diff']));
2336 YUD.get(button).innerHTML = "&uarr; {0} &uarr;".format(_TM['Collapse diff']); 2032 }
2337 } 2033 else if(!$target.hasClass('hidden')){
2338 else if(!YUD.hasClass(t, 'hidden')){ 2034 $target.addClass('hidden');
2339 YUD.addClass(t, 'hidden'); 2035 $button.html("&darr; {0} &darr;".format(_TM['Expand diff']));
2340 YUD.get(button).innerHTML = "&darr; {0} &darr;".format(_TM['Expand diff']);
2341 } 2036 }
2342 }); 2037 });
2343 }); 2038 });