<commit_before>/* Copyright (c) 2013-2016 The TagSpaces Authors.
 * Use of this source code is governed by the MIT license which can be found in the LICENSE.txt file. */

define(function(require, exports, module) {
  "use strict";

  var extensionID = "editorText"; // ID should be equal to the directory name where the ext. is located
  console.log("Loading " + extensionID);

  var TSCORE = require("tscore");
  var currentFilePath;
  var $containerElement;
  var extensionDirectory = TSCORE.Config.getExtensionPath() + "/" + extensionID;
  var cmEditor;
  var contentLoaded = false;

  function init(filePath, containerElementID, isViewer) {
    console.log("Initalization Text Editor...");
    $containerElement = $('#' + containerElementID);

    currentFilePath = filePath;
    $containerElement.empty();
    $containerElement.css("background-color" , "white");
    $containerElement.append($('<iframe>', {
      sandbox: "allow-same-origin allow-scripts allow-modals",
      id: "iframeViewer",
      "nwdisable": "",
      "src": extensionDirectory + "/index.html?&locale=" + TSCORE.currentLanguage
    }));

    TSCORE.IO.loadTextFilePromise(filePath).then(function(content) {
      setContent(content);
      viewerMode(isViewer);
    }, function(error) {
      TSCORE.hideLoadingAnimation();
      TSCORE.showAlertDialog("Loading " + filePath + " failed.");
      console.error("Loading file " + filePath + " failed " + error);
    });

    //keys[convertMouseTrapToCodeMirrorKeyBindings(TSCORE.Config.getSaveDocumentKeyBinding())] = function() {
    //  TSCORE.FileOpener.saveFile();
    //};
    //
    //keys[convertMouseTrapToCodeMirrorKeyBindings(TSCORE.Config.getCloseViewerKeyBinding())] = function() {
    //  TSCORE.FileOpener.closeFile();
    //};

    //TSCORE.IO.loadTextFilePromise(filePath).then(function(content) {
    //  exports.setContent(content);
    //},
    //function(error) {
    //  TSCORE.hideLoadingAnimation();
    //  TSCORE.showAlertDialog("Loading " + filePath + " failed.");
    //  console.error("Loading file " + filePath + " failed " + error);
    //});
    //});
  }

  // Converts mod+s to Ctrl+S
  function convertMouseTrapToCodeMirrorKeyBindings(keyBinding) {
    if (keyBinding.indexOf("+") < 0) {
      return;
    }
    var key = keyBinding.split("+");
    if (key[0] === "mod") {
      isOSX ? key[0] = "cmd" : key[0] = "ctrl";
    }
    key[0] = key[0].charAt(0).toUpperCase() + key[0].slice(1);
    return key[0] + "-" + key[1].toUpperCase();
  }

  function viewerMode(isViewerMode) {
    var contentWindow = document.getElementById("iframeViewer").contentWindow;
    if (typeof contentWindow.viewerMode === "function") {
      contentWindow.viewerMode(isViewerMode);
    } else {
      window.setTimeout(function() {
        if (typeof contentWindow.viewerMode === "function") {
          contentWindow.viewerMode(isViewerMode);
        }
      } , 500);
    }
  }

  function setContent(content) {

    var UTF8_BOM = "\ufeff";
    if (content.indexOf(UTF8_BOM) === 0) {
      content = content.substring(1, content.length);
    }

    var contentWindow = document.getElementById("iframeViewer").contentWindow;
    if (typeof contentWindow.setContent === "function") {
      contentWindow.require = require;
      var isViewerMode = true;
      contentWindow.isViewerMode = isViewerMode;
      contentWindow.extensionDirectory = extensionDirectory;
      contentWindow.setContent(content , currentFilePath);
    } else {
      window.setTimeout(function() {
        if (typeof contentWindow.setContent === "function") {
          contentWindow.setContent(content);
        }
      } , 500);
    }

  }

  function getContent() {

    return cmEditor.getValue();
  }

  exports.init = init;
  exports.getContent = getContent;
  exports.setContent = setContent;
  exports.viewerMode = viewerMode;

});

<commit_msg>update ext<commit_after>/* Copyright (c) 2013-2016 The TagSpaces Authors.
 * Use of this source code is governed by the MIT license which can be found in the LICENSE.txt file. */

define(function(require, exports, module) {
  "use strict";

  var extensionID = "editorText"; // ID should be equal to the directory name where the ext. is located
  console.log("Loading " + extensionID);

  var TSCORE = require("tscore");
  var currentFilePath;
  var $containerElement;
  var extensionDirectory = TSCORE.Config.getExtensionPath() + "/" + extensionID;
  var cmEditor;
  var contentLoaded = false;

  function init(filePath, containerElementID, isViewer) {
    console.log("Initalization Text Editor...");
    $containerElement = $('#' + containerElementID);

    currentFilePath = filePath;
    $containerElement.empty();
    $containerElement.css("background-color" , "white");
    $containerElement.append($('<iframe>', {
      sandbox: "allow-same-origin allow-scripts allow-modals",
      id: "iframeViewer",
      "nwdisable": "",
      "src": extensionDirectory + "/index.html?&locale=" + TSCORE.currentLanguage
    }));

    TSCORE.IO.loadTextFilePromise(filePath).then(function(content) {
      setContent(content);
      viewerMode(isViewer);
    }, function(error) {
      TSCORE.hideLoadingAnimation();
      TSCORE.showAlertDialog("Loading " + filePath + " failed.");
      console.error("Loading file " + filePath + " failed " + error);
    });

    //keys[convertMouseTrapToCodeMirrorKeyBindings(TSCORE.Config.getSaveDocumentKeyBinding())] = function() {
    //  TSCORE.FileOpener.saveFile();
    //};
    //
    //keys[convertMouseTrapToCodeMirrorKeyBindings(TSCORE.Config.getCloseViewerKeyBinding())] = function() {
    //  TSCORE.FileOpener.closeFile();
    //};

    //TSCORE.IO.loadTextFilePromise(filePath).then(function(content) {
    //  exports.setContent(content);
    //},
    //function(error) {
    //  TSCORE.hideLoadingAnimation();
    //  TSCORE.showAlertDialog("Loading " + filePath + " failed.");
    //  console.error("Loading file " + filePath + " failed " + error);
    //});
    //});
  }

  // Converts mod+s to Ctrl+S
  function convertMouseTrapToCodeMirrorKeyBindings(keyBinding) {
    if (keyBinding.indexOf("+") < 0) {
      return;
    }
    var key = keyBinding.split("+");
    if (key[0] === "mod") {
      isOSX ? key[0] = "cmd" : key[0] = "ctrl";
    }
    key[0] = key[0].charAt(0).toUpperCase() + key[0].slice(1);
    return key[0] + "-" + key[1].toUpperCase();
  }

  function viewerMode(isViewerMode) {
    var contentWindow = document.getElementById("iframeViewer").contentWindow;
    if (typeof contentWindow.viewerMode === "function") {
      contentWindow.viewerMode(isViewerMode);
    } else {
      window.setTimeout(function() {
        if (typeof contentWindow.viewerMode === "function") {
          contentWindow.viewerMode(isViewerMode);
        }
      } , 500);
    }
  }

  function setContent(content) {

    var UTF8_BOM = "\ufeff";
    if (content.indexOf(UTF8_BOM) === 0) {
      content = content.substring(1, content.length);
    }

    var contentWindow = document.getElementById("iframeViewer").contentWindow;
    if (typeof contentWindow.setContent === "function") {
      contentWindow.require = require;
      var isViewerMode = true;
      contentWindow.isViewerMode = isViewerMode;
      contentWindow.extensionDirectory = extensionDirectory;
      contentWindow.setContent(content , currentFilePath);
    } else {
      window.setTimeout(function() {
        if (typeof contentWindow.setContent === "function") {
          contentWindow.setContent(content, currentFilePath);
        }
      } , 500);
    }
  }

  function getContent() {

    return cmEditor.getValue();
  }

  exports.init = init;
  exports.getContent = getContent;
  exports.setContent = setContent;
  exports.viewerMode = viewerMode;

});


{'fraction_non_alphanumeric': 0.1445146319453397, 'fraction_numerical': 0.007477117442310171, 'mean_word_length': 3.290929203539823, 'pattern_counts': {'":': 4, '<': 7, '<?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': '2790590', 'n_tokens_mistral': 2422, 'n_tokens_neox': 2347, 'n_words': 434}