<commit_before>///////////////////UTILITY
function util_error(message){
   console.log('%c' +message, 'color: red');
}
window.onerror = function(a,b,c){
  alert(a+'\n'+b+'\n'+c);
}


//DEFAULTS
window.app = {
  url:''
  ,file:''
  ,cifra: {
    id:undefined,
    history:[]
  }
  ,view:{}
  ,pages:{}
  ,collection:{}
  ,router:{}
  ,data:{}
  ,URN:{
      current:'',
      previous:'',
  }
}


///////////////////////////
var get_data = function(){
    var deferred = new $.Deferred();
    try{
        if(navigator.network.connection.type == 'none'){
            alert('get from localstorage');
            var retrievedObject = localStorage.getItem('cifras');
            console.log('localstorage');
            window.app.data.JSON = JSON.parse(retrievedObject);
            deferred.resolve();
        }
        else{
            return $.get( "http://mail.baligena.com/convert_music_stand?download", function( data ) {
                window.app.data.JSON = JSON.parse(data);
                localStorage.setItem('cifras', JSON.stringify(app.data.JSON));
            });
        }
    }
    catch(e){
        alert('Device not ready, should try again');
        deferred.reject();
    }
    return deferred;

}


var get_data2 = function(){
    var deferred = new $.Deferred();
    console.log('internte');
    return $.get( "http://mail.baligena.com/convert_music_stand?download", function( data ) {
                window.app.data.JSON = JSON.parse(data);
                localStorage.setItem('cifras', JSON.stringify(app.data.JSON));
            });
    var retrievedObject = localStorage.getItem('cifras');
    console.log('localstorage');
    window.app.data.JSON = JSON.parse(retrievedObject);
    deferred.resolve();
    return deferred
    // // Retrieve the object from storage
    // var retrievedObject = localStorage.getItem('testObject');

    // console.log('retrievedObject: ', JSON.parse(retrievedObject));

    // alert(JSON.parse(retrievedObject)[0]['date'] );
}


var load_cifras = (/Chrome/i.test(navigator.userAgent) ? get_data2() : get_data());






app.view.page = Backbone.View.extend({
  //DEFAULTS
  el: 'main'
  ,name: 'SET page NAME, CURRENTLY COMING FROM PARENT'
  ,initialize:function(options){
    //initialize runs only once when object is initiated
    this.clear_page();
    this.options = options;
    app.url = document.URL;
    app.file = location.pathname;
    _.bindAll(this, 'render');
    this.render();
  }
  ,set_URN:function(){
    app.URN.previous = app.URN.current;
    app.URN.current = location.hash;
  }
  ,change_page:function(ev){
      $('.controls li').css('background','rgb(0, 26, 3)');

       this.record_history(ev.target.id-1);
       app.cifra.id = ev.target.id-1;
       if(ev.target.className == 'first_line'){
          app.route.navigate('cifra/'+app.cifra.id, {trigger: true});
       }
       else{
          app.route.navigate(ev.target.id, {trigger: true});
          // console.log($(ev.target).html());
          //controls css
          $(ev.target).css('background','grey');
       }
       $('body').animate({ scrollTop: 0 }, 0); //scroll to the top of page

  }
   ,record_history:function(id){ 
       if( isNaN(id) || id == -1){ //only record the cifra pages that has an id set to a number greater than -1
          return false;
       }
       var history =  app.cifra.history;
       var i = history.indexOf(id)
       if( i != -1){ //no duplicates
          history.splice(i, 1);
       }
       history.unshift(id); 
  }
  ,clear_page:function(){
    var deferred = new $.Deferred();
    this.$el.html('');
    deferred.resolve('hello world');
    return deferred;
  }
});

  app.view.controls = app.view.page.extend({
      el: 'body'
      ,events:{
          'click .controls li': 'change_page'
      }
      ,initialize:function(){
          this.draw_controls();
      }
      ,draw_controls:function(){
          this.$el.append('<li class="null"></li>'); //hack that make the control navigation not overlap/clear
          
          this.$el.append('<ul class="controls"></ul>');
          var ul = $('ul.controls');
          ul.append('<li id="">Alpha</li>');      
          ul.append('<li id="history">History</li>');      
          ul.append('<li id="version">v2.0.0</li>');      
      }
  });

app.view.navigation = app.view.page.extend({
   render: function(){
    this.set_URN();
    this.draw_list();
    return this;
  }
  ,draw_list:function(){
    var that = this;
    var i = 1;
    this.collection.each(function(model){
      that.$el.append('<li class="first_line" id=' + i + '>' + model.get('first_line') + '</li>');
      i++;
    });
  }

})


app.view.home_page = app.view.navigation.extend({
  name: 'home' 
   ,events:{
    'click li.first_line': 'change_page'
  }

});

 app.view.history_page = app.view.navigation.extend({<commit_msg>refractor, renamiming, removed old commented code<commit_after>///////////////////UTILITY
function util_error(message){
   console.log('%c' +message, 'color: red');
}
///////////////////////////
window.onerror = function(a,b,c){
  alert(a+'\n'+b+'\n'+c);
}


//DEFAULTS
window.app = {
  url:''
  ,file:''
  ,cifra: {
    id:undefined,
    history:[]
  }
  ,view:{}
  ,pages:{}
  ,collection:{}
  ,router:{}
  ,data:{}
  ,URN:{
      current:'',
      previous:'',
  }
}



var get_data_mobile = function(){
    var deferred = new $.Deferred();
    try{
        if(navigator.network.connection.type == 'none'){
            alert('get from localstorage');
            var retrievedObject = localStorage.getItem('cifras');
            console.log('localstorage');
            window.app.data.JSON = JSON.parse(retrievedObject);
            deferred.resolve();
        }
        else{
            return $.get( "http://mail.baligena.com/convert_music_stand?download", function( data ) {
                window.app.data.JSON = JSON.parse(data);
                localStorage.setItem('cifras', JSON.stringify(app.data.JSON));
            });
        }
    }
    catch(e){
        alert('Device not ready, should try again');
        deferred.reject();
    }
    return deferred;

}


var get_data_browser = function(){
    var deferred = new $.Deferred();
    // console.log('internet');
    return $.get( "http://mail.baligena.com/convert_music_stand?download", function( data ) {
                window.app.data.JSON = JSON.parse(data);
                localStorage.setItem('cifras', JSON.stringify(app.data.JSON));
            });
    // var retrievedObject = localStorage.getItem('cifras');
    // console.log('localstorage');
    // window.app.data.JSON = JSON.parse(retrievedObject);
    // deferred.resolve();
    // return deferred
}


var load_cifras = (/Chrome/i.test(navigator.userAgent) ? get_data_browser() : get_data_mobile());

app.view.page = Backbone.View.extend({
  //DEFAULTS
  el: 'main'
  ,name: 'SET page NAME, CURRENTLY COMING FROM PARENT'
  ,initialize:function(options){
    //initialize runs only once when object is initiated
    this.clear_page();
    this.options = options;
    app.url = document.URL;
    app.file = location.pathname;
    _.bindAll(this, 'render');
    this.render();
  }
  ,set_URN:function(){
    app.URN.previous = app.URN.current;
    app.URN.current = location.hash;
  }
  ,change_page:function(ev){
      $('.controls li').css('background','rgb(0, 26, 3)');

       this.record_history(ev.target.id-1);
       app.cifra.id = ev.target.id-1;
       if(ev.target.className == 'first_line'){
          app.route.navigate('cifra/'+app.cifra.id, {trigger: true});
       }
       else{
          app.route.navigate(ev.target.id, {trigger: true});
          // console.log($(ev.target).html());
          //controls css
          $(ev.target).css('background','grey');
       }
       $('body').animate({ scrollTop: 0 }, 0); //scroll to the top of page

  }
   ,record_history:function(id){ 
       if( isNaN(id) || id == -1){ //only record the cifra pages that has an id set to a number greater than -1
          return false;
       }
       var history =  app.cifra.history;
       var i = history.indexOf(id)
       if( i != -1){ //no duplicates
          history.splice(i, 1);
       }
       history.unshift(id); 
  }
  ,clear_page:function(){
    var deferred = new $.Deferred();
    this.$el.html('');
    deferred.resolve('hello world');
    return deferred;
  }
});

  app.view.controls = app.view.page.extend({
      el: 'body'
      ,events:{
          'click .controls li': 'change_page'
      }
      ,initialize:function(){
          this.draw_controls();
      }
      ,draw_controls:function(){
          this.$el.append('<li class="null"></li>'); //hack that make the control navigation not overlap/clear
          
          this.$el.append('<ul class="controls"></ul>');
          var ul = $('ul.controls');
          //when you add a page route is should automatically be created a page
          ul.append('<li id="">Alpha</li>');      
          ul.append('<li id="history">History</li>');      
          ul.append('<li id="history">Info</li>');      
          ul.append('<li id="version">v2.0.0</li>');      
      }
  });

app.view.nav_list = app.view.page.extend({
   render: function(){
    this.set_URN();
    this.draw_list();
    return this;
  }
  ,draw_list:function(){
    var that = this;
    var i = 1;
    this.collection.each(function(model){
      that.$el.append('<li class="first_line" id=' + i + '>' + model.get('first_line') + '</li>');
      i++;
    });
  }

})


app.view.home_page = app.view.nav_list.extend({
  name: 'home' 
   ,events:{
    'click li.first_line': 'change_page'
  }
});

 app.view.history_page = app.view.nav_list.extend({
{'fraction_non_alphanumeric': 0.18213732576148683, 'fraction_numerical': 0.0036138358286009293, 'mean_word_length': 2.3319573443412454, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7405291', 'n_tokens_mistral': 3184, 'n_tokens_neox': 3069, 'n_words': 584}