<commit_before>/**
 * @file Planet class. Part of the "Age of Space" project.
 * @author github.com/azziliz
 * @author github.com/thyshimrod
 * {@link https://github.com/The-game-craftmen/age-of-space/ Project page}
 * @license MIT
 */

'use strict';
var aos = aos || {};
//debugger;

/**
 * The planet is part of solar system. Player will try to colonize it, according to constraint like breathable air,....
 * Player will certainly need to terraform it.
 *
 * @class
 */
aos.Planet = function () {
    /** @type {number}
     * in Million km2
    */
    this.size = 0;
    /** @type {aos.ressource} */
    this.ressources = [];
    /** @type {aos.ressource} */
    this.ressourcesStored = [];
    /** @type {number} */
    this.landSize = 0;
    /** @type {number} */
    this.population = 0;
    /** @type {number}
     * Indicator calculated to estimate the viability of the planet. Population will grow or not depending of it.
     * 0 : population decreases deadly, 50 : population stagnation, 100 : population grows highly
    */
    this.healtingIndicator = 0;
    /** @type {aos.building} */
    this.buildings=[];
    /** @type {boolean}
     * Planet must be scanned to show planet properties to Player
    */
    this.scanned = false;
};

aos.Planet.prototype = {

    generate: function () {
        this.size = Math.floor(Math.random() * 5) * 150;
        this.landSize = Math.random * this.size;
        this.generateAir();
        this.generateGround();
        this.generateLiquid();
        let b = new aos.Building();
        b.construct("iron Mine");
        this.buildings.push(b);
        b = new aos.Building();
        b.construct("solar plant");
        this.buildings.push(b);
        b = new aos.Building();
        b.construct("CO2 epuration");
        this.buildings.push(b);

    },

    generateAir : function(){
        var compositionPercent = 0;
        for(let i = 0 ; i < aos.ressources.length ; i++){
            if( aos.ressources[i].category == "air"){
                let ressource = new aos.Ressource();
                ressource.type = "air";
                ressource.name = aos.ressources[i].name;
                if ( i == ( aos.ressources.length-1 )){
                    ressource.quantity = 100-compositionPercent;
                }else{
                    let itAirPrcent = Math.floor(Math.random() * (100-compositionPercent))
                    ressource.quantity = itAirPrcent;
                    ressource.percent = itAirPrcent;
                    compositionPercent += itAirPrcent;
                }
                this.ressources.push(ressource);
            }
        }
    },

    generateLiquid : function(){
        var compositionPercent = 0;
        for(let i = 0 ; i < aos.ressources.length ; i++){
            if( aos.ressources[i].category == "liquid"){
                let ressource = new aos.Ressource();
                ressource.type = "liquid";
                ressource.name = aos.ressources[i].name;
                if ( i == ( aos.ressources.length-1 )){
                    ressource.quantity = 100-compositionPercent;
                }else{
                    let itPrcent = Math.floor(Math.random() * (100-compositionPercent))
                    ressource.quantity = itPrcent;
                    compositionPercent += itPrcent;
                }
                this.ressources.push(ressource);
            }
        }
    },

    generateMetal : function(prcent){
        var compositionPercent = 0;
        for( let i = 0 ; i < aos.ressources.length ; i++){
            if( aos.ressources[i].category == "metal"){
                let ressource = new aos.Ressource();
                ressource.type = "metal";
                ressource.name = aos.ressources[i].name;
                if ( i == ( aos.ressources.length-1 )){
                    ressource.quantity = (prcent - compositionPercent) ;
                }else{
                    let itPrcent = Math.floor(Math.random() * (prcent-compositionPercent))
                    ressource.quantity = itPrcent ;
                    compositionPercent += itPrcent;
                }
                this.ressources.push(ressource);
            }
        }
    },

    generateGround : function(){
        var compositionPercent = 0;
        for( let i = 0 ; i < aos.ressources.length ; i++){
            if( aos.ressources[i].category == "ground"){
                let ressource = new aos.Ressource();
                ressource.type = "ground";
                ressource.name = aos.ressources[i].name;
                if ( i == ( aos.ressources.length-1 )){
                    ressource.quantity = 100 - compositionPercent;
                    this.ressources.push(ressource);
                }else{
                    let itPrcent = Math.floor(Math.random() * (100-compositionPercent))
                    if( aos.ressources[i].name == "metal" ){
                        this.generateMetal(itPrcent);
                    }else{
                        ressource.quantity = itPrcent;
                        this.ressources.push(ressource);
                    }
                    compositionPercent += itPrcent;
                }
            }

        }
    },

    calculateHealthIndicator: function(){
        this.healtingIndicator = 70;
    },

    populationGrowing : function(){
        if(this.healtingIndicator > 50){
            this.population += 100000;
        }else{
            this.population -= 100000;
        }
    },

    removeRessource : function(name, quantity,planetRessource){
        let qtyRemoved = 0;
        if (planetRessource){
            for ( let itPlanetRes = 0 ; itPlanetRes < this.ressources.length ; itPlanetRes++ ){
                if ( this.ressources[itPlanetRes].name == name && this.ressources[itPlanetRes].quantity>0){
                    qtyRemoved = ((this.ressources[itPlanetRes].quantity * this. size * 100000) - quantity) > 0 ? quantity : quantity - this.ressources[itPlanetRes].quantity* this. size * 100000;
                    let newPercent = ((this.ressources[itPlanetRes].quantity * this. size * 100000) - qtyRemoved) / (100 * this. size * 100000);
                    this.ressources[itPlanetRes].quantity = newPercent * 100;
                }
            }
        }else{
            for (let itRes = 0 ; itRes < this.ressourcesStored.length ; itRes++){
                if (this.ressourcesStored[itRes].name == name && this.ressourcesStored[itRes].quantity>0 ){
                    qtyRemoved = (this.ressources[itRes].quantity - quantity) > 0 ? quantity : quantity - this.ressources[itRes].quantity;
                    this.ressourcesStored[itRes].quantity -= qtyRemoved;
                }
            }
        }
        return qtyRemoved;
    },

    produce : function(typeProduct){
        for( let itBuilding = 0 ; itBuilding < this.buildings.length ; itBuilding++){
            let building = this.buildings[itBuilding];
            if ( building.type == typeProduct ){
                building.functional = true;
                if (typeof building.production.require !== "undefined"){
                    for ( let itProd = 0 ; itProd < building.production.require.length ; itProd++ ){
                        let removeRes = this.removeRessource(building.production.require[itProd].name,building.production.require[itProd].quantity,building.production.require[itProd].planetRessource);
                        if (removeRes != building.production.require[itProd].quantity) building.functional = false;
                    }
                }
                if ( building.functional){
                    for ( let itPlanetRes = 0 ; itPlanetRes < this.ressources.length ; itPlanetRes++ ){
                        if ( this.ressources[itPlanetRes].name == building.production.from && this.ressources[itPlanetRes].quantity>0){
                            let nbMined = ((this.ressources[itPlanetRes].percent * this. size * aos.volumeRessources[this.ressources[itPlanetRes].type]) - building.production.quantity) > 0 ? building.production.quantity : building.production.quantity - this.ressources[itPlanetRes].percent * this. size * 100000;
                            let newPercent = ((this.ressources[itPlanetRes].percent * this. size * aos.volumeRessources[this.ressources[itPlanetRes].type]) - nbMined) / (100 * this. size * aos.volumeRessources[this.ressources[itPlanetRes].type]);
                            this.ressources[itPlanetRes].percent = newPercent * 100;
                            let findRes = null;
                            let storage = null;
                            if ( building.production.to == "planet"){
                                storage = this.ressources;
                            }else{
                                storage = this.ressourcesStored;
                            }
                            for ( let itRes = 0 ; itRes < storage.length ; itRes ++){
                                if ( storage[itRes].name == building.production.product ){
                                    findRes = storage[itRes];
                                    break;
                                }
                            }
                            if ( findRes == null ){
                                findRes = new aos.Ressource();
                                findRes.name = building.production.product;
                                findRes.type = building.production.type;
                                findRes.quantity = nbMined;
                                findRes.percent = (nbMined) / (100 * this. size * aos.volumeRessources[findRes.type]) * 100;
                                storage.push(findRes);
                            }else{
                                findRes.quantity += nbMined;
                                findRes.percent = ((findRes.percent * this. size * aos.volumeRessources[findRes.type]) + nbMined) / (100 * this. size * aos.volumeRessources[findRes.type]) * 100;
                            }
                            break;
                        }
                    }
                }
            }
        }
    },

    produceEnergy : function(){
      for ( let itBuilding = 0 ; itBuilding < this.buildings.length ; itBuilding++ ){
          let building = this.buildings[itBuilding];
          if ( building.type == "plant" ){
            let findRes = null;
            for ( let itRes = 0 ; itRes < this.ressourcesStored.length ; itRes ++){
                if ( this.ressourcesStored[itRes].name == building.production.product ){
                    findRes = this.ressourcesStored[itRes];
                    break;
                }
            }
            if ( findRes == null ){
                findRes = new aos.Ressource();
                findRes.name = building.production.product;
                findRes.type = building.production.type;
                findRes.quantity = building.production.quantity;
                this.ressourcesStored.push(findRes);
            }else{
                findRes.quantity += building.production.quantity;
            }
          }
      }
    },

    run : function(speedTick){

        this.calculateHealthIndicator();
        this.populationGrowing();
        this.produceEnergy();
        //this.produce("mine");
        this.produce("epurateur");
        this.showStats();
    },

    showPlanetRessources: function(){
        for( let i = 0; i < this.ressources.length ; i++){
            if (this.ressources[i].type == "metal"){
                document.getElementById('p' + this.ressources[i].name + 'Text').innerHTML = Math.floor(this.ressources[i].quantity * this. size * 100000);
            }else if (this.ressources[i].name == "water"){
                document.getElementById('p' + this.ressources[i].name + 'Text').innerHTML = Math.floor(this.ressources[i].quantity * this. size * 100000);
            }

        }
    },

    showStoredRessources : function(){
        for ( let i = 0 ; i < this.ressourcesStored.length ; i++){
            let htmlVar = document.getElementById( this.ressourcesStored[i].name + 'Text');
            if ( htmlVar != null && typeof htmlVar !== "undefined"){
                htmlVar.innerHTML = this.ressourcesStored[i].quantity;
            }
        }
    },

    showStatsAir : function(){
        for( let i = 0; i < this.ressources.length ; i++){
            if ( this.ressources[i].type == "air"){
                document.getElementById('air' + this.ressources[i].name + 'Text').innerHTML = Math.floor(this.ressources[i].percent) + "%";
            }
        }
    },

    showStatsLiquid : function(){
        for( let i = 0; i < this.ressources.length ; i++){
            if ( this.ressources[i].type == "liquid"){
                document.getElementById('liquid' + this.ressources[i].name + 'Text').innerHTML = Math.floor(this.ressources[i].quantity) + "%";
            }
        }
    },

    showStatsGround : function(){
        var metal=0;
        for( let i = 0; i < this.ressources.length ; i++){
            if ( this.ressources[i].type == "ground"){
                document.getElementById('ground' + this.ressources[i].name + 'Text').innerHTML = Math.floor(this.ressources[i].quantity) + "%";
            }else if ( this.ressources[i].type == "metal") metal += this.ressources[i].quantity;
        }
        document.getElementById('groundmetalText').innerHTML = Math.floor(metal) + "%";
    },

    showBuildings : function(){

    },

    showStats : function(){
        document.getElementById('populationTxt').innerHTML = this.population + " colons";
        document.getElementById('healthingTxt').innerHTML = this.healtingIndicator + " %";
        this.showPlanetRessources();
        this.showStoredRessources();
        this.showStatsAir();
        this.showStatsGround();
        this.showStatsLiquid();
        this.showBuildings();
    }

};
var instance = null;
window.onload = function () {
    instance = new aos.Planet();
    instance.generate();
};

window.setInterval(function(){
    instance.run(1);
},500);<commit_msg>constant replacement<commit_after>/**
 * @file Planet class. Part of the "Age of Space" project.
 * @author github.com/azziliz
 * @author github.com/thyshimrod
 * {@link https://github.com/The-game-craftmen/age-of-space/ Project page}
 * @license MIT
 */

'use strict';
var aos = aos || {};
//debugger;

/**
 * The planet is part of solar system. Player will try to colonize it, according to constraint like breathable air,....
 * Player will certainly need to terraform it.
 *
 * @class
 */
aos.Planet = function () {
    /** @type {number}
     * in Million km2
    */
    this.size = 0;
    /** @type {aos.ressource} */
    this.ressources = [];
    /** @type {aos.ressource} */
    this.ressourcesStored = [];
    /** @type {number} */
    this.landSize = 0;
    /** @type {number} */
    this.population = 0;
    /** @type {number}
     * Indicator calculated to estimate the viability of the planet. Population will grow or not depending of it.
     * 0 : population decreases deadly, 50 : population stagnation, 100 : population grows highly
    */
    this.healtingIndicator = 0;
    /** @type {aos.building} */
    this.buildings=[];
    /** @type {boolean}
     * Planet must be scanned to show planet properties to Player
    */
    this.scanned = false;
};

aos.Planet.prototype = {

    generate: function () {
        this.size = Math.floor(Math.random() * 5) * 150;
        this.landSize = Math.random * this.size;
        this.generateAir();
        this.generateGround();
        this.generateLiquid();
        let b = new aos.Building();
        b.construct("iron Mine");
        this.buildings.push(b);
        b = new aos.Building();
        b.construct("solar plant");
        this.buildings.push(b);
        b = new aos.Building();
        b.construct("CO2 epuration");
        this.buildings.push(b);

    },

    generateAir : function(){
        var compositionPercent = 0;
        for(let i = 0 ; i < aos.ressources.length ; i++){
            if( aos.ressources[i].category == "air"){
                let ressource = new aos.Ressource();
                ressource.type = "air";
                ressource.name = aos.ressources[i].name;
                if ( i == ( aos.ressources.length-1 )){
                    ressource.quantity = 100-compositionPercent;
                }else{
                    let itAirPrcent = Math.floor(Math.random() * (100-compositionPercent))
                    ressource.quantity = itAirPrcent;
                    ressource.percent = itAirPrcent;
                    compositionPercent += itAirPrcent;
                }
                this.ressources.push(ressource);
            }
        }
    },

    generateLiquid : function(){
        var compositionPercent = 0;
        for(let i = 0 ; i < aos.ressources.length ; i++){
            if( aos.ressources[i].category == "liquid"){
                let ressource = new aos.Ressource();
                ressource.type = "liquid";
                ressource.name = aos.ressources[i].name;
                if ( i == ( aos.ressources.length-1 )){
                    ressource.quantity = 100-compositionPercent;
                }else{
                    let itPrcent = Math.floor(Math.random() * (100-compositionPercent))
                    ressource.quantity = itPrcent;
                    compositionPercent += itPrcent;
                }
                this.ressources.push(ressource);
            }
        }
    },

    generateMetal : function(prcent){
        var compositionPercent = 0;
        for( let i = 0 ; i < aos.ressources.length ; i++){
            if( aos.ressources[i].category == "metal"){
                let ressource = new aos.Ressource();
                ressource.type = "metal";
                ressource.name = aos.ressources[i].name;
                if ( i == ( aos.ressources.length-1 )){
                    ressource.quantity = (prcent - compositionPercent) ;
                }else{
                    let itPrcent = Math.floor(Math.random() * (prcent-compositionPercent))
                    ressource.quantity = itPrcent ;
                    compositionPercent += itPrcent;
                }
                this.ressources.push(ressource);
            }
        }
    },

    generateGround : function(){
        var compositionPercent = 0;
        for( let i = 0 ; i < aos.ressources.length ; i++){
            if( aos.ressources[i].category == "ground"){
                let ressource = new aos.Ressource();
                ressource.type = "ground";
                ressource.name = aos.ressources[i].name;
                if ( i == ( aos.ressources.length-1 )){
                    ressource.quantity = 100 - compositionPercent;
                    this.ressources.push(ressource);
                }else{
                    let itPrcent = Math.floor(Math.random() * (100-compositionPercent))
                    if( aos.ressources[i].name == "metal" ){
                        this.generateMetal(itPrcent);
                    }else{
                        ressource.quantity = itPrcent;
                        this.ressources.push(ressource);
                    }
                    compositionPercent += itPrcent;
                }
            }

        }
    },

    calculateHealthIndicator: function(){
        this.healtingIndicator = 70;
    },

    populationGrowing : function(){
        if(this.healtingIndicator > 50){
            this.population += 100000;
        }else{
            this.population -= 100000;
        }
    },

    removeRessource : function(name, quantity,planetRessource){
        let qtyRemoved = 0;
        if (planetRessource){
            for ( let itPlanetRes = 0 ; itPlanetRes < this.ressources.length ; itPlanetRes++ ){
                if ( this.ressources[itPlanetRes].name == name && this.ressources[itPlanetRes].quantity>0){
                    qtyRemoved = ((this.ressources[itPlanetRes].quantity * this. size * aos.volumeRessources[this.ressources[itPlanetRes].type]) - quantity) > 0 ? quantity : quantity - this.ressources[itPlanetRes].quantity* this. size * aos.volumeRessources[this.ressources[itPlanetRes].type];
                    let newPercent = ((this.ressources[itPlanetRes].quantity * this. size * aos.volumeRessources[this.ressources[itPlanetRes].type]) - qtyRemoved) / (100 * this. size * aos.volumeRessources[this.ressources[itPlanetRes].type]);
                    this.ressources[itPlanetRes].quantity = newPercent * 100;
                }
            }
        }else{
            for (let itRes = 0 ; itRes < this.ressourcesStored.length ; itRes++){
                if (this.ressourcesStored[itRes].name == name && this.ressourcesStored[itRes].quantity>0 ){
                    qtyRemoved = (this.ressources[itRes].quantity - quantity) > 0 ? quantity : quantity - this.ressources[itRes].quantity;
                    this.ressourcesStored[itRes].quantity -= qtyRemoved;
                }
            }
        }
        return qtyRemoved;
    },

    produce : function(typeProduct){
        for( let itBuilding = 0 ; itBuilding < this.buildings.length ; itBuilding++){
            let building = this.buildings[itBuilding];
            if ( building.type == typeProduct ){
                building.functional = true;
                if (typeof building.production.require !== "undefined"){
                    for ( let itProd = 0 ; itProd < building.production.require.length ; itProd++ ){
                        let removeRes = this.removeRessource(building.production.require[itProd].name,building.production.require[itProd].quantity,building.production.require[itProd].planetRessource);
                        if (removeRes != building.production.require[itProd].quantity) building.functional = false;
                    }
                }
                if ( building.functional){
                    for ( let itPlanetRes = 0 ; itPlanetRes < this.ressources.length ; itPlanetRes++ ){
                        if ( this.ressources[itPlanetRes].name == building.production.from && this.ressources[itPlanetRes].quantity>0){
                            let nbMined = ((this.ressources[itPlanetRes].percent * this. size * aos.volumeRessources[this.ressources[itPlanetRes].type]) - building.production.quantity) > 0 ? building.production.quantity : building.production.quantity - this.ressources[itPlanetRes].percent * this. size * aos.volumeRessources[this.ressources[itPlanetRes].type];
                            let newPercent = ((this.ressources[itPlanetRes].percent * this. size * aos.volumeRessources[this.ressources[itPlanetRes].type]) - nbMined) / (100 * this. size * aos.volumeRessources[this.ressources[itPlanetRes].type]);
                            this.ressources[itPlanetRes].percent = newPercent * 100;
                            let findRes = null;
                            let storage = null;
                            if ( building.production.to == "planet"){
                                storage = this.ressources;
                            }else{
                                storage = this.ressourcesStored;
                            }
                            for ( let itRes = 0 ; itRes < storage.length ; itRes ++){
                                if ( storage[itRes].name == building.production.product ){
                                    findRes = storage[itRes];
                                    break;
                                }
                            }
                            if ( findRes == null ){
                                findRes = new aos.Ressource();
                                findRes.name = building.production.product;
                                findRes.type = building.production.type;
                                findRes.quantity = nbMined;
                                findRes.percent = (nbMined) / (100 * this. size * aos.volumeRessources[findRes.type]) * 100;
                                storage.push(findRes);
                            }else{
                                findRes.quantity += nbMined;
                                findRes.percent = ((findRes.percent * this. size * aos.volumeRessources[findRes.type]) + nbMined) / (100 * this. size * aos.volumeRessources[findRes.type]) * 100;
                            }
                            break;
                        }
                    }
                }
            }
        }
    },

    produceEnergy : function(){
      for ( let itBuilding = 0 ; itBuilding < this.buildings.length ; itBuilding++ ){
          let building = this.buildings[itBuilding];
          if ( building.type == "plant" ){
            let findRes = null;
            for ( let itRes = 0 ; itRes < this.ressourcesStored.length ; itRes ++){
                if ( this.ressourcesStored[itRes].name == building.production.product ){
                    findRes = this.ressourcesStored[itRes];
                    break;
                }
            }
            if ( findRes == null ){
                findRes = new aos.Ressource();
                findRes.name = building.production.product;
                findRes.type = building.production.type;
                findRes.quantity = building.production.quantity;
                this.ressourcesStored.push(findRes);
            }else{
                findRes.quantity += building.production.quantity;
            }
          }
      }
    },

    run : function(speedTick){

        this.calculateHealthIndicator();
        this.populationGrowing();
        this.produceEnergy();
        //this.produce("mine");
        this.produce("epurateur");
        this.showStats();
    },

    showPlanetRessources: function(){
        for( let i = 0; i < this.ressources.length ; i++){
            if (this.ressources[i].type == "metal"){
                document.getElementById('p' + this.ressources[i].name + 'Text').innerHTML = Math.floor(this.ressources[i].quantity * this. size * aos.volumeRessources["metal"]);
            }else if (this.ressources[i].name == "water"){
                document.getElementById('p' + this.ressources[i].name + 'Text').innerHTML = Math.floor(this.ressources[i].quantity * this. size * aos.volumeRessources["liquid"]);
            }

        }
    },

    showStoredRessources : function(){
        for ( let i = 0 ; i < this.ressourcesStored.length ; i++){
            let htmlVar = document.getElementById( this.ressourcesStored[i].name + 'Text');
            if ( htmlVar != null && typeof htmlVar !== "undefined"){
                htmlVar.innerHTML = this.ressourcesStored[i].quantity;
            }
        }
    },

    showStatsAir : function(){
        for( let i = 0; i < this.ressources.length ; i++){
            if ( this.ressources[i].type == "air"){
                document.getElementById('air' + this.ressources[i].name + 'Text').innerHTML = Math.floor(this.ressources[i].percent) + "%";
            }
        }
    },

    showStatsLiquid : function(){
        for( let i = 0; i < this.ressources.length ; i++){
            if ( this.ressources[i].type == "liquid"){
                document.getElementById('liquid' + this.ressources[i].name + 'Text').innerHTML = Math.floor(this.ressources[i].quantity) + "%";
            }
        }
    },

    showStatsGround : function(){
        var metal=0;
        for( let i = 0; i < this.ressources.length ; i++){
            if ( this.ressources[i].type == "ground"){
                document.getElementById('ground' + this.ressources[i].name + 'Text').innerHTML = Math.floor(this.ressources[i].quantity) + "%";
            }else if ( this.ressources[i].type == "metal") metal += this.ressources[i].quantity;
        }
        document.getElementById('groundmetalText').innerHTML = Math.floor(metal) + "%";
    },

    showBuildings : function(){

    },

    showStats : function(){
        document.getElementById('populationTxt').innerHTML = this.population + " colons";
        document.getElementById('healthingTxt').innerHTML = this.healtingIndicator + " %";
        this.showPlanetRessources();
        this.showStoredRessources();
        this.showStatsAir();
        this.showStatsGround();
        this.showStatsLiquid();
        this.showBuildings();
    }

};
var instance = null;
window.onload = function () {
    instance = new aos.Planet();
    instance.generate();
};

window.setInterval(function(){
    instance.run(1);
},500);<|endoftext|>


<commit_before>import React from 'react'
import { inject, observer } from 'mobx-react'
import Checkbox from 'material-ui/Checkbox'

@inject('searchStore')
@inject('tabStore')
@observer
export default class Tab extends React.Component {
  onClick = () => {
    this.focus()
    this.props.tabStore.activate(this.props)
  }

  select = () => {
    this.focus()
    this.props.tabStore.select(this.props)
  }

  focus = () => {
    this.props.searchStore.focus(this.props)
  }

  render () {
    const {
      id,
      title,
      tabStore: { selection }
    } = this.props
    const selected = selection.has(id)
    return (

        <Checkbox
          checked={selected}
          onChange={this.select}
          style={{
            width: '1rem',
            height: '1rem',
            padding: 4
          }}
        />

          {title}

    )
  }
}
<commit_msg>Make Tab respect onFocus event which may trigger by Tab<commit_after>import React from 'react'
import { inject, observer } from 'mobx-react'
import Checkbox from 'material-ui/Checkbox'

@inject('searchStore')
@inject('tabStore')
@observer
export default class Tab extends React.Component {
  onClick = () => {
    this.onFocus()
    this.props.tabStore.activate(this.props)
  }

  select = () => {
    this.onFocus()
    this.props.tabStore.select(this.props)
  }

  onFocus = () => {
    this.props.searchStore.focus(this.props)
  }

  render () {
    const {
      id,
      title,
      tabStore: { selection }
    } = this.props
    const selected = selection.has(id)
    return (

        <Checkbox
          checked={selected}
          onChange={this.select}
          onFocus={this.onFocus}
          style={{
            width: '1rem',
            height: '1rem',
            padding: 4
          }}
        />

          {title}

    )
  }
}
<|endoftext|>


<commit_before>
export const VERSION = '2.3.0-test';

export const CAMERA_NONE         = 0;
export const CAMERA_ORTHOGRAPHIC = 1;
export const CAMERA_PERSPECTIVE  = 2;
export const CAMERA_ANAGLYPH     = 3;

export const CAMERA_OFFSET       = 600;

// preset camera views

export const VIEW_NONE           = 0;
export const VIEW_PLAN           = 1;
export const VIEW_ELEVATION_N    = 2;
export const VIEW_ELEVATION_S    = 3;
export const VIEW_ELEVATION_E    = 4;
export const VIEW_ELEVATION_W    = 5;

// mouse selection operation mode

export const MOUSE_MODE_NORMAL     = 0;
export const MOUSE_MODE_ROUTE_EDIT = 1;
export const MOUSE_MODE_DISTANCE   = 2;
export const MOUSE_MODE_TRACE_EDIT = 3;
export const MOUSE_MODE_ENTRANCES  = 4;

// shading types

export const SHADING_HEIGHT       = 1;
export const SHADING_LENGTH       = 2;
export const SHADING_INCLINATION  = 3;
export const SHADING_CURSOR       = 4;
export const SHADING_SINGLE       = 5;
export const SHADING_SURVEY       = 6;
export const SHADING_OVERLAY      = 7;
export const SHADING_SHADED       = 8;
export const SHADING_RELIEF       = 8;
export const SHADING_DEPTH        = 9;
export const SHADING_PATH         = 10;
export const SHADING_DEPTH_CURSOR = 11;
export const SHADING_DISTANCE     = 13;
export const SHADING_CONTOURS     = 15;
export const SHADING_SURFACE      = 17;
export const SHADING_DUPLICATE    = 18;

// layer tags for scene objects

export const FEATURE_SURVEY        = 0;
export const LEG_CAVE              = 1;
export const LEG_SPLAY             = 2;
export const LEG_SURFACE           = 3;
export const FEATURE_BOX           = 4;
export const FEATURE_SELECTED_BOX  = 5;
export const FEATURE_ENTRANCES     = 6;
export const FEATURE_TERRAIN       = 7;
export const FEATURE_STATIONS      = 8;
export const FEATURE_TRACES        = 9;
export const FACE_WALLS            = 11;
export const FACE_SCRAPS           = 12;
export const LABEL_STATION         = 13;
export const SURVEY_WARNINGS       = 14;
export const LABEL_STATION_COMMENT = 15;
export const CLUSTER_MARKERS       = 16;
export const FEATURE_ENTRANCE_DOTS = 17;
export const FEATURE_GRID          = 18;
export const LEG_DUPLICATE         = 19;

export const WALL_OVAL             = 1; // based on Therion .lox types
export const WALL_SQUARE           = 2;
export const WALL_DIAMOND          = 3;

// bit mask
export const STATION_NORMAL = 1;
export const STATION_ENTRANCE = 2;
export const STATION_XSECT = 4;

export const TERRAIN_BASIC   = 0;
export const TERRAIN_STENCIL = 1;
export const TERRAIN_BLEND   = 2;
<commit_msg>update version number<commit_after>
export const VERSION = '2.3.0';

export const CAMERA_NONE         = 0;
export const CAMERA_ORTHOGRAPHIC = 1;
export const CAMERA_PERSPECTIVE  = 2;
export const CAMERA_ANAGLYPH     = 3;

export const CAMERA_OFFSET       = 600;

// preset camera views

export const VIEW_NONE           = 0;
export const VIEW_PLAN           = 1;
export const VIEW_ELEVATION_N    = 2;
export const VIEW_ELEVATION_S    = 3;
export const VIEW_ELEVATION_E    = 4;
export const VIEW_ELEVATION_W    = 5;

// mouse selection operation mode

export const MOUSE_MODE_NORMAL     = 0;
export const MOUSE_MODE_ROUTE_EDIT = 1;
export const MOUSE_MODE_DISTANCE   = 2;
export const MOUSE_MODE_TRACE_EDIT = 3;
export const MOUSE_MODE_ENTRANCES  = 4;

// shading types

export const SHADING_HEIGHT       = 1;
export const SHADING_LENGTH       = 2;
export const SHADING_INCLINATION  = 3;
export const SHADING_CURSOR       = 4;
export const SHADING_SINGLE       = 5;
export const SHADING_SURVEY       = 6;
export const SHADING_OVERLAY      = 7;
export const SHADING_SHADED       = 8;
export const SHADING_RELIEF       = 8;
export const SHADING_DEPTH        = 9;
export const SHADING_PATH         = 10;
export const SHADING_DEPTH_CURSOR = 11;
export const SHADING_DISTANCE     = 13;
export const SHADING_CONTOURS     = 15;
export const SHADING_SURFACE      = 17;
export const SHADING_DUPLICATE    = 18;

// layer tags for scene objects

export const FEATURE_SURVEY        = 0;
export const LEG_CAVE              = 1;
export const LEG_SPLAY             = 2;
export const LEG_SURFACE           = 3;
export const FEATURE_BOX           = 4;
export const FEATURE_SELECTED_BOX  = 5;
export const FEATURE_ENTRANCES     = 6;
export const FEATURE_TERRAIN       = 7;
export const FEATURE_STATIONS      = 8;
export const FEATURE_TRACES        = 9;
export const FACE_WALLS            = 11;
export const FACE_SCRAPS           = 12;
export const LABEL_STATION         = 13;
export const SURVEY_WARNINGS       = 14;
export const LABEL_STATION_COMMENT = 15;
export const CLUSTER_MARKERS       = 16;
export const FEATURE_ENTRANCE_DOTS = 17;
export const FEATURE_GRID          = 18;
export const LEG_DUPLICATE         = 19;

export const WALL_OVAL             = 1; // based on Therion .lox types
export const WALL_SQUARE           = 2;
export const WALL_DIAMOND          = 3;

// bit mask
export const STATION_NORMAL = 1;
export const STATION_ENTRANCE = 2;
export const STATION_XSECT = 4;

export const TERRAIN_BASIC   = 0;
export const TERRAIN_STENCIL = 1;
export const TERRAIN_BLEND   = 2;
<|endoftext|>


<commit_before>
const supportedCities = require('./supportedCities')
import { redirectTo } from '../navigation/location-redirector'
import { newElement } from '../dom'

const init = (location) => {
  const modal = document.querySelector('.js-location-select-modal')

  if (modal) {
    modal.classList.add('is-active')

    const changeCity = (newCity) => {
      location.setCurrent(newCity)
      redirectTo(newCity)
    }

    document.querySelector('.js-modal-close')
      .addEventListener('click', (e) => {
        modal.classList.remove('is-active')
        changeCity(supportedCities.default().id)
      })

    const dropdown = document.querySelector('.js-modal-location-dropdown')
    dropdown.innerHTML = ''
    dropdown.appendChild(newElement('option', '-- please select --'))

    location
      .getCurrent()
      .then((result) => {
        supportedCities.locations
          .filter((c) => c.isPublic)
          .forEach((c) => {
            const attributes = {
              value: c.id
            }
            if (result.id === c.id) {
              attributes['selected'] = 'selected'
            }
            dropdown.appendChild(newElement('option', c.name, attributes))
          })
      })

    dropdown
      .addEventListener('change', (e) => {
        e.preventDefault()
        const value = e.target.value
        if (value.length) {
          changeCity(value)
        }
      })
  }
}

module.exports = {
  init: init
}
<commit_msg>bin off pre-selecting current location<commit_after>
const supportedCities = require('./supportedCities')
import { redirectTo } from '../navigation/location-redirector'
import { newElement } from '../dom'

const init = (location) => {
  const modal = document.querySelector('.js-location-select-modal')

  if (modal) {
    modal.classList.add('is-active')

    const changeCity = (newCity) => {
      location.setCurrent(newCity)
      redirectTo(newCity)
    }

    document.querySelector('.js-modal-close')
      .addEventListener('click', (e) => {
        modal.classList.remove('is-active')
        changeCity(supportedCities.default().id)
      })

    const dropdown = document.querySelector('.js-modal-location-dropdown')
    dropdown.innerHTML = ''
    dropdown.appendChild(newElement('option', '-- please select --'))

    supportedCities.locations
      .filter((c) => c.isPublic)
      .forEach((c) => {
        const attributes = {
          value: c.id
        }
        dropdown.appendChild(newElement('option', c.name, attributes))
      })

    dropdown
      .addEventListener('change', (e) => {
        e.preventDefault()
        const value = e.target.value
        if (value.length) {
          changeCity(value)
        }
      })
  }
}

module.exports = {
  init: init
}
<|endoftext|>


<commit_before>
const supportedCities = require('./supportedCities')
const browser = require('../browser')
const urlParams = require('../get-url-parameter')

import { newElement } from '../dom'

const init = (location) => {
  const modal = document.querySelector('.js-location-select-modal')

  if (modal) {
    modal.classList.add('is-active')

    const changeCity = (newCity) => {
      location.setCurrent(newCity)
      let currCity = urlParams.parameter('location')
      if (currCity.length > 0) {
        browser.redirect(window.location.href.replace(currCity, newCity))
      } else {
        window.location.reload()
      }
    }

    document.querySelector('.js-modal-close')
      .addEventListener('click', (e) => {
        modal.classList.remove('is-active')
        changeCity(supportedCities.default().id)
      })

    const dropdown = document.querySelector('.js-modal-location-dropdown')
    dropdown.innerHTML = ''
    dropdown.appendChild(newElement('option', '-- please select --'))

    supportedCities.locations
      .filter((c) => c.isPublic)
      .forEach((c) => {
        dropdown.appendChild(newElement('option', c.name, {
          value: c.id
        }))
      })

    dropdown
      .addEventListener('change', (e) => {
        e.preventDefault()
        const value = e.target.value
        if (value.length) {
          changeCity(value)
        }
      })
  }
}

module.exports = {
  init: init
}
<commit_msg>set selected location on modal popup<commit_after>
const supportedCities = require('./supportedCities')
import { redirectTo } from '../navigation/location-redirector'
import { newElement } from '../dom'

const init = (location) => {
  const modal = document.querySelector('.js-location-select-modal')

  if (modal) {
    modal.classList.add('is-active')

    const changeCity = (newCity) => {
      location.setCurrent(newCity)
      redirectTo(newCity)
    }

    document.querySelector('.js-modal-close')
      .addEventListener('click', (e) => {
        modal.classList.remove('is-active')
        changeCity(supportedCities.default().id)
      })

    const dropdown = document.querySelector('.js-modal-location-dropdown')
    dropdown.innerHTML = ''
    dropdown.appendChild(newElement('option', '-- please select --'))

    location
      .getCurrent()
      .then((result) => {
        supportedCities.locations
          .filter((c) => c.isPublic)
          .forEach((c) => {
            const attributes = {
              value: c.id
            }
            if (result.id === c.id) {
              attributes['selected'] = 'selected'
            }
            dropdown.appendChild(newElement('option', c.name, attributes))
          })
      })

    dropdown
      .addEventListener('change', (e) => {
        e.preventDefault()
        const value = e.target.value
        if (value.length) {
          changeCity(value)
        }
      })
  }
}

module.exports = {
  init: init
}
<|endoftext|>


<commit_before>/**
 * Navigation Plugin
 * @version 2.1.0
 * @author Artus Kolanowski
 * @author David Deutsch
 * @license The MIT License (MIT)
 */
;(function($, window, document, undefined) {
	'use strict';

	/**
	 * Creates the navigation plugin.
	 * @class The Navigation Plugin
	 * @param {Owl} carousel - The Owl Carousel.
	 */
	var Navigation = function(carousel) {
		/**
		 * Reference to the core.
		 * @protected
		 * @type {Owl}
		 */
		this._core = carousel;

		/**
		 * Indicates whether the plugin is initialized or not.
		 * @protected
		 * @type {Boolean}
		 */
		this._initialized = false;

		/**
		 * The current paging indexes.
		 * @protected
		 * @type {Array}
		 */
		this._pages = [];

		/**
		 * All DOM elements of the user interface.
		 * @protected
		 * @type {Object}
		 */
		this._controls = {};

		/**
		 * Markup for an indicator.
		 * @protected
		 * @type {Array.<String>}
		 */
		this._templates = [];

		/**
		 * The carousel element.
		 * @type {jQuery}
		 */
		this.$element = this._core.$element;

		/**
		 * Overridden methods of the carousel.
		 * @protected
		 * @type {Object}
		 */
		this._overrides = {
			next: this._core.next,
			prev: this._core.prev,
			to: this._core.to
		};

		/**
		 * All event handlers.
		 * @protected
		 * @type {Object}
		 */
		this._handlers = {
			'prepared.owl.carousel': $.proxy(function(e) {
				if (e.namespace && this._core.settings.dotsData) {
					this._templates.push('
' +
						$(e.content).find('[data-dot]').addBack('[data-dot]').attr('data-dot') + '
');
				}
			}, this),
			'added.owl.carousel': $.proxy(function(e) {
				if (e.namespace && this._core.settings.dotsData) {
					this._templates.splice(e.position, 0, this._templates.pop());
				}
			}, this),
			'remove.owl.carousel': $.proxy(function(e) {
				if (e.namespace && this._core.settings.dotsData) {
					this._templates.splice(e.position, 1);
				}
			}, this),
			'changed.owl.carousel': $.proxy(function(e) {
				if (e.namespace && e.property.name == 'position') {
					this.draw();
				}
			}, this),
			'initialized.owl.carousel': $.proxy(function(e) {
				if (e.namespace && !this._initialized) {
					this._core.trigger('initialize', null, 'navigation');
					this.initialize();
					this.update();
					this.draw();
					this._initialized = true;
					this._core.trigger('initialized', null, 'navigation');
				}
			}, this),
			'refreshed.owl.carousel': $.proxy(function(e) {
				if (e.namespace && this._initialized) {
					this._core.trigger('refresh', null, 'navigation');
					this.update();
					this.draw();
					this._core.trigger('refreshed', null, 'navigation');
				}
			}, this)
		};

		// set default options
		this._core.options = $.extend({}, Navigation.Defaults, this._core.options);

		// register event handlers
		this.$element.on(this._handlers);
	};

	/**
	 * Default options.
	 * @public
	 * @todo Rename `slideBy` to `navBy`
	 */
	Navigation.Defaults = {
		nav: false,
		navText: [ 'prev', 'next' ],
		navSpeed: false,
		navElement: 'div',
		navContainer: false,
		navContainerClass: 'owl-nav',
		navClass: [ 'owl-prev', 'owl-next' ],
		slideBy: 1,
		dotClass: 'owl-dot',
		dotsClass: 'owl-dots',
		dots: true,
		dotsEach: false,
		dotsData: false,
		dotsSpeed: false,
		dotsContainer: false
	};

	/**
	 * Initializes the layout of the plugin and extends the carousel.
	 * @protected
	 */
	Navigation.prototype.initialize = function() {
		var override,
			settings = this._core.settings;

		// create DOM structure for relative navigation
		this._controls.$relative = (settings.navContainer ? $(settings.navContainer)
			: $('
').addClass(settings.navContainerClass).appendTo(this.$element)).addClass('disabled');

		this._controls.$previous = $('<' + settings.navElement + '>')
			.addClass(settings.navClass[0])
			.html(settings.navText[0])
			.prependTo(this._controls.$relative)
			.on('click', $.proxy(function(e) {
				this.prev(settings.navSpeed);
			}, this));
		this._controls.$next = $('<' + settings.navElement + '>')
			.addClass(settings.navClass[1])
			.html(settings.navText[1])
			.appendTo(this._controls.$relative)
			.on('click', $.proxy(function(e) {
				this.next(settings.navSpeed);
			}, this));

		// create DOM structure for absolute navigation
		if (!settings.dotsData) {
			this._templates = [ $('
')
				.addClass(settings.dotClass)
				.append($(''))
				.prop('outerHTML') ];
		}

		this._controls.$absolute = (settings.dotsContainer ? $(settings.dotsContainer)
			: $('
').addClass(settings.dotsClass).appendTo(this.$element)).addClass('disabled');

		this._controls.$absolute.on('click', 'div', $.proxy(function(e) {
			var index = $(e.target).parent().is(this._controls.$absolute)
				? $(e.target).index() : $(e.target).parent().index();

			e.preventDefault();

			this.to(index, settings.dotsSpeed);
		}, this));

		// override public methods of the carousel
		for (override in this._overrides) {
			this._core[override] = $.proxy(this[override], this);
		}
	};

	/**
	 * Destroys the plugin.
	 * @protected
	 */
	Navigation.prototype.destroy = function() {
		var handler, control, property, override;

		for (handler in this._handlers) {
			this.$element.off(handler, this._handlers[handler]);
		}
		for (control in this._controls) {
			if(control === '$relative' && settings.navContainer){
				this._controls[control].html('');
			}else{
				this._controls[control].remove();
			}
		}
		for (override in this.overides) {
			this._core[override] = this._overrides[override];
		}
		for (property in Object.getOwnPropertyNames(this)) {
			typeof this[property] != 'function' && (this[property] = null);
		}
	};

	/**
	 * Updates the internal state.
	 * @protected
	 */
	Navigation.prototype.update = function() {
		var i, j, k,
			lower = this._core.clones().length / 2,
			upper = lower + this._core.items().length,
			maximum = this._core.maximum(true),
			settings = this._core.settings,
			size = settings.center || settings.autoWidth || settings.dotsData
				? 1 : settings.dotsEach || settings.items;

		if (settings.slideBy !== 'page') {
			settings.slideBy = Math.min(settings.slideBy, settings.items);
		}

		if (settings.dots || settings.slideBy == 'page') {
			this._pages = [];

			for (i = lower, j = 0, k = 0; i < upper; i++) {
				if (j >= size || j === 0) {
					this._pages.push({
						start: Math.min(maximum, i - lower),
						end: i - lower + size - 1
					});
					if (Math.min(maximum, i - lower) === maximum) {
						break;
					}
					j = 0, ++k;
				}
				j += this._core.mergers(this._core.relative(i));
			}
		}
	};

	/**
	 * Draws the user interface.
	 * @todo The option `dotsData` wont work.
	 * @protected
	 */
	Navigation.prototype.draw = function() {
		var difference,
			settings = this._core.settings,
			disabled = this._core.items().length <= settings.items,
			index = this._core.relative(this._core.current()),
			loop = settings.loop || settings.rewind;

		this._controls.$relative.toggleClass('disabled', !settings.nav || disabled);

		if (settings.nav) {
			this._controls.$previous.toggleClass('disabled', !loop && index <= this._core.minimum(true));
			this._controls.$next.toggleClass('disabled', !loop && index >= this._core.maximum(true));
		}

		this._controls.$absolute.toggleClass('disabled', !settings.dots || disabled);

		if (settings.dots) {
			difference = this._pages.length - this._controls.$absolute.children().length;

			if (settings.dotsData && difference !== 0) {
				this._controls.$absolute.html(this._templates.join(''));
			} else if (difference > 0) {
				this._controls.$absolute.append(new Array(difference + 1).join(this._templates[0]));
			} else if (difference < 0) {
				this._controls.$absolute.children().slice(difference).remove();
			}

			this._controls.$absolute.find('.active').removeClass('active');
			this._controls.$absolute.children().eq($.inArray(this.current(), this._pages)).addClass('active');
		}
	};

	/**
	 * Extends event data.
	 * @protected
	 * @param {Event} event - The event object which gets thrown.
	 */
	Navigation.prototype.onTrigger = function(event) {
		var settings = this._core.settings;

		event.page = {
			index: $.inArray(this.current(), this._pages),
			count: this._pages.length,
			size: settings && (settings.center || settings.autoWidth || settings.dotsData
				? 1 : settings.dotsEach || settings.items)
		};
	};

	/**
	 * Gets the current page position of the carousel.
	 * @protected
	 * @returns {Number}
	 */
	Navigation.prototype.current = function() {
		var current = this._core.relative(this._core.current());
		return $.grep(this._pages, $.proxy(function(page, index) {
			return page.start <= current && page.end >= current;
		}, this)).pop();
	};

	/**
	 * Gets the current succesor/predecessor position.
	 * @protected
	 * @returns {Number}
	 */
	Navigation.prototype.getPosition = function(successor) {
		var position, length,
			settings = this._core.settings;

		if (settings.slideBy == 'page') {
			position = $.inArray(this.current(), this._pages);
			length = this._pages.length;
			successor ? ++position : --position;
			position = this._pages[((position % length) + length) % length].start;
		} else {
			position = this._core.relative(this._core.current());
			length = this._core.items().length;
			successor ? position += settings.slideBy : position -= settings.slideBy;
		}

		return position;
	};

	/**
	 * Slides to the next item or page.
	 * @public
	 * @param {Number} [speed=false] - The time in milliseconds for the transition.
	 */
	Navigation.prototype.next = function(speed) {
		$.proxy(this._overrides.to, this._core)(this.getPosition(true), speed);
	};

	/**
	 * Slides to the previous item or page.
	 * @public
	 * @param {Number} [speed=false] - The time in milliseconds for the transition.
	 */
	Navigation.prototype.prev = function(speed) {
		$.proxy(this._overrides.to, this._core)(this.getPosition(false), speed);
	};

	/**
	 * Slides to the specified item or page.
	 * @public
	 * @param {Number} position - The position of the item or page.
	 * @param {Number} [speed] - The time in milliseconds for the transition.
	 * @param {Boolean} [standard=false] - Whether to use the standard behaviour or not.
	 */
	Navigation.prototype.to = function(position, speed, standard) {
		var length;

		if (!standard && this._pages.length) {
			length = this._pages.length;
			$.proxy(this._overrides.to, this._core)(this._pages[((position % length) + length) % length].start, speed);
		} else {
			$.proxy(this._overrides.to, this._core)(position, speed);
		}
	};

	$.fn.owlCarousel.Constructor.Plugins.Navigation = Navigation;

})(window.Zepto || window.jQuery, window, document);
<commit_msg>Fix code style<commit_after>/**
 * Navigation Plugin
 * @version 2.1.0
 * @author Artus Kolanowski
 * @author David Deutsch
 * @license The MIT License (MIT)
 */
;(function($, window, document, undefined) {
	'use strict';

	/**
	 * Creates the navigation plugin.
	 * @class The Navigation Plugin
	 * @param {Owl} carousel - The Owl Carousel.
	 */
	var Navigation = function(carousel) {
		/**
		 * Reference to the core.
		 * @protected
		 * @type {Owl}
		 */
		this._core = carousel;

		/**
		 * Indicates whether the plugin is initialized or not.
		 * @protected
		 * @type {Boolean}
		 */
		this._initialized = false;

		/**
		 * The current paging indexes.
		 * @protected
		 * @type {Array}
		 */
		this._pages = [];

		/**
		 * All DOM elements of the user interface.
		 * @protected
		 * @type {Object}
		 */
		this._controls = {};

		/**
		 * Markup for an indicator.
		 * @protected
		 * @type {Array.<String>}
		 */
		this._templates = [];

		/**
		 * The carousel element.
		 * @type {jQuery}
		 */
		this.$element = this._core.$element;

		/**
		 * Overridden methods of the carousel.
		 * @protected
		 * @type {Object}
		 */
		this._overrides = {
			next: this._core.next,
			prev: this._core.prev,
			to: this._core.to
		};

		/**
		 * All event handlers.
		 * @protected
		 * @type {Object}
		 */
		this._handlers = {
			'prepared.owl.carousel': $.proxy(function(e) {
				if (e.namespace && this._core.settings.dotsData) {
					this._templates.push('
' +
						$(e.content).find('[data-dot]').addBack('[data-dot]').attr('data-dot') + '
');
				}
			}, this),
			'added.owl.carousel': $.proxy(function(e) {
				if (e.namespace && this._core.settings.dotsData) {
					this._templates.splice(e.position, 0, this._templates.pop());
				}
			}, this),
			'remove.owl.carousel': $.proxy(function(e) {
				if (e.namespace && this._core.settings.dotsData) {
					this._templates.splice(e.position, 1);
				}
			}, this),
			'changed.owl.carousel': $.proxy(function(e) {
				if (e.namespace && e.property.name == 'position') {
					this.draw();
				}
			}, this),
			'initialized.owl.carousel': $.proxy(function(e) {
				if (e.namespace && !this._initialized) {
					this._core.trigger('initialize', null, 'navigation');
					this.initialize();
					this.update();
					this.draw();
					this._initialized = true;
					this._core.trigger('initialized', null, 'navigation');
				}
			}, this),
			'refreshed.owl.carousel': $.proxy(function(e) {
				if (e.namespace && this._initialized) {
					this._core.trigger('refresh', null, 'navigation');
					this.update();
					this.draw();
					this._core.trigger('refreshed', null, 'navigation');
				}
			}, this)
		};

		// set default options
		this._core.options = $.extend({}, Navigation.Defaults, this._core.options);

		// register event handlers
		this.$element.on(this._handlers);
	};

	/**
	 * Default options.
	 * @public
	 * @todo Rename `slideBy` to `navBy`
	 */
	Navigation.Defaults = {
		nav: false,
		navText: [ 'prev', 'next' ],
		navSpeed: false,
		navElement: 'div',
		navContainer: false,
		navContainerClass: 'owl-nav',
		navClass: [ 'owl-prev', 'owl-next' ],
		slideBy: 1,
		dotClass: 'owl-dot',
		dotsClass: 'owl-dots',
		dots: true,
		dotsEach: false,
		dotsData: false,
		dotsSpeed: false,
		dotsContainer: false
	};

	/**
	 * Initializes the layout of the plugin and extends the carousel.
	 * @protected
	 */
	Navigation.prototype.initialize = function() {
		var override,
			settings = this._core.settings;

		// create DOM structure for relative navigation
		this._controls.$relative = (settings.navContainer ? $(settings.navContainer)
			: $('
').addClass(settings.navContainerClass).appendTo(this.$element)).addClass('disabled');

		this._controls.$previous = $('<' + settings.navElement + '>')
			.addClass(settings.navClass[0])
			.html(settings.navText[0])
			.prependTo(this._controls.$relative)
			.on('click', $.proxy(function(e) {
				this.prev(settings.navSpeed);
			}, this));
		this._controls.$next = $('<' + settings.navElement + '>')
			.addClass(settings.navClass[1])
			.html(settings.navText[1])
			.appendTo(this._controls.$relative)
			.on('click', $.proxy(function(e) {
				this.next(settings.navSpeed);
			}, this));

		// create DOM structure for absolute navigation
		if (!settings.dotsData) {
			this._templates = [ $('
')
				.addClass(settings.dotClass)
				.append($(''))
				.prop('outerHTML') ];
		}

		this._controls.$absolute = (settings.dotsContainer ? $(settings.dotsContainer)
			: $('
').addClass(settings.dotsClass).appendTo(this.$element)).addClass('disabled');

		this._controls.$absolute.on('click', 'div', $.proxy(function(e) {
			var index = $(e.target).parent().is(this._controls.$absolute)
				? $(e.target).index() : $(e.target).parent().index();

			e.preventDefault();

			this.to(index, settings.dotsSpeed);
		}, this));

		// override public methods of the carousel
		for (override in this._overrides) {
			this._core[override] = $.proxy(this[override], this);
		}
	};

	/**
	 * Destroys the plugin.
	 * @protected
	 */
	Navigation.prototype.destroy = function() {
		var handler, control, property, override;

		for (handler in this._handlers) {
			this.$element.off(handler, this._handlers[handler]);
		}
		for (control in this._controls) {
			if (control === '$relative' && settings.navContainer) {
				this._controls[control].html('');
			} else {
				this._controls[control].remove();
			}
		}
		for (override in this.overides) {
			this._core[override] = this._overrides[override];
		}
		for (property in Object.getOwnPropertyNames(this)) {
			typeof this[property] != 'function' && (this[property] = null);
		}
	};

	/**
	 * Updates the internal state.
	 * @protected
	 */
	Navigation.prototype.update = function() {
		var i, j, k,
			lower = this._core.clones().length / 2,
			upper = lower + this._core.items().length,
			maximum = this._core.maximum(true),
			settings = this._core.settings,
			size = settings.center || settings.autoWidth || settings.dotsData
				? 1 : settings.dotsEach || settings.items;

		if (settings.slideBy !== 'page') {
			settings.slideBy = Math.min(settings.slideBy, settings.items);
		}

		if (settings.dots || settings.slideBy == 'page') {
			this._pages = [];

			for (i = lower, j = 0, k = 0; i < upper; i++) {
				if (j >= size || j === 0) {
					this._pages.push({
						start: Math.min(maximum, i - lower),
						end: i - lower + size - 1
					});
					if (Math.min(maximum, i - lower) === maximum) {
						break;
					}
					j = 0, ++k;
				}
				j += this._core.mergers(this._core.relative(i));
			}
		}
	};

	/**
	 * Draws the user interface.
	 * @todo The option `dotsData` wont work.
	 * @protected
	 */
	Navigation.prototype.draw = function() {
		var difference,
			settings = this._core.settings,
			disabled = this._core.items().length <= settings.items,
			index = this._core.relative(this._core.current()),
			loop = settings.loop || settings.rewind;

		this._controls.$relative.toggleClass('disabled', !settings.nav || disabled);

		if (settings.nav) {
			this._controls.$previous.toggleClass('disabled', !loop && index <= this._core.minimum(true));
			this._controls.$next.toggleClass('disabled', !loop && index >= this._core.maximum(true));
		}

		this._controls.$absolute.toggleClass('disabled', !settings.dots || disabled);

		if (settings.dots) {
			difference = this._pages.length - this._controls.$absolute.children().length;

			if (settings.dotsData && difference !== 0) {
				this._controls.$absolute.html(this._templates.join(''));
			} else if (difference > 0) {
				this._controls.$absolute.append(new Array(difference + 1).join(this._templates[0]));
			} else if (difference < 0) {
				this._controls.$absolute.children().slice(difference).remove();
			}

			this._controls.$absolute.find('.active').removeClass('active');
			this._controls.$absolute.children().eq($.inArray(this.current(), this._pages)).addClass('active');
		}
	};

	/**
	 * Extends event data.
	 * @protected
	 * @param {Event} event - The event object which gets thrown.
	 */
	Navigation.prototype.onTrigger = function(event) {
		var settings = this._core.settings;

		event.page = {
			index: $.inArray(this.current(), this._pages),
			count: this._pages.length,
			size: settings && (settings.center || settings.autoWidth || settings.dotsData
				? 1 : settings.dotsEach || settings.items)
		};
	};

	/**
	 * Gets the current page position of the carousel.
	 * @protected
	 * @returns {Number}
	 */
	Navigation.prototype.current = function() {
		var current = this._core.relative(this._core.current());
		return $.grep(this._pages, $.proxy(function(page, index) {
			return page.start <= current && page.end >= current;
		}, this)).pop();
	};

	/**
	 * Gets the current succesor/predecessor position.
	 * @protected
	 * @returns {Number}
	 */
	Navigation.prototype.getPosition = function(successor) {
		var position, length,
			settings = this._core.settings;

		if (settings.slideBy == 'page') {
			position = $.inArray(this.current(), this._pages);
			length = this._pages.length;
			successor ? ++position : --position;
			position = this._pages[((position % length) + length) % length].start;
		} else {
			position = this._core.relative(this._core.current());
			length = this._core.items().length;
			successor ? position += settings.slideBy : position -= settings.slideBy;
		}

		return position;
	};

	/**
	 * Slides to the next item or page.
	 * @public
	 * @param {Number} [speed=false] - The time in milliseconds for the transition.
	 */
	Navigation.prototype.next = function(speed) {
		$.proxy(this._overrides.to, this._core)(this.getPosition(true), speed);
	};

	/**
	 * Slides to the previous item or page.
	 * @public
	 * @param {Number} [speed=false] - The time in milliseconds for the transition.
	 */
	Navigation.prototype.prev = function(speed) {
		$.proxy(this._overrides.to, this._core)(this.getPosition(false), speed);
	};

	/**
	 * Slides to the specified item or page.
	 * @public
	 * @param {Number} position - The position of the item or page.
	 * @param {Number} [speed] - The time in milliseconds for the transition.
	 * @param {Boolean} [standard=false] - Whether to use the standard behaviour or not.
	 */
	Navigation.prototype.to = function(position, speed, standard) {
		var length;

		if (!standard && this._pages.length) {
			length = this._pages.length;
			$.proxy(this._overrides.to, this._core)(this._pages[((position % length) + length) % length].start, speed);
		} else {
			$.proxy(this._overrides.to, this._core)(position, speed);
		}
	};

	$.fn.owlCarousel.Constructor.Plugins.Navigation = Navigation;

})(window.Zepto || window.jQuery, window, document);
<|endoftext|>


<commit_before>import { css } from 'styled-components';

import { deepFreeze } from '../utils';

export const grommet = deepFreeze({
  global: {
    colors: {
      background: '#ffffff',
    },
    font: {
      family: '"San Francisco", "Helvetica Neue", Helvetica, Arial, sans-serif',
    },
  },
  anchor: {
    color: {
      dark: '#FD6FFF',
      light: '#9060EB',
    },
  },
  button: {
    extend: css`
      ${props => !props.plain && 'font-weight: bold;'};
    `,
  },
});
<commit_msg>Added the right system-ui font config for grommet theme. (#2401)<commit_after>import { css } from 'styled-components';

import { deepFreeze } from '../utils';

export const grommet = deepFreeze({
  global: {
    colors: {
      background: '#ffffff',
    },
    font: {
      family:
        '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Fira Sans", "Droid Sans",  "Helvetica Neue", Arial, sans-serif,  "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"',
    },
  },
  anchor: {
    color: {
      dark: '#FD6FFF',
      light: '#9060EB',
    },
  },
  button: {
    extend: css`
      ${props => !props.plain && 'font-weight: bold;'};
    `,
  },
});
<|endoftext|>


<commit_before>/**
 * Truncate string with options for clean break and ellipses
 * @param {string} text to trim
 * @param {number} [chars=100] number of characters to cut at
 * @param {boolean} [clean=true] break on space?
 * @param {boolean} [ellipses=false] add ...

 * @returns {string} truncated text
 */
function truncate({ text, chars = 100, clean = true, ellipses = false }) {
	const a = text.substring(0, chars);
	const end = clean ? a.lastIndexOf(' ') : a.length;
	const b = a.substring(0, end);
	const e = ellipses ? '...' : '';
	return `${b}${e}`;
}

export default truncate;
<commit_msg>fix truncate<commit_after>/**
 * Truncate string with options for clean break and ellipses
 * @param {string} text to trim
 * @param {number} [chars=100] number of characters to cut at
 * @param {boolean} [clean=true] break on space?
 * @param {boolean} [ellipses=false] add ...

 * @returns {string} truncated text
 */
function truncate({ text, chars = 100, clean = true, ellipses = false }) {
	const over = text.length > chars;
	const a = text.substring(0, chars);
	const end = clean ? a.lastIndexOf(' ') : a.length;
	const b = over ? a.substring(0, end) : text;
	const e = over && ellipses ? '...' : '';
	return `${b}${e}`;
}

export default truncate;
<|endoftext|>


<commit_before>'use strict';

var $ = require('jquery'),
  _ = require('underscore'),
  Backbone = require('backbone'),
  PageView = require('../framework/page');

var homeScreen = PageView.extend({

  template: require('../../templates/views/home.hbs'),

  buttonEvents: {
    'button-right': 'goToContacts',
    'button-top': 'scrollUp',
    'button-bottom': 'scrollDown'
  },

  goToContacts: function(e) {
    window.location.hash = '/contacts';
  },

  scrollUp: function() {
    $('#watch-face').animate({scrollTop: '+=70px'});
  },

  scrollDown: function() {
    $('#watch-face').animate({scrollTop: '-=70px'});
  },

  render: function() {

    this.$el.html(this.template());

    return this;

  }

});

module.exports = homeScreen;
<commit_msg>Unnatural scrolling<commit_after>'use strict';

var $ = require('jquery'),
  _ = require('underscore'),
  Backbone = require('backbone'),
  PageView = require('../framework/page');

var homeScreen = PageView.extend({

  template: require('../../templates/views/home.hbs'),

  buttonEvents: {
    'button-right': 'goToContacts',
    'button-top': 'scrollUp',
    'button-bottom': 'scrollDown'
  },

  goToContacts: function(e) {
    window.location.hash = '/contacts';
  },

  scrollUp: function() {
    $('#watch-face').animate({scrollTop: '-=70px'});
  },

  scrollDown: function() {
    $('#watch-face').animate({scrollTop: '+=70px'});
  },

  render: function() {

    this.$el.html(this.template());

    return this;

  }

});

module.exports = homeScreen;
<|endoftext|>