<commit_before># -*- coding: utf-8 -*-

# This plugin provides Chessboard’s default toolbar used
# when creating new posts or replying. Currently for Markdown
# only the emoticons toolbar is provided, BBCode also has a
# tool toolbar with buttons to insert BBCode.
module DefaultToolbarPlugin
  include Chessboard::Plugin

  # All tools which appear in the BBCode toolbar. :code is what
  # gets inserted, :show is what the button is labelled. The main
  # key is used as an identifier for JavaScript.
  BB_TAGS = {
    "bold"      => {:code => "[b][/b]", :show => "<strong>b</strong>"},
    "italics"   => {:code => "[i][/i]", :show => "<em>i</em>"},
    "underline" => {:code => "[u][/u]", :show => "<span style='text-decoration: underline'>u</span>"},
    "url"       => {:code => "[url][/url]", :show => "[url]"},
    "fullurl"   => {:code => "[url=][/url]", :show => "[url=]"},
    "img"       => {:code => "[img][/img]", :show => "[img]"},
    "quote"     => {:code => "[quote][/quote]", :show => "[quote]"},
    "code"      => {:code => "[code][/code]", :show => "[code]"},
    "list"      => {:code => "[list][/list]", :show => "[list]"},
    "olist"     => {:code => "[list=1][/list]", :show => "[list=1]"}
  }

  def hook_html_header(options)
    str = super
    str = content_tag("style", :type => "text/css") do
<<CSS.html_safe
.toolbar ul {
  margin: 0px;
  list-style-type: none;
  padding: 0px;
}
.toolbar ul li {
  display: inline-block;
  margin-left: 4px;
}
.tool-emoticon {
  cursor: pointer;
}
.toolbar .tools li {
  background-color: white;
  border: 1px solid #AAAAAA;
  padding: 2px;
  min-width: 30px;
  text-align: center;
  cursor: pointer;
}
CSS
    end

    str += content_tag("script", :type => "text/javascript") do
<<JS.html_safe
$(document).ready(function(){
  $(".tool-emoticon").click(function(){
    $("#post_content, #personal_post_content, #topic_posts_attributes_0_content, #personal_message_posts_attributes_0_content").insertAtCaret(":" + $(this).attr("alt") + ":");
  });

  #{
  BB_TAGS.reduce("".html_safe) do |str, (ident, hsh)|
    str + %Q<$("#tool-#{ident.html_safe}").click(function(){
      $("#post_content").insertAtCaret("#{hsh[:code].html_safe}");
    });>.html_safe + "\n".html_safe
  end
  }
});
JS
    end
<commit_msg>Fix toolbar buttons JS not inserting into personal messages<commit_after># -*- coding: utf-8 -*-

# This plugin provides Chessboard’s default toolbar used
# when creating new posts or replying. Currently for Markdown
# only the emoticons toolbar is provided, BBCode also has a
# tool toolbar with buttons to insert BBCode.
module DefaultToolbarPlugin
  include Chessboard::Plugin

  # All tools which appear in the BBCode toolbar. :code is what
  # gets inserted, :show is what the button is labelled. The main
  # key is used as an identifier for JavaScript.
  BB_TAGS = {
    "bold"      => {:code => "[b][/b]", :show => "<strong>b</strong>"},
    "italics"   => {:code => "[i][/i]", :show => "<em>i</em>"},
    "underline" => {:code => "[u][/u]", :show => "<span style='text-decoration: underline'>u</span>"},
    "url"       => {:code => "[url][/url]", :show => "[url]"},
    "fullurl"   => {:code => "[url=][/url]", :show => "[url=]"},
    "img"       => {:code => "[img][/img]", :show => "[img]"},
    "quote"     => {:code => "[quote][/quote]", :show => "[quote]"},
    "code"      => {:code => "[code][/code]", :show => "[code]"},
    "list"      => {:code => "[list][/list]", :show => "[list]"},
    "olist"     => {:code => "[list=1][/list]", :show => "[list=1]"}
  }

  def hook_html_header(options)
    str = super
    str = content_tag("style", :type => "text/css") do
<<CSS.html_safe
.toolbar ul {
  margin: 0px;
  list-style-type: none;
  padding: 0px;
}
.toolbar ul li {
  display: inline-block;
  margin-left: 4px;
}
.tool-emoticon {
  cursor: pointer;
}
.toolbar .tools li {
  background-color: white;
  border: 1px solid #AAAAAA;
  padding: 2px;
  min-width: 30px;
  text-align: center;
  cursor: pointer;
}
CSS
    end

    str += content_tag("script", :type => "text/javascript") do
<<JS.html_safe
$(document).ready(function(){
  $(".tool-emoticon").click(function(){
    $("#post_content, #personal_post_content, #topic_posts_attributes_0_content, #personal_message_posts_attributes_0_content").insertAtCaret(":" + $(this).attr("alt") + ":");
  });

  #{
  BB_TAGS.reduce("".html_safe) do |str, (ident, hsh)|
    str + %Q<$("#tool-#{ident.html_safe}").click(function(){
      $("#post_content, #personal_post_content, #topic_posts_attributes_0_content, #personal_message_posts_attributes_0_content").insertAtCaret("#{hsh[:code].html_safe}");
    });>.html_safe + "\n".html_safe
  end
  }
});
JS
    end

{'fraction_non_alphanumeric': 0.2149393487976165, 'fraction_numerical': 0.005533092147265376, 'mean_word_length': 3.7474747474747474, 'pattern_counts': {'":': 4, '<': 25, '<?xml version=': 0, '>': 81, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6180918', 'n_tokens_mistral': 1658, 'n_tokens_neox': 1615, 'n_words': 403}