Project

General

Profile

Patch #31385 » RM_31385_formating_toolbar_color_tools_jstoolbar_SVN.diff

Jérôme BATAILLE, 2019-09-16 16:48

View differences:

public/javascripts/jstoolbar/jstoolbar.js
373 373
      suffix = suffix + " ";
374 374
    }
375 375

  
376
    var prev_res = '';
377
    if (sel) {
378
      prev_res = sel;
379
    }
380

  
376 381
    if (typeof(fn) == 'function') {
377
      res = (sel) ? fn.call(this,sel) : fn('');
382
      res = (sel) ? fn.call(this, sel, prefix, suffix) : fn('');
378 383
    } else {
379 384
      res = (sel) ? sel : '';
380 385
    }
381 386

  
382
    subst = prefix + res + suffix;
387
    if (prev_res != res) {
388
      // change done in fn
389
      subst = res;
390
    } else {
391
      subst = prefix + res + suffix;
392
    }
383 393

  
384 394
    if (typeof(document["selection"]) != "undefined") {
385 395
      document.selection.createRange().text = subst;
386
      var range = this.textarea.createTextRange();
387
      range.collapse(false);
388
      range.move('character', -suffix.length);
389
      range.select();
396
      // suffix not added if fn changed res
397
      if (prev_res == res) {
398
        var range = this.textarea.createTextRange();
399
        range.collapse(false);
400
        range.move('character', -suffix.length);
401
        range.select();
390 402
//      this.textarea.caretPos -= suffix.length;
403
      }
391 404
    } else if (typeof(this.textarea["setSelectionRange"]) != "undefined") {
392 405
      this.textarea.value = this.textarea.value.substring(0, start) + subst +
393
      this.textarea.value.substring(end);
394
      if (sel) {
395
        this.textarea.setSelectionRange(start + subst.length, start + subst.length);
396
      } else {
397
        this.textarea.setSelectionRange(start + prefix.length, start + prefix.length);
406
        this.textarea.value.substring(end);
407

  
408
      // prefix not added if fn changed res
409
      if (prev_res == res) {
410
        if (sel) {
411
          this.textarea.setSelectionRange(start + subst.length, start + subst.length);
412
        } else {
413
          this.textarea.setSelectionRange(start + prefix.length, start + prefix.length);
414
        }
415
        this.textarea.scrollTop = scrollPos;
398 416
      }
399
      this.textarea.scrollTop = scrollPos;
400 417
    }
401 418
  },
402 419
  showPreview: function(event) {
......
471 488
  });
472 489
  return false;
473 490
};
491

  
492
/* Colors menu */
493
jsToolBar.prototype.colorsMenu = function(fn){
494
  var aColors = [
495
    ['#330000','#331900','#333300','#193300','#003300','#003319','#003333','#001933','#000033','#190033','#330033','#330019','#000000'],
496
    ['#660000','#663300','#666600','#336600','#006600','#006633','#006666','#003366','#000066','#330066','#660066','#660033','#202020'],
497
    ['#990000','#994C00','#999900','#4C9900','#009900','#00994C','#009999','#004C99','#000099','#4C0099','#990099','#99004C','#404040'],
498
    ['#CC0000','#CC6600','#CCCC00','#66CC00','#00CC00','#00CC66','#00CCCC','#0066CC','#0000CC','#6600CC','#CC00CC','#CC0066','#606060'],
499
    ['#FF0000','#FF8000','#FFFF00','#80FF00','#00FF00','#00FF80','#00FFFF','#0080FF','#0000FF','#7F00FF','#FF00FF','#FF007F','#808080'],
500
    ['#FF3333','#FF9933','#FFFF33','#99FF33','#33FF33','#33FF99','#33FFFF','#3399FF','#3333FF','#9933FF','#FF33FF','#FF3399','#A0A0A0'],
501
    ['#FF6666','#FFB266','#FFFF66','#B2FF66','#66FF66','#66FFB2','#66FFFF','#66B2FF','#6666FF','#B266FF','#FF66FF','#FF66B2','#C0C0C0'],
502
    ['#FF9999','#FFCC99','#FFFF99','#CCFF99','#99FF99','#99FFCC','#99FFFF','#99CCFF','#9999FF','#CC99FF','#FF99FF','#FF99CC','#E0E0E0'],
503
    ['#FFCCCC','#FFE5CC','#FFFFCC','#E5FFCC','#CCFFCC','#CCFFE5','#CCFFFF','#CCE5FF','#CCCCFF','#E5CCFF','#FFCCFF','#FFCCE5','#FFFFFF']
504
  ];
505
  var menu = $('<table style="position:absolute"></table>');
506
  var alColors = '';
507
  var line;
508
  var cell;
509
  for (var i = 0; i < aColors.length; i++) {
510
    alColors = aColors[i];
511
    line = $('<tr></tr>').appendTo(menu);
512
    for (var j = 0; j < alColors.length; j++) {
513
      cell = $('<td style="background: ' + alColors[j] + '" data-color="' + alColors[j] + '" class="palette"></td>');
514
      cell.appendTo(line);
515
      cell.mouseover(function(){
516
          $(this).addClass('palette-hover');
517
        }).mouseout(function(){
518
          $(this).removeClass('palette-hover');
519
        }).mousedown(function(){
520
          fn($(this).data('color'));
521
        });
522
    }
523
  }
524
  $("body").append(menu);
525
  menu.menu().width(150).position({
526
    my: "left top",
527
    at: "left bottom",
528
    of: this.toolNodes['precode']
529
  });
530
  $(document).on("mousedown", function() {
531
    menu.remove();
532
  });
533
  return false;
534
};
(9-9/9)