<commit_before>define(function(require) {
  var $ = require("jquery");
  var Publisher = require("fc/publisher");
  var ProjectRenameUtility = require("fc/project-rename");
  var KeyHandler = require("fc/bramble-keyhandler");
  var BrambleMenus = require("fc/bramble-menus");
  var Underlay = require("fc/bramble-underlay");
  var FileSystemSync = require("fc/filesystem-sync");
  var Project = require("project/project");
  var analytics = require("analytics");

  var _escKeyHandler;

  var adapting = false;
  var adaptTimeoutMS = 200; // How often we adapt editor bar layout

  function updateLayout(data) {
    $(".filetree-pane-nav").width(data.sidebarWidth);
    $(".editor-pane-nav").width(data.firstPaneWidth);
    $(".preview-pane-nav").width(data.secondPaneWidth);

    // Only adapt the layout every once in a while
    if(!adapting) {
      adapting = true;
      adaptLayout();
      setTimeout(function(){
        adapting = false;
      },adaptTimeoutMS);
    }
  }

  // Adapt each of the pane header elements
  function adaptLayout(){
    $(".nav-container").each(function(){
      adaptElement($(this));
    });
  }

  // Checks if there is enough room for all of the elements inside it
  // Adds a 'narrow' class, in priority order, when there isn't.
  function adaptElement(el){
    var itemCount = el.find("[data-adapt-order]").addClass("narrow").length;

    for(var i = itemCount; i > 0; i--) {
      var item = el.find("[data-adapt-order="+i+"]");
      item.removeClass("narrow");
      if(!hasEnoughRoom(el)) {
        item.addClass("narrow");
      }
    }
  }

  // Checks if the current element has enough room for everything in it
  // by checking if the last visible element is too far to the right.
  function hasEnoughRoom(el) {
    var maxRight = el[0].getBoundingClientRect().width - parseInt(el.css("padding-left"));

    // Finds the last visible first-order child
    var lastEl = false;
    el.find("> *").each(function(){
      if($(this).is(":visible")){
        lastEl = $(this);
      }
    });

    if(lastEl) {
      var parentLeft = el[0].getBoundingClientRect().left;
      var lastElBounds = lastEl[0].getBoundingClientRect();
      var lastElLeft = lastElBounds.left - parentLeft;
      var lastElWidth = lastElBounds.width;
      var lastElRight = lastElLeft + lastElWidth;

      return Math.round(lastElRight) <= Math.round(maxRight);
    } else {
      return true;
    }
  }

  function init(bramble, csrfToken, appUrl) {
    var publisher;
    var locale = $("html")[0].lang;

    // *******ON LOAD
    checkIfMultiFile();
    if(bramble.getLayout())       {updateLayout(bramble.getLayout());}
    if(bramble.getFilename())     {setNavFilename(bramble.getFilename());}
    if(bramble.getPreviewMode())  {activatePreviewMode(bramble.getPreviewMode());}

    //Show sidebar nav if it is present on load
    function checkIfMultiFile() {
      var data = bramble.getLayout();

      if(data.sidebarWidth > 0) {
        // Total width of window
        var total = data.sidebarWidth + data.firstPaneWidth + data.secondPaneWidth;

        // Set width in percent, easier for window resize
        $(".filetree-pane-nav").width(((data.sidebarWidth / total) * 100) + "%");
        $(".editor-pane-nav").width(((data.firstPaneWidth / total) * 100) + "%");
        $(".preview-pane-nav").width(((data.secondPaneWidth / total) * 100) + "%");

        $("#editor-pane-nav-options-menu").hide();
        $("#editor-pane-nav-fileview").hide();
        $(".filetree-pane-nav").css("display", "block");
      }
    }

    // *******EVENTS
    // User bar menu help
    $("#navbar-help").click(function() {
      window.open("https://support.mozilla.org/" + locale + "/products/webmaker/thimble");
    });

    $("#new-project-link").click(function(e) {
      e.preventDefault();
      e.stopPropagation();

      analytics.event("NewProject", {label: "New authenticated project"});

      var queryString = window.location.search;
      var cacheBust = "cacheBust=" + Date.now();
      queryString = queryString === "" ? "?" + cacheBust : queryString + "&" + cacheBust;
      window.location.href = "/" + locale + "/projects/new"  + queryString;
    });
    $("#delete-project-link").click(function() {
      var projectId = Project.getID();

      // TODO: we can do better than this, but let's at least make it harder to lose data.
      if(!window.confirm("{{ deleteProjectConfirmationText }}")) {<commit_msg>Update t o address issue 1647- Add help page to Thimble (#1821)<commit_after>define(function(require) {
  var $ = require("jquery");
  var Publisher = require("fc/publisher");
  var ProjectRenameUtility = require("fc/project-rename");
  var KeyHandler = require("fc/bramble-keyhandler");
  var BrambleMenus = require("fc/bramble-menus");
  var Underlay = require("fc/bramble-underlay");
  var FileSystemSync = require("fc/filesystem-sync");
  var Project = require("project/project");
  var analytics = require("analytics");

  var _escKeyHandler;

  var adapting = false;
  var adaptTimeoutMS = 200; // How often we adapt editor bar layout

  function updateLayout(data) {
    $(".filetree-pane-nav").width(data.sidebarWidth);
    $(".editor-pane-nav").width(data.firstPaneWidth);
    $(".preview-pane-nav").width(data.secondPaneWidth);

    // Only adapt the layout every once in a while
    if(!adapting) {
      adapting = true;
      adaptLayout();
      setTimeout(function(){
        adapting = false;
      },adaptTimeoutMS);
    }
  }

  // Adapt each of the pane header elements
  function adaptLayout(){
    $(".nav-container").each(function(){
      adaptElement($(this));
    });
  }

  // Checks if there is enough room for all of the elements inside it
  // Adds a 'narrow' class, in priority order, when there isn't.
  function adaptElement(el){
    var itemCount = el.find("[data-adapt-order]").addClass("narrow").length;

    for(var i = itemCount; i > 0; i--) {
      var item = el.find("[data-adapt-order="+i+"]");
      item.removeClass("narrow");
      if(!hasEnoughRoom(el)) {
        item.addClass("narrow");
      }
    }
  }

  // Checks if the current element has enough room for everything in it
  // by checking if the last visible element is too far to the right.
  function hasEnoughRoom(el) {
    var maxRight = el[0].getBoundingClientRect().width - parseInt(el.css("padding-left"));

    // Finds the last visible first-order child
    var lastEl = false;
    el.find("> *").each(function(){
      if($(this).is(":visible")){
        lastEl = $(this);
      }
    });

    if(lastEl) {
      var parentLeft = el[0].getBoundingClientRect().left;
      var lastElBounds = lastEl[0].getBoundingClientRect();
      var lastElLeft = lastElBounds.left - parentLeft;
      var lastElWidth = lastElBounds.width;
      var lastElRight = lastElLeft + lastElWidth;

      return Math.round(lastElRight) <= Math.round(maxRight);
    } else {
      return true;
    }
  }

  function init(bramble, csrfToken, appUrl) {
    var publisher;
    var locale = $("html")[0].lang;

    // *******ON LOAD
    checkIfMultiFile();
    if(bramble.getLayout())       {updateLayout(bramble.getLayout());}
    if(bramble.getFilename())     {setNavFilename(bramble.getFilename());}
    if(bramble.getPreviewMode())  {activatePreviewMode(bramble.getPreviewMode());}

    //Show sidebar nav if it is present on load
    function checkIfMultiFile() {
      var data = bramble.getLayout();

      if(data.sidebarWidth > 0) {
        // Total width of window
        var total = data.sidebarWidth + data.firstPaneWidth + data.secondPaneWidth;

        // Set width in percent, easier for window resize
        $(".filetree-pane-nav").width(((data.sidebarWidth / total) * 100) + "%");
        $(".editor-pane-nav").width(((data.firstPaneWidth / total) * 100) + "%");
        $(".preview-pane-nav").width(((data.secondPaneWidth / total) * 100) + "%");

        $("#editor-pane-nav-options-menu").hide();
        $("#editor-pane-nav-fileview").hide();
        $(".filetree-pane-nav").css("display", "block");
      }
    }

    // *******EVENTS
    // User bar menu help
    $("#navbar-help").click(function() {
      window.open("https://github.com/mozilla/thimble.mozilla.org/wiki/Using-Thimble-FAQ");
    });

    $("#new-project-link").click(function(e) {
      e.preventDefault();
      e.stopPropagation();

      analytics.event("NewProject", {label: "New authenticated project"});

      var queryString = window.location.search;
      var cacheBust = "cacheBust=" + Date.now();
      queryString = queryString === "" ? "?" + cacheBust : queryString + "&" + cacheBust;
      window.location.href = "/" + locale + "/projects/new"  + queryString;
    });
    $("#delete-project-link").click(function() {
      var projectId = Project.getID();

      // TODO: we can do better than this, but let's at least make it harder to lose data.
      if(!window.confirm("{{ deleteProjectConfirmationText }}")) {
{'fraction_non_alphanumeric': 0.162442782181534, 'fraction_numerical': 0.004912359048788657, 'mean_word_length': 3.046070460704607, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 2, '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': '3951879', 'n_tokens_mistral': 2834, 'n_tokens_neox': 2726, 'n_words': 617}