ubuntu-it QuickReply Enhanced Editor

Aggiunge alcune delle funzionalità dell'editor completo alla risposta rapida

Verze ze dne 23. 07. 2015. Zobrazit nejnovější verzi.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name        ubuntu-it QuickReply Enhanced Editor
// @description Aggiunge alcune delle funzionalità dell'editor completo alla risposta rapida
// @namespace   ubuntu-it
// @include     http://forum.ubuntu-it.org/viewtopic.php?*
// @version     201507231337
// @grant       none
// ==/UserScript==


(function($, window) {
    $.fn.selection = function() {
        var doc = window.doc;
        var element = this[0];
        var selection = {};
        if (window.getSelection) {
            /* except IE */
            selection.start = element.selectionStart;
            selection.end = element.selectionEnd;
            selection.text = element.value.slice(selection.start, selection.end);
        } else if (doc.selection) {
            /* for IE */
            element.focus();
            var range = doc.selection.createRange(),
                range2 = doc.body.createTextRange();
            selection.text = range.text;
            try {
                range2.moveToElementText(element);
                range2.setEndPoint('StartToStart', range);
            } catch (e) {
                range2 = element.createTextRange();
                range2.setEndPoint('StartToStart', range);
            }
            selection.start = element.value.length - range2.text.length;
            selection.end = selection.start + range.text.length;
        }
        return selection;
    }
})(jQuery, window);

//Pulsanti da inserire nell'editor
var buttons = [{
    code: 'b',
    name: '<strong>B</strong>'
}, {
    code: 'u',
  name: '<span style="text-decoration: underline;">u</span>'
}, {
    code: 'i',
    name: '<i>i</i>'
}, {
    code: 'code',
    name: 'Codice'
}, {
    code: 'quote',
    name: 'Cita'
}, {
    code: 'url',
    name: 'URL'
}, ];
jQuery('input[name="show_qr"]').click(function(){  
  var previewBtn = $('<input class="button2" type="submit" value="Anteprima" name="preview" tabindex="8" accesskey="a">');
  previewBtn.click(function(){
    var action = $(this).parents('form').attr('action');
    $(this).parents('form').attr('action', action+'#preview');
  });
  jQuery('.submit-buttons').append(previewBtn);
  jQuery('#message-box').each(function() {
      var $buttons = $('<div id="buttons"></div>');
      $(this).prepend($buttons);
      var $textarea = $('.inputbox', this);
      $.each(buttons, function(i, button) {
          var $btn = $('<button type="button">' + button.name + '</button>');
          $buttons.append($btn);
          $btn.click(function(e) {
              e.preventDefault();
              var textarea = $textarea[0];
              var scrollTop = textarea.scrollTop;
              var selection = $textarea.selection();

              var val = $textarea.val();
              var pre = val.substring(0, selection.start);
              var code = button.code;
              var text = selection.text || '';
              if( code === 'url' ){
                  code += '=' + prompt("Inserire l'URL");
                  if( text.length === 0 ){
                      text += prompt("Inserire il testo");
                  }
              }
              var bbcode = '[' + code + ']' + text + '[/' + button.code + ']';
              var post = val.substring(selection.end);

              var newSelectionStart = selection.start + 2 + button.code.length;
              var newSelectionStop = newSelectionStart + selection.text.length;
              $textarea.val(pre + bbcode + post);
              textarea.selectionStart = newSelectionStart;
              textarea.selectionEnd = newSelectionStop;
              textarea.focus();
              textarea.scrollTop = scrollTop;

          });
      });
  });
});