<commit_before>define([
  'jquery',
  'underscore',
  'backbone',
  'oh',
  'vent',
  'text!templates/iframe.html'
], function($, _, Backbone, oh, vent, iframeTemplate){
  var iframeView = Backbone.View.extend({
    el: $("#iframe"),
    initialize: function(){
      var template = _.template( iframeTemplate);
      this.$el.html(template({foo: 'bar'}));
      var iframe = this.$el.find("#meta_iframe");
      var that = this;
      that.iframe_logging_in = false
      iframe.on('load', function(){
        //a hack to leave the iframe in iframe login. this makes it easier for the clients??
        var iframe_location = iframe[0].contentWindow.location
        if (iframe_location.hash == '#login' && !(iframe_location.href.match(/navbar\/(.*)/))){
          vent.trigger("route:navlink", 'login');
          vent.trigger('ohmage:error:auth');
          that.iframe_logging_in = true;
        } else {
          if (that.iframe_logging_in) {
            that.iframe_logging_in = false;
            vent.trigger('ohmage:success:auth');
          }
        }
        vent.trigger('iframe:hash');
        $(this.contentWindow).on('hashchange', function(){
          vent.trigger('iframe:hash');
        })  
      });
      vent.on('iframe', this.navigate, this)
      vent.on('iframe:hash', this.hashUpdate, this)
    },
    navigate: function(src){
      console.log('iframe navigating to: '+src);
      this.$el.find('#meta_iframe').attr("src", '/navbar/' + src);
    },
    hashUpdate: function(){
      var iframe = this.$el.find('#meta_iframe');  
      var iframe_href = iframe[0].contentWindow.location;
      var location = iframe[0].contentWindow.location.href.match(/navbar\/(.*)/)
      location = '#'+location[1];
      history.replaceState('', '', location);  
    }
  });
  return iframeView;
});<commit_msg>handle a weird trailing slash edge case<commit_after>define([
  'jquery',
  'underscore',
  'backbone',
  'oh',
  'vent',
  'text!templates/iframe.html'
], function($, _, Backbone, oh, vent, iframeTemplate){
  var iframeView = Backbone.View.extend({
    el: $("#iframe"),
    initialize: function(){
      var template = _.template( iframeTemplate);
      this.$el.html(template({foo: 'bar'}));
      var iframe = this.$el.find("#meta_iframe");
      var that = this;
      that.iframe_logging_in = false
      iframe.on('load', function(){
        //a hack to leave the iframe in iframe login. this makes it easier for the clients??
        var iframe_location = iframe[0].contentWindow.location
        if (iframe_location.hash == '#login' && !(iframe_location.href.match(/navbar\/(.*)/))){
          vent.trigger("route:navlink", 'login');
          vent.trigger('ohmage:error:auth');
          that.iframe_logging_in = true;
        } else {
          if (that.iframe_logging_in) {
            that.iframe_logging_in = false;
            vent.trigger('ohmage:success:auth');
          }
        }
        vent.trigger('iframe:hash');
        $(this.contentWindow).on('hashchange', function(){
          vent.trigger('iframe:hash');
        })  
      });
      vent.on('iframe', this.navigate, this)
      vent.on('iframe:hash', this.hashUpdate, this)
    },
    navigate: function(src){
      console.log('iframe navigating to: '+src);
      // add a ending slash unless it isn't needed.
      // without this, browsers tend to reset the request to add a slash as in:
      // /navbar/campaigns resets to /navbar/campaigns/ (which can also cause a bug in non-https with iframes..)
      if (/(\/|#)/.test(src)) {
        src = src
      } else {
        src = src + '/'
      }
      this.$el.find('#meta_iframe').attr("src", '/navbar/' + src);
    },
    hashUpdate: function(){
      var iframe = this.$el.find('#meta_iframe');  
      var iframe_href = iframe[0].contentWindow.location;
      var location = iframe[0].contentWindow.location.href.match(/navbar\/(.*)/)
      location = '#'+location[1];
      history.replaceState('', '', location);  
    }
  });
  return iframeView;
});
{'fraction_non_alphanumeric': 0.16791044776119404, 'fraction_numerical': 0.001990049751243781, 'mean_word_length': 2.6225225225225226, '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': '3574128', 'n_tokens_mistral': 1297, 'n_tokens_neox': 1210, 'n_words': 259}