<commit_before>// Generated by CoffeeScript 1.6.3
(function () {
  define(['require', 'jquery', 'aloha', 'aloha/plugin', 'ui/ui', 'PubSub', 'jquery19', 'underscore', 'booktype', 'format/format-plugin'],
    function (require, jQuery, Aloha, Plugin, Ui, PubSub, jQuery19, _, booktype, formatPlugin) {

      // win.booktype.editor.data.settings.config.media.allowUpload

      var $ROOT, adoptedActions, makeItemRelay, squirreledEditable;
      var $ = jQuery;
      var foundTag = '';
      var foundStyle = null;
      var globalSettings = null;

      squirreledEditable = null;
      //   $ROOT = jQuery('body');
      $ROOT = jQuery('DIV.contentHeader');

      makeItemRelay = function (slot) {
        var ItemRelay;
        ItemRelay = (function () {
          function ItemRelay() {
          }

          ItemRelay.prototype.show = function () {
            return $ROOT.find(".action." + slot).removeClass('hidden');
          };

          ItemRelay.prototype.hide = function () {
          };

          ItemRelay.prototype.setActive = function (bool) {
            if (!bool) {
              $ROOT.find(".action." + slot).removeClass('active');
            }
            if (bool) {
              return $ROOT.find(".action." + slot).addClass('active');
            }
          };

          ItemRelay.prototype.setState = function (bool) {
            return this.setActive(bool);
          };

          ItemRelay.prototype.enable = function (bool) {
            if (bool == null) {
              bool = true;
            }
            if ($ROOT.find(".action." + slot).is('.btn')) {
              if (!bool) {
                $ROOT.find(".action." + slot).attr('disabled', 'disabled');
              }
              if (bool) {
                return $ROOT.find(".action." + slot).removeAttr('disabled');
              }
            } else {
              if (!bool) {
                $ROOT.find(".action." + slot).parent().addClass('disabled');
              }
              if (bool) {
                return $ROOT.find(".action." + slot).parent().removeClass('disabled');
              }
            }
          };

          ItemRelay.prototype.disable = function () {
            return this.enable(false);
          };

          ItemRelay.prototype.setActiveButton = function (a, b) {
            return;
          };

          ItemRelay.prototype.focus = function (a) {
            return;
          };

          ItemRelay.prototype.foreground = function (a) {
            return;
          };

          return ItemRelay;

        })();
        return new ItemRelay();
      };

      var _previousTag = null;

      var disableOptions = function (tag) {
        var toolbar = require('toolbar/toolbar-plugin');

        // This list should be somehow configurable
        var _buttons = booktype.editor.data.settings.config.edit.toolbar;
        var _menus = booktype.editor.data.settings.config.edit.menu;

        // This creates problems with book heading block
        // if(_previousTag === tag) return;
        // _previousTag = tag;

        toolbar.enableToolbarAll();
        toolbar.enableMenuAll();

        // When focus is in headings
        if (_.indexOf(['h1', 'h2', 'h3', 'h4', 'h5', 'h6'], tag.toLowerCase()) != -1) {
          _.each(_buttons['H'], function (btn) {
            toolbar.disableToolbar(btn);
          });

          _.each(_menus['H'], function (btn) {
            toolbar.disableMenu(btn);
          });
        }

        // When focus is in preformated text
        if (_.indexOf(['pre'], tag.toLowerCase()) != -1) {
          _.each(_buttons['PRE'], function (btn) {
            toolbar.disableToolbar(btn);
          });

          _.each(_menus['PRE'], function (btn) {
            toolbar.disableMenu(btn);
          });
        }
      };


      adoptedActions = {};

      Ui.adopt = function (slot, type, settings) {
        var evt;
        evt = $.Event('aloha.toolbar.adopt');
        $.extend(evt, {
          params: {
            slot: slot,
            type: type,
            settings: settings
          },
          component: null
        });
        PubSub.pub(evt.type, evt);
        if (evt.isDefaultPrevented()) {
          evt.component.adoptParent(toolbar);
          return evt.component;
        }
        adoptedActions[slot] = settings;
        return makeItemRelay(slot);
      };

      var fireOnToolbar = function (editable) {
        var $ROOT2 = jQuery('DIV.contentHeader');

        var changeHeading = function (evt) {
          var $el, hTag, rangeObject;

          //evt.preventDefault();

          // mahaloBlock na elementu koji zelimo

          $el = jQuery(this);
          hTag = $el.attr('data-tagname');

          rangeObject = Aloha.Selection.getRangeObject();
          rangeObject.select();

          if (foundStyle) {
            if (foundStyle.type == 'custom') {
              if (!_.isUndefined(foundStyle.remove)) {
                foundStyle.remove(rangeObject);
                rangeObject = Aloha.Selection.getRangeObject();
                rangeObject.select();
              }
            }
          }

          var _s = globalSettings.styles[hTag.toUpperCase()];
          var _hasModified = false;


          if (_s.type == 'custom') {
            if (!_.isUndefined(_s.create)) {
              _hasModified = _s.create(rangeObject);
            }
          }

          if (!_hasModified) {
            if (_s.type === 'formatting') {
              // formatPlugin.removeFormat();
              formatPlugin.changeMarkup(hTag);
            } else {
              Aloha.execCommand('FormatBlock', false, hTag);
            }
          }
<commit_msg>BK-1807 Define for custom styles if you want to remove previous style<commit_after>// Generated by CoffeeScript 1.6.3
(function () {
  define(['require', 'jquery', 'aloha', 'aloha/plugin', 'ui/ui', 'PubSub', 'jquery19', 'underscore', 'booktype', 'format/format-plugin'],
    function (require, jQuery, Aloha, Plugin, Ui, PubSub, jQuery19, _, booktype, formatPlugin) {

      // win.booktype.editor.data.settings.config.media.allowUpload

      var $ROOT, adoptedActions, makeItemRelay, squirreledEditable;
      var $ = jQuery;
      var foundTag = '';
      var foundStyle = null;
      var globalSettings = null;

      squirreledEditable = null;
      //   $ROOT = jQuery('body');
      $ROOT = jQuery('DIV.contentHeader');

      makeItemRelay = function (slot) {
        var ItemRelay;
        ItemRelay = (function () {
          function ItemRelay() {
          }

          ItemRelay.prototype.show = function () {
            return $ROOT.find(".action." + slot).removeClass('hidden');
          };

          ItemRelay.prototype.hide = function () {
          };

          ItemRelay.prototype.setActive = function (bool) {
            if (!bool) {
              $ROOT.find(".action." + slot).removeClass('active');
            }
            if (bool) {
              return $ROOT.find(".action." + slot).addClass('active');
            }
          };

          ItemRelay.prototype.setState = function (bool) {
            return this.setActive(bool);
          };

          ItemRelay.prototype.enable = function (bool) {
            if (bool == null) {
              bool = true;
            }
            if ($ROOT.find(".action." + slot).is('.btn')) {
              if (!bool) {
                $ROOT.find(".action." + slot).attr('disabled', 'disabled');
              }
              if (bool) {
                return $ROOT.find(".action." + slot).removeAttr('disabled');
              }
            } else {
              if (!bool) {
                $ROOT.find(".action." + slot).parent().addClass('disabled');
              }
              if (bool) {
                return $ROOT.find(".action." + slot).parent().removeClass('disabled');
              }
            }
          };

          ItemRelay.prototype.disable = function () {
            return this.enable(false);
          };

          ItemRelay.prototype.setActiveButton = function (a, b) {
            return;
          };

          ItemRelay.prototype.focus = function (a) {
            return;
          };

          ItemRelay.prototype.foreground = function (a) {
            return;
          };

          return ItemRelay;

        })();
        return new ItemRelay();
      };

      var _previousTag = null;

      var disableOptions = function (tag) {
        var toolbar = require('toolbar/toolbar-plugin');

        // This list should be somehow configurable
        var _buttons = booktype.editor.data.settings.config.edit.toolbar;
        var _menus = booktype.editor.data.settings.config.edit.menu;

        // This creates problems with book heading block
        // if(_previousTag === tag) return;
        // _previousTag = tag;

        toolbar.enableToolbarAll();
        toolbar.enableMenuAll();

        // When focus is in headings
        if (_.indexOf(['h1', 'h2', 'h3', 'h4', 'h5', 'h6'], tag.toLowerCase()) != -1) {
          _.each(_buttons['H'], function (btn) {
            toolbar.disableToolbar(btn);
          });

          _.each(_menus['H'], function (btn) {
            toolbar.disableMenu(btn);
          });
        }

        // When focus is in preformated text
        if (_.indexOf(['pre'], tag.toLowerCase()) != -1) {
          _.each(_buttons['PRE'], function (btn) {
            toolbar.disableToolbar(btn);
          });

          _.each(_menus['PRE'], function (btn) {
            toolbar.disableMenu(btn);
          });
        }
      };


      adoptedActions = {};

      Ui.adopt = function (slot, type, settings) {
        var evt;
        evt = $.Event('aloha.toolbar.adopt');
        $.extend(evt, {
          params: {
            slot: slot,
            type: type,
            settings: settings
          },
          component: null
        });
        PubSub.pub(evt.type, evt);
        if (evt.isDefaultPrevented()) {
          evt.component.adoptParent(toolbar);
          return evt.component;
        }
        adoptedActions[slot] = settings;
        return makeItemRelay(slot);
      };

      var fireOnToolbar = function (editable) {
        var $ROOT2 = jQuery('DIV.contentHeader');

        var changeHeading = function (evt) {
          var $el, hTag, rangeObject;

          //evt.preventDefault();

          // mahaloBlock na elementu koji zelimo

          $el = jQuery(this);
          hTag = $el.attr('data-tagname');

          rangeObject = Aloha.Selection.getRangeObject();
          rangeObject.select();

          var _s = globalSettings.styles[hTag.toUpperCase()];
          var removePrevious = !_.isUndefined(_s.remove_previous)?_s.remove_previous:false;

          if (foundStyle) {
            if (foundStyle.type == 'custom') {
              if (!_.isUndefined(foundStyle.remove) && removePrevious) {
                foundStyle.remove(rangeObject);
                rangeObject = Aloha.Selection.getRangeObject();
                rangeObject.select();
              }
            }
          }

          var _hasModified = false;


          if (_s.type == 'custom') {
            if (!_.isUndefined(_s.create)) {
              _hasModified = _s.create(rangeObject);
            }
          }

          if (!_hasModified) {
            if (_s.type === 'formatting') {
              // formatPlugin.removeFormat();
              formatPlugin.changeMarkup(hTag);
            } else {
              Aloha.execCommand('FormatBlock', false, hTag);
            }
          }

{'fraction_non_alphanumeric': 0.13758127438231468, 'fraction_numerical': 0.0031209362808842654, 'mean_word_length': 1.6011273957158962, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4559425', 'n_tokens_mistral': 3198, 'n_tokens_neox': 3109, 'n_words': 623}