<commit_before>//= require cms/lib/form
//= require cms/lib/template_form

//= require ss/lib/workflow
//= require ss/lib/addon/temp_file
//= require ss/lib/search_ui
//= require ss/lib/list_ui
//= require ss/lib/tree_ui
//= require ss/lib/dropdown

// here are polyfills for IE11
//= require mdn-polyfills/String.prototype.endsWith.js
//= require mdn-polyfills/String.prototype.includes.js
//= require mdn-polyfills/String.prototype.padEnd.js
//= require mdn-polyfills/String.prototype.padStart.js
//= require mdn-polyfills/String.prototype.repeat.js
//= require mdn-polyfills/String.prototype.startsWith.js
//= require mdn-polyfills/String.prototype.trim.js

SS_Preview = (function () {
  function SS_Preview(el) {
    this.el = el;
    this.inplaceMode = false;
    this.layouts = [];
    this.parts = [];
    this.editLock = new EditLock(this);
  }

  SS_Preview.libs = {
    jquery: { isInstalled: function() { return !!window.jQuery; }, js: null, css: null },
    datetimePicker: { isInstalled: function() { return !!$.datetimepicker; }, js: null, css: null },
    colorbox: { isInstalled: function() { return !!$.colorbox; }, js: null, css: null },
    dialog: { isInstalled: function() { return $.ui && $.ui.dialog; }, js: null, css: null }
  };

  SS_Preview.confirms = { delete: null, publish: null };

  SS_Preview.notices = { deleted: null, published: null, moved: null };

  SS_Preview.item = {};

  SS_Preview.preview_path = "";

  SS_Preview.mobile_path = "/mobile";

  SS_Preview.request_path = null;

  SS_Preview.form_item = null;

  SS_Preview.overlayPadding = 0;
  SS_Preview.previewToolHeight = 70;

  SS_Preview.inplaceFormPath = { page: null, columnValue: {}, palette: null };

  SS_Preview.workflowPath = { wizard: null, pages: null, request: null };

  SS_Preview.redirectorPath = { newPage: null };

  SS_Preview.publishPath = null;

  SS_Preview.lockPath = null;

  SS_Preview.refreshLockInterval = 2 * 60 * 1000;

  SS_Preview.instance = null;

  SS_Preview.minFrameSize = { width: 320, height: 150 };
  SS_Preview.initialFrameSize = { width: 960, height: 240 };
  SS_Preview.initialApproverSize = { width: SS_Preview.initialFrameSize.width, height: 480 };

  SS_Preview.jqueryDialogMargin = { height: 60 };

  SS_Preview.pageTitle = "<%= I18n.t("modules.addons.cms/body") %>";

  SS_Preview.userInplaceEdit = true;

  SS_Preview.render = function (opts) {
    if (SS_Preview.instance) {
      return;
    }

    SS_Preview.instance = new SS_Preview("#ss-preview");

    SS_Preview.loadJQuery(function() {
      $.when(
        SS_Preview.lazyLoad(SS_Preview.libs.datetimePicker),
        SS_Preview.lazyLoad(SS_Preview.libs.colorbox),
        SS_Preview.lazyLoad(SS_Preview.libs.dialog)
      ).done(function () {
        SS_Preview.instance.initialize(opts);
      });
    });
  };

  SS_Preview.loadJQuery = function (callback) {
    if (window.jQuery) {
      callback();
      return;
    }

    var link = document.createElement("link");
    link.rel = "stylesheet";
    link.href = SS_Preview.libs.jquery.css;

    var script = document.createElement("script");
    script.type = "text/javascript";
    script.src = SS_Preview.libs.jquery.js;

    if (script.readyState) {
      // IE
    } else {
      script.onload = function () {
        callback();
      }
    }

    document.getElementsByTagName("head")[0].appendChild(link);
    document.getElementsByTagName("head")[0].appendChild(script);
  };

  SS_Preview.lazyLoad = function (data) {
    var d = $.Deferred();

    if (data.isInstalled()) {
      d.resolve();
      return d.promise();
    }

    var link;
    if (data.css) {
      link = document.createElement("link");
      link.rel = "stylesheet";
      link.href = data.css;
    }

    var script;
    if (data.js) {
      script = document.createElement("script");
      script.type = "text/javascript";
      script.src = data.js;
    }

    if (link) {
      document.getElementsByTagName("head")[0].appendChild(link);
    }

    if (script) {
      if (script.readyState) {
        // IE
        d.resolve();
      } else {
        script.onload = function () {
          d.resolve();
        }
      }

      document.getElementsByTagName("head")[0].appendChild(script);
    } else {
      d.resolve();
    }

    return d.promise();
  };

  SS_Preview.notice = function (message) {
    if (!SS_Preview.instance) {
      return;
    }
    if (!SS_Preview.instance.notice) {
      return;
    }

    SS_Preview.instance.notice.show(message);
  };

  SS_Preview.bindToWorkflowCommentForm = function (updateType) {
    if (!SS_Preview.instance) {
      return;
    }

    SS_Preview.instance.bindToWorkflowCommentForm(updateType);
  };

  SS_Preview.prototype.initialize = function(opts) {
    this.$el = $(this.el);
    this.$datePicker = this.$el.find(".ss-preview-date");
    this.$datePicker.datetimepicker({
      lang: "ja",
      roundTime: "ceil",
      step: 30,
      closeOnDateSelect: true
    });

    var self = this;

    this.initializePart();
    this.initializeLayout();
    this.initializePage();
    this.initializeColumn();

    // initialize workflow
    this.$el.on("click", "#ss-preview-btn-workflow-start", function() {
      self.openWorkflowApprove();
    });

    this.$el.on("click", "#ss-preview-btn-workflow-approve", function() {
      self.openWorkflowComment("approve");
    });
    this.$el.on("click", "#ss-preview-btn-workflow-remand", function() {
      self.openWorkflowComment("remand");
    });
    this.$el.on("click", "#ss-preview-btn-workflow-pull-up", function() {
      self.openWorkflowComment("pull-up");
    });

    this.$el.on("click", "#ss-preview-btn-publish", function () {
      self.publish();
    });

    // initialize overlay
    this.overlay = new Overlay(this);
    this.overlay.on("part:edit", function(ev, data) {
      self.openPartEdit(data.id);
    });
    this.overlay.on("page:edit", function(ev, data) {
      self.openPageEdit(data.id);
    });
    this.overlay.on("column:edit", function(ev, data) {
      self.openColumnEdit(data.id);
    });
    this.overlay.on("column:delete", function(ev, data) {
      self.postColumnDelete(data.id);
    });
    this.overlay.on("column:moveUp", function(ev, data) {
      self.postColumnMoveUp(data.id);
    });
    this.overlay.on("column:moveDown", function(ev, data) {
      self.postColumnMoveDown(data.id);
    });
    this.overlay.on("column:movePosition", function(ev, data, order) {
      self.postColumnMovePosition(data.id, order);
    });

    var formEnd = $("#ss-preview-form-end");
    if (formEnd[0]) {
      this.formPalette = FormPalette.createBefore(this, formEnd[0]);
    }

    this.$el.on("click", ".ss-preview-btn-toggle-inplace", function () {
      var before = self.inplaceMode;
      self.toggleInplaceMode().always(function() {
        if (before === self.inplaceMode) {
          return;
        }
        if (!window.history.pushState) {
          return;
        }

        if (self.inplaceMode) {
          window.history.pushState(null, null, window.location.pathname + "#inplace");
        } else {
          window.history.pushState(null, null, window.location.pathname);
        }
      });
    });

    $(document).on("click", ".ss-preview-btn-open-path", function () {
      var path = $(this).data("path");
      if (path) {
        window.open(path, "_blank")
      }
    });

    var $selectNodeBtn = this.$el.find("#ss-preview-btn-select-node");
    $selectNodeBtn.colorbox({ iframe: true, fixed: true, width: "90%", height: "90%" })
      .data("on-select", function($item) {
        var $dataEl = $item.closest("[data-id]");
        var id = $dataEl.data("id");
        var name = $dataEl.find(".name").text();

        var $nodeDataEl = $selectNodeBtn.closest("[data-node-id]");
        SS_Preview.setData($nodeDataEl, "node-id", id);
        $nodeDataEl.find("label").html(name);
      });

    this.$el.find("#ss-preview-btn-create-new-page").on("click", function() {
      var $nodeDataEl = $selectNodeBtn.closest("[data-node-id]");<commit_msg>[modify] modified to turn edit mode off when click approve<commit_after>//= require cms/lib/form
//= require cms/lib/template_form

//= require ss/lib/workflow
//= require ss/lib/addon/temp_file
//= require ss/lib/search_ui
//= require ss/lib/list_ui
//= require ss/lib/tree_ui
//= require ss/lib/dropdown

// here are polyfills for IE11
//= require mdn-polyfills/String.prototype.endsWith.js
//= require mdn-polyfills/String.prototype.includes.js
//= require mdn-polyfills/String.prototype.padEnd.js
//= require mdn-polyfills/String.prototype.padStart.js
//= require mdn-polyfills/String.prototype.repeat.js
//= require mdn-polyfills/String.prototype.startsWith.js
//= require mdn-polyfills/String.prototype.trim.js

SS_Preview = (function () {
  function SS_Preview(el) {
    this.el = el;
    this.inplaceMode = false;
    this.layouts = [];
    this.parts = [];
    this.editLock = new EditLock(this);
  }

  SS_Preview.libs = {
    jquery: { isInstalled: function() { return !!window.jQuery; }, js: null, css: null },
    datetimePicker: { isInstalled: function() { return !!$.datetimepicker; }, js: null, css: null },
    colorbox: { isInstalled: function() { return !!$.colorbox; }, js: null, css: null },
    dialog: { isInstalled: function() { return $.ui && $.ui.dialog; }, js: null, css: null }
  };

  SS_Preview.confirms = { delete: null, publish: null };

  SS_Preview.notices = { deleted: null, published: null, moved: null };

  SS_Preview.item = {};

  SS_Preview.preview_path = "";

  SS_Preview.mobile_path = "/mobile";

  SS_Preview.request_path = null;

  SS_Preview.form_item = null;

  SS_Preview.overlayPadding = 0;
  SS_Preview.previewToolHeight = 70;

  SS_Preview.inplaceFormPath = { page: null, columnValue: {}, palette: null };

  SS_Preview.workflowPath = { wizard: null, pages: null, request: null };

  SS_Preview.redirectorPath = { newPage: null };

  SS_Preview.publishPath = null;

  SS_Preview.lockPath = null;

  SS_Preview.refreshLockInterval = 2 * 60 * 1000;

  SS_Preview.instance = null;

  SS_Preview.minFrameSize = { width: 320, height: 150 };
  SS_Preview.initialFrameSize = { width: 960, height: 240 };
  SS_Preview.initialApproverSize = { width: SS_Preview.initialFrameSize.width, height: 480 };

  SS_Preview.jqueryDialogMargin = { height: 60 };

  SS_Preview.pageTitle = "<%= I18n.t("modules.addons.cms/body") %>";

  SS_Preview.userInplaceEdit = true;

  SS_Preview.render = function (opts) {
    if (SS_Preview.instance) {
      return;
    }

    SS_Preview.instance = new SS_Preview("#ss-preview");

    SS_Preview.loadJQuery(function() {
      $.when(
        SS_Preview.lazyLoad(SS_Preview.libs.datetimePicker),
        SS_Preview.lazyLoad(SS_Preview.libs.colorbox),
        SS_Preview.lazyLoad(SS_Preview.libs.dialog)
      ).done(function () {
        SS_Preview.instance.initialize(opts);
      });
    });
  };

  SS_Preview.loadJQuery = function (callback) {
    if (window.jQuery) {
      callback();
      return;
    }

    var link = document.createElement("link");
    link.rel = "stylesheet";
    link.href = SS_Preview.libs.jquery.css;

    var script = document.createElement("script");
    script.type = "text/javascript";
    script.src = SS_Preview.libs.jquery.js;

    if (script.readyState) {
      // IE
    } else {
      script.onload = function () {
        callback();
      }
    }

    document.getElementsByTagName("head")[0].appendChild(link);
    document.getElementsByTagName("head")[0].appendChild(script);
  };

  SS_Preview.lazyLoad = function (data) {
    var d = $.Deferred();

    if (data.isInstalled()) {
      d.resolve();
      return d.promise();
    }

    var link;
    if (data.css) {
      link = document.createElement("link");
      link.rel = "stylesheet";
      link.href = data.css;
    }

    var script;
    if (data.js) {
      script = document.createElement("script");
      script.type = "text/javascript";
      script.src = data.js;
    }

    if (link) {
      document.getElementsByTagName("head")[0].appendChild(link);
    }

    if (script) {
      if (script.readyState) {
        // IE
        d.resolve();
      } else {
        script.onload = function () {
          d.resolve();
        }
      }

      document.getElementsByTagName("head")[0].appendChild(script);
    } else {
      d.resolve();
    }

    return d.promise();
  };

  SS_Preview.notice = function (message) {
    if (!SS_Preview.instance) {
      return;
    }
    if (!SS_Preview.instance.notice) {
      return;
    }

    SS_Preview.instance.notice.show(message);
  };

  SS_Preview.bindToWorkflowCommentForm = function (updateType) {
    if (!SS_Preview.instance) {
      return;
    }

    SS_Preview.instance.bindToWorkflowCommentForm(updateType);
  };

  SS_Preview.prototype.initialize = function(opts) {
    this.$el = $(this.el);
    this.$datePicker = this.$el.find(".ss-preview-date");
    this.$datePicker.datetimepicker({
      lang: "ja",
      roundTime: "ceil",
      step: 30,
      closeOnDateSelect: true
    });

    var self = this;

    this.initializePart();
    this.initializeLayout();
    this.initializePage();
    this.initializeColumn();

    // initialize workflow
    this.$el.on("click", "#ss-preview-btn-workflow-start", function() {
      self.openWorkflowApprove();
    });

    this.$el.on("click", "#ss-preview-btn-workflow-approve", function() {
      self.openWorkflowComment("approve");
    });
    this.$el.on("click", "#ss-preview-btn-workflow-remand", function() {
      self.openWorkflowComment("remand");
    });
    this.$el.on("click", "#ss-preview-btn-workflow-pull-up", function() {
      self.openWorkflowComment("pull-up");
    });

    this.$el.on("click", "#ss-preview-btn-publish", function () {
      self.publish();
    });

    // initialize overlay
    this.overlay = new Overlay(this);
    this.overlay.on("part:edit", function(ev, data) {
      self.openPartEdit(data.id);
    });
    this.overlay.on("page:edit", function(ev, data) {
      self.openPageEdit(data.id);
    });
    this.overlay.on("column:edit", function(ev, data) {
      self.openColumnEdit(data.id);
    });
    this.overlay.on("column:delete", function(ev, data) {
      self.postColumnDelete(data.id);
    });
    this.overlay.on("column:moveUp", function(ev, data) {
      self.postColumnMoveUp(data.id);
    });
    this.overlay.on("column:moveDown", function(ev, data) {
      self.postColumnMoveDown(data.id);
    });
    this.overlay.on("column:movePosition", function(ev, data, order) {
      self.postColumnMovePosition(data.id, order);
    });

    var formEnd = $("#ss-preview-form-end");
    if (formEnd[0]) {
      this.formPalette = FormPalette.createBefore(this, formEnd[0]);
    }

    this.$el.on("click", ".ss-preview-btn-toggle-inplace", function () {
      var before = self.inplaceMode;
      self.toggleInplaceMode().always(function() {
        if (before === self.inplaceMode) {
          return;
        }
        if (!window.history.pushState) {
          return;
        }

        if (self.inplaceMode) {
          window.history.pushState(null, null, window.location.pathname + "#inplace");
        } else {
          window.history.pushState(null, null, window.location.pathname);
        }
      });
    });

    this.$el.on("click", "#ss-preview-btn-workflow-start", function () {
      var before = self.inplaceMode;
      if (self.inplaceMode) {
        self.toggleInplaceMode().always(function () {
          if (before === self.inplaceMode) {
            return;
          }
          if (!window.history.pushState) {
            return;
          }
          window.history.pushState(null, null, window.location.pathname);
        });
      }
    });

    $(document).on("click", ".ss-preview-btn-open-path", function () {
      var path = $(this).data("path");
      if (path) {
        window.open(path, "_blank")
      }
    });

    var $selectNodeBtn = this.$el.find("#ss-preview-btn-select-node");
    $selectNodeBtn.colorbox({ iframe: true, fixed: true, width: "90%", height: "90%" })
      .data("on-select", function($item) {
        var $dataEl = $item.closest("[data-id]");
        var id = $dataEl.data("id");
        var name = $dataEl.find(".name").text();

        var $nodeDataEl = $selectNodeBtn.closest("[data-node-id]");
        SS_Preview.setData($nodeDataEl, "node-id", id);
        $nodeDataEl.find("label").html(name);
      });

    this.$el.find("#ss-preview-btn-create-new-page").on("click", function() {
      var $nodeDataEl = $selectNodeBtn.closest("[data-node-id]");
{'fraction_non_alphanumeric': 0.16387718242022878, 'fraction_numerical': 0.005177603853100542, 'mean_word_length': 2.8247755008058943, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '6879815', 'n_tokens_mistral': 5550, 'n_tokens_neox': 5340, 'n_words': 881}