<commit_before>var NUM_COLUMNS = 12;

/*----------------------------------------------------------------------------------------------------------------------------------*/
function p_div_new(performance) {

  var div = document.createElement("div");
  div.id = makeid(20);
  var name = performance.name;

  div.comm = comm_new(div, performance.name); //Create comm object for communictiation with the server.
  performance.comm = div.comm;

  performance.add_notify_rank(p_div_rank_updated, div);
  performance.add_notify_score(p_div_score_updated, div);

  var row = document.createElement("div");
  row.className = 'row';
  var column = document.createElement('div');
  column.className = 'small-11 columns';
  column.innerHTML = "
 " + name + "
";
  row.appendChild(column);

  var column = document.createElement("div");
  column.className = 'small-1 columns';

  var remove_me = make_remove_me_div(div);
  column.appendChild(remove_me);
  row.appendChild(column);

  div.appendChild(row);

  div.column_length = {Judges: slam.num_judges, Time: 2, Penalty: 1, Score: 1, Subscore: 1, Rank:1};
  div.titles = ["Judges", "Time", "Penalty", "", "", ""];
  p_div_build_columns_hash(div);

  div.performance = performance;

  p_div_build_titles_row(div);
  p_div_build_sub_titles(div);
  p_div_build_data_row(div);
  p_div_build_footers(div);

  div.style.backgroundColor = '#F4F4F4';
  div.style.borderStyle = 'solid';
  div.style.borderWidth = '1px';

  row = document.createElement("div");
  row.className = "row";

  /*
  column = document.createElement("div");
  column.className = "small-12 columns";
  column.style.minHeight = "15px"; //http://stackoverflow.com/a/25431669

  row.appendChild(column);
  div.appendChild(row);
  */

  row = document.createElement("div");
  row.className = "row";

  column = document.createElement("div");
  column.className = "small-2 columns";
  column.style.color = "blue";
  column.innerHTML = "
 Score:
";
  row.appendChild(column);

  div.score_column = document.createElement("div");
  div.score_column.className = "small-2 columns";
  div.score_column.innerHTML = "";
  row.appendChild(div.score_column);

  if (div.performance.prev != null) {

    column = document.createElement("div");
    column.className = "small-2 columns";
    column.style.color = "blue";
    column.innerHTML = "
 Total:
";
    row.appendChild(column);

    div.cumulative_column = document.createElement("div");
    div.cumulative_column.className = "small-2 columns";
    div.cumulative_column.innerHTML = "";
    row.appendChild(div.cumulative_column);

  }

  column = document.createElement("div");
  column.className = "small-2 columns";
  column.style.color = "blue";
  column.innerHTML = "
 Rank:
";
  row.appendChild(column);

  div.rank_column = document.createElement("div");
  div.rank_column.className = "small-2 columns end";
  div.rank_column.innerHTML = "";
  row.appendChild(div.rank_column);

  div.appendChild(row);

  return div;
}

/*----------------------------------------------------------------------------------------------------------------------------------*/
function p_div_build_columns_hash(div) {

  var num_columns = 12;

  var columns = div.columns = {};
  var titles = div.titles;

  var remaining_columns = num_columns;
  for (var i=0; i<titles.length; i++) {
    columns[titles[i]] = remaining_columns;
    remaining_columns -= div.column_length[titles[i]];

    if (i > 0) {
      for (j=0; j<i; j++) {
	columns[titles[j]] = div.column_length[titles[j]];
      }
    }
  }
}
/*----------------------------------------------------------------------------------------------------------------------------------*/
function p_div_build_titles_row(div) {

  var row = document.createElement("div");
  row.className = "row";

  for (var i=0; i<div.titles.length; i++) {

    var column = document.createElement("div");
    column.className = "small-" + div.columns[div.titles[i]] + " columns";
    column.innerHTML = "" + div.titles[i] + "";

    row.appendChild(column);

  }
  div.appendChild(row);
}
/*----------------------------------------------------------------------------------------------------------------------------------*/
function p_div_build_sub_titles(div) {

  var num_columns = 12;

  var row = document.createElement("div");
  row.className = "row";

  // Add Judges
  var column;
  for (var i=0; i<slam.num_judges; i++) {

    column = document.createElement("div");

    column.className = "small-1 columns";
    column.innerHTML = "" + (i + 1) + "";

    row.appendChild(column);
  }
  // Add Time
  column = document.createElement("div");
  column.className = "small-1 columns";
  column.innerHTML = "m";
  row.appendChild(column);

  column = document.createElement("div");
  column.className = "small-1 columns end";
  column.innerHTML = "s";
  row.appendChild(column);

  div.appendChild(row);
}

/*----------------------------------------------------------------------------------------------------------------------------------*/
function p_div_setup_indexes(div) {

  div.data_columns = [];
  div.indexes = {};

  var i = slam.num_judges;

  div.indexes.minutes_i = i++;
  div.indexes.seconds_i = i++;
  div.indexes.penalty_i = i++;
  div.indexes.score_i = i++;
  div.indexes.subscore_i = i++;
  div.indexes.rank = i;
}
/*----------------------------------------------------------------------------------------------------------------------------------*/
function format_value(value) {

  // Return a value that has at most one decimal place.
  return Math.round(value * 100) / 100;
}
/*----------------------------------------------------------------------------------------------------------------------------------*/
function p_div_update_data_column(div, index, value) {
  div.data_columns[index].innerHTML = format_value(value);

  // Why bother displaying subscore when it equals score?
  if (div.performance.prev == null)
    div.data_columns[div.indexes.subscore_i].innerHTML = '';
}

/*----------------------------------------------------------------------------------------------------------------------------------*/
function p_div_score_updated(div, performance) {

  //p_div_update_data_column(div, div.indexes.score_i, performance.score);
  //p_div_update_data_column(div, div.indexes.subscore_i, performance.subscore);

  div.score_column.innerHTML = format_value(performance.score);

  if (div.performance.prev != null)
    div.cumulative_column.innerHTML = format_value(performance.subscore);

  var min_i = performance.min_judge;
  var max_i = performance.max_judge;

  if (slam.do_not_include_min_and_max_scores) {
    for (var i=0; i<slam.num_judges; i++) {
      div.footers[i].innerHTML = "

";
      div.data_columns[i].style.color = "black";
    }

    var min_max_color = "darkviolet";

    var low_str = "
L

LOW
";
    var high_str = "
H

HIGH
";

    div.data_columns[min_i].style.color = min_max_color;
    div.data_columns[max_i].style.color = min_max_color;

    div.footers[min_i].innerHTML = low_str;
    div.footers[min_i].style.color = min_max_color;

    div.footers[max_i].innerHTML = high_str;
    div.footers[max_i].style.color = min_max_color;
  }
  // Time Penalty

  var time_penalty = performance.calculate_time_penalty() * -1;
  if (time_penalty != 0){
    div.footers[slam.num_judges].innerHTML = "P:";
    div.footers[slam.num_judges].style.color = "green";
    div.footers[slam.num_judges + 1].innerHTML = time_penalty;
    div.footers[slam.num_judges + 1].style.color = "green";
  }
  else {
    div.footers[slam.num_judges].innerHTML = "

";
    div.footers[slam.num_judges + 1].innerHTML = "

";
  }
}
/*----------------------------------------------------------------------------------------------------------------------------------*/
function p_div_rank_updated (div, performance) {

  //div.data_columns[div.indexes.rank].innerHTML = performance.rank;

  div.rank_column.innerHTML = performance.rank;

  div.footers[div.indexes.score_i].innerHTML = performance.is_tied ? "tie" : "";

}
/*----------------------------------------------------------------------------------------------------------------------------------*/
function p_div_get_time(div) {

  var minutes = parse_int_or_return_zero(div.data_columns[div.indexes.minutes_i].value);
  var seconds = parse_int_or_return_zero(div.data_columns[div.indexes.seconds_i].value);

  return {minutes: minutes, seconds: seconds};
}

/*----------------------------------------------------------------------------------------------------------------------------------*/
function p_div_input_entered(input) {

  if (!login_info.is_logged_in)
    return;

  var i = parseInt(input.getAttribute('data-index'));
  var div = input.div;
  var performance = div.performance;

  var value = parse_float_or_return_zero(input.value);

  switch (i)
  {
    case div.indexes.minutes_i:
    case div.indexes.seconds_i:
      var time = p_div_get_time(div);
      performance.set_time(time.minutes, time.seconds);
      set_time_request(performance.comm, time.minutes, time.seconds);
      break;
    case div.indexes.penalty_i:
      performance.set_penalty(value);
      set_penalty_request(performance.comm, value);
      break;
    default:
      if (i >= 0 && i < div.indexes.minutes_i) {
	var value = input.value /= 10;
	input.value = value;
	performance.judge(i, value);
	judge_request(performance.comm, i, value);
      }
  }
}

/*----------------------------------------------------------------------------------------------------------------------------------*/
function p_div_set_score(p_div, judge_i, value) {

  p_div.data_columns[judge_i].value = value;
  p_div.performance.judge(judge_i, value);
}

/*----------------------------------------------------------------------------------------------------------------------------------*/
function p_div_set_time(p_div, minutes, seconds) {

  var i = p_div.indexes.minutes_i;

  p_div.data_columns[i].value = minutes;
  p_div.data_columns[++i].value = seconds;

  p_div.performance.set_time(minutes, seconds);
}

/*----------------------------------------------------------------------------------------------------------------------------------*/
function p_div_set_penalty(p_div, value) {

  var i = p_div.indexes.penalty_i;

  p_div.data_columns[i].value = value;

  p_div.performance.set_penalty(value);
}
/*----------------------------------------------------------------------------------------------------------------------------------*/
function p_div_build_data_row(div) {

  p_div_setup_indexes(div);

  var row = document.createElement("div");
  row.className = "row";

  var num_columns = slam.num_judges + 3; // Judges + Minutes + Seconds + Penalty

  var i;
  for (i=0; i<num_columns; i++) {
    var column = document.createElement("div");
    column.className = "small-1 columns";

    var input = document.createElement("input");
    input.div = div;
    input.className =  "scorekeeper_input";
    input.setAttribute('size', 4);
    input.setAttribute('onchange', 'p_div_input_entered(this)');
    input.setAttribute('data-index', i);
    input.type = "number";
    input.style.width = "60px";

    if (!login_info.is_logged_in)
      input.setAttribute('readonly', null);

    column.appendChild(input);
    div.data_columns.push(input);

    row.appendChild(column);
  }

  num_columns = 12;
  for (; i< num_columns; i++) {

    var column = document.createElement("div");
    column.className = "small-1 columns";
    row.appendChild(column);

    div.data_columns.push(column);
  }

  div.appendChild(row);
}
/*----------------------------------------------------------------------------------------------------------------------------------*/
function p_div_build_footers(div) {

  div.footers = [];

  var num_columns = 12;
  var row = document.createElement("div");
  row.className = "row";

  for (var i=0; i<num_columns; i++) {

    var column = document.createElement("div");
    column.className = "small-1 columns";
    column.innerHTML = "

";

    row.appendChild(column);
    div.footers.push(column);
  }

  div.appendChild(row);
}
/*----------------------------------------------------------------------------------------------------------------------------------*/

<commit_msg>Adjusting column sizes for Score, Total, and Rank in medium screen size.<commit_after>var NUM_COLUMNS = 12;

/*----------------------------------------------------------------------------------------------------------------------------------*/
function p_div_new(performance) {

  var div = document.createElement("div");
  div.id = makeid(20);
  var name = performance.name;

  div.comm = comm_new(div, performance.name); //Create comm object for communictiation with the server.
  performance.comm = div.comm;

  performance.add_notify_rank(p_div_rank_updated, div);
  performance.add_notify_score(p_div_score_updated, div);

  var row = document.createElement("div");
  row.className = 'row';
  var column = document.createElement('div');
  column.className = 'small-11 columns';
  column.innerHTML = "
 " + name + "
";
  row.appendChild(column);

  var column = document.createElement("div");
  column.className = 'small-1 columns';

  var remove_me = make_remove_me_div(div);
  column.appendChild(remove_me);
  row.appendChild(column);

  div.appendChild(row);

  div.column_length = {Judges: slam.num_judges, Time: 2, Penalty: 1, Score: 1, Subscore: 1, Rank:1};
  div.titles = ["Judges", "Time", "Penalty", "", "", ""];
  p_div_build_columns_hash(div);

  div.performance = performance;

  p_div_build_titles_row(div);
  p_div_build_sub_titles(div);
  p_div_build_data_row(div);
  p_div_build_footers(div);

  div.style.backgroundColor = '#F4F4F4';
  div.style.borderStyle = 'solid';
  div.style.borderWidth = '1px';

  row = document.createElement("div");
  row.className = "row";

  /*
  column = document.createElement("div");
  column.className = "small-12 columns";
  column.style.minHeight = "15px"; //http://stackoverflow.com/a/25431669

  row.appendChild(column);
  div.appendChild(row);
  */

  row = document.createElement("div");
  row.className = "row";

  column = document.createElement("div");
  column.className = "small-2 medium-1 columns";
  column.style.color = "blue";
  column.innerHTML = "
 Score:
";
  row.appendChild(column);

  div.score_column = document.createElement("div");
  div.score_column.className = "small-2 medium-1 columns";
  div.score_column.innerHTML = "";
  row.appendChild(div.score_column);

  if (div.performance.prev != null) {

    column = document.createElement("div");
    column.className = "small-2 medium-1 columns";
    column.style.color = "blue";
    column.innerHTML = "
 Total:
";
    row.appendChild(column);

    div.cumulative_column = document.createElement("div");
    div.cumulative_column.className = "small-2 medium-1 columns";
    div.cumulative_column.innerHTML = "";
    row.appendChild(div.cumulative_column);

  }

  column = document.createElement("div");
  column.className = "small-2 medium-1 columns";
  column.style.color = "blue";
  column.innerHTML = "
 Rank:
";
  row.appendChild(column);

  div.rank_column = document.createElement("div");
  div.rank_column.className = "small-2 medium-1 columns end";
  div.rank_column.innerHTML = "";
  row.appendChild(div.rank_column);

  div.appendChild(row);

  return div;
}

/*----------------------------------------------------------------------------------------------------------------------------------*/
function p_div_build_columns_hash(div) {

  var num_columns = 12;

  var columns = div.columns = {};
  var titles = div.titles;

  var remaining_columns = num_columns;
  for (var i=0; i<titles.length; i++) {
    columns[titles[i]] = remaining_columns;
    remaining_columns -= div.column_length[titles[i]];

    if (i > 0) {
      for (j=0; j<i; j++) {
	columns[titles[j]] = div.column_length[titles[j]];
      }
    }
  }
}
/*----------------------------------------------------------------------------------------------------------------------------------*/
function p_div_build_titles_row(div) {

  var row = document.createElement("div");
  row.className = "row";

  for (var i=0; i<div.titles.length; i++) {

    var column = document.createElement("div");
    column.className = "small-" + div.columns[div.titles[i]] + " columns";
    column.innerHTML = "" + div.titles[i] + "";

    row.appendChild(column);

  }
  div.appendChild(row);
}
/*----------------------------------------------------------------------------------------------------------------------------------*/
function p_div_build_sub_titles(div) {

  var num_columns = 12;

  var row = document.createElement("div");
  row.className = "row";

  // Add Judges
  var column;
  for (var i=0; i<slam.num_judges; i++) {

    column = document.createElement("div");

    column.className = "small-1 columns";
    column.innerHTML = "" + (i + 1) + "";

    row.appendChild(column);
  }
  // Add Time
  column = document.createElement("div");
  column.className = "small-1 columns";
  column.innerHTML = "m";
  row.appendChild(column);

  column = document.createElement("div");
  column.className = "small-1 columns end";
  column.innerHTML = "s";
  row.appendChild(column);

  div.appendChild(row);
}

/*----------------------------------------------------------------------------------------------------------------------------------*/
function p_div_setup_indexes(div) {

  div.data_columns = [];
  div.indexes = {};

  var i = slam.num_judges;

  div.indexes.minutes_i = i++;
  div.indexes.seconds_i = i++;
  div.indexes.penalty_i = i++;
  div.indexes.score_i = i++;
  div.indexes.subscore_i = i++;
  div.indexes.rank = i;
}
/*----------------------------------------------------------------------------------------------------------------------------------*/
function format_value(value) {

  // Return a value that has at most one decimal place.
  return Math.round(value * 100) / 100;
}
/*----------------------------------------------------------------------------------------------------------------------------------*/
function p_div_update_data_column(div, index, value) {
  div.data_columns[index].innerHTML = format_value(value);

  // Why bother displaying subscore when it equals score?
  if (div.performance.prev == null)
    div.data_columns[div.indexes.subscore_i].innerHTML = '';
}

/*----------------------------------------------------------------------------------------------------------------------------------*/
function p_div_score_updated(div, performance) {

  //p_div_update_data_column(div, div.indexes.score_i, performance.score);
  //p_div_update_data_column(div, div.indexes.subscore_i, performance.subscore);

  div.score_column.innerHTML = format_value(performance.score);

  if (div.performance.prev != null)
    div.cumulative_column.innerHTML = format_value(performance.subscore);

  var min_i = performance.min_judge;
  var max_i = performance.max_judge;

  if (slam.do_not_include_min_and_max_scores) {
    for (var i=0; i<slam.num_judges; i++) {
      div.footers[i].innerHTML = "

";
      div.data_columns[i].style.color = "black";
    }

    var min_max_color = "darkviolet";

    var low_str = "
L

LOW
";
    var high_str = "
H

HIGH
";

    div.data_columns[min_i].style.color = min_max_color;
    div.data_columns[max_i].style.color = min_max_color;

    div.footers[min_i].innerHTML = low_str;
    div.footers[min_i].style.color = min_max_color;

    div.footers[max_i].innerHTML = high_str;
    div.footers[max_i].style.color = min_max_color;
  }
  // Time Penalty

  var time_penalty = performance.calculate_time_penalty() * -1;
  if (time_penalty != 0){
    div.footers[slam.num_judges].innerHTML = "P:";
    div.footers[slam.num_judges].style.color = "green";
    div.footers[slam.num_judges + 1].innerHTML = time_penalty;
    div.footers[slam.num_judges + 1].style.color = "green";
  }
  else {
    div.footers[slam.num_judges].innerHTML = "

";
    div.footers[slam.num_judges + 1].innerHTML = "

";
  }
}
/*----------------------------------------------------------------------------------------------------------------------------------*/
function p_div_rank_updated (div, performance) {

  //div.data_columns[div.indexes.rank].innerHTML = performance.rank;

  div.rank_column.innerHTML = performance.rank;

  div.footers[div.indexes.score_i].innerHTML = performance.is_tied ? "tie" : "";

}
/*----------------------------------------------------------------------------------------------------------------------------------*/
function p_div_get_time(div) {

  var minutes = parse_int_or_return_zero(div.data_columns[div.indexes.minutes_i].value);
  var seconds = parse_int_or_return_zero(div.data_columns[div.indexes.seconds_i].value);

  return {minutes: minutes, seconds: seconds};
}

/*----------------------------------------------------------------------------------------------------------------------------------*/
function p_div_input_entered(input) {

  if (!login_info.is_logged_in)
    return;

  var i = parseInt(input.getAttribute('data-index'));
  var div = input.div;
  var performance = div.performance;

  var value = parse_float_or_return_zero(input.value);

  switch (i)
  {
    case div.indexes.minutes_i:
    case div.indexes.seconds_i:
      var time = p_div_get_time(div);
      performance.set_time(time.minutes, time.seconds);
      set_time_request(performance.comm, time.minutes, time.seconds);
      break;
    case div.indexes.penalty_i:
      performance.set_penalty(value);
      set_penalty_request(performance.comm, value);
      break;
    default:
      if (i >= 0 && i < div.indexes.minutes_i) {
	var value = input.value /= 10;
	input.value = value;
	performance.judge(i, value);
	judge_request(performance.comm, i, value);
      }
  }
}

/*----------------------------------------------------------------------------------------------------------------------------------*/
function p_div_set_score(p_div, judge_i, value) {

  p_div.data_columns[judge_i].value = value;
  p_div.performance.judge(judge_i, value);
}

/*----------------------------------------------------------------------------------------------------------------------------------*/
function p_div_set_time(p_div, minutes, seconds) {

  var i = p_div.indexes.minutes_i;

  p_div.data_columns[i].value = minutes;
  p_div.data_columns[++i].value = seconds;

  p_div.performance.set_time(minutes, seconds);
}

/*----------------------------------------------------------------------------------------------------------------------------------*/
function p_div_set_penalty(p_div, value) {

  var i = p_div.indexes.penalty_i;

  p_div.data_columns[i].value = value;

  p_div.performance.set_penalty(value);
}
/*----------------------------------------------------------------------------------------------------------------------------------*/
function p_div_build_data_row(div) {

  p_div_setup_indexes(div);

  var row = document.createElement("div");
  row.className = "row";

  var num_columns = slam.num_judges + 3; // Judges + Minutes + Seconds + Penalty

  var i;
  for (i=0; i<num_columns; i++) {
    var column = document.createElement("div");
    column.className = "small-1 columns";

    var input = document.createElement("input");
    input.div = div;
    input.className =  "scorekeeper_input";
    input.setAttribute('size', 4);
    input.setAttribute('onchange', 'p_div_input_entered(this)');
    input.setAttribute('data-index', i);
    input.type = "number";
    input.style.width = "60px";

    if (!login_info.is_logged_in)
      input.setAttribute('readonly', null);

    column.appendChild(input);
    div.data_columns.push(input);

    row.appendChild(column);
  }

  num_columns = 12;
  for (; i< num_columns; i++) {

    var column = document.createElement("div");
    column.className = "small-1 columns";
    row.appendChild(column);

    div.data_columns.push(column);
  }

  div.appendChild(row);
}
/*----------------------------------------------------------------------------------------------------------------------------------*/
function p_div_build_footers(div) {

  div.footers = [];

  var num_columns = 12;
  var row = document.createElement("div");
  row.className = "row";

  for (var i=0; i<num_columns; i++) {

    var column = document.createElement("div");
    column.className = "small-1 columns";
    column.innerHTML = "

";

    row.appendChild(column);
    div.footers.push(column);
  }

  div.appendChild(row);
}
/*----------------------------------------------------------------------------------------------------------------------------------*/

<|endoftext|>


<commit_before>/* eslint-disable no-undef */
require('typeface-roboto')

import { createBrowserHistory } from 'history'
import React from 'react'
import ReactDOM from 'react-dom'

import configureStore from './store.js'
import { lcaInit } from './ducks/actions.js'

import RootContainer from './containers/rootContainer.jsx'

const store = configureStore()

store.dispatch(lcaInit())

ReactDOM.render(
  <RootContainer store={store} history={history} />,
  document.getElementById('root')
)
<commit_msg>Fix error with History<commit_after>/* eslint-disable no-undef */
require('typeface-roboto')

import { createBrowserHistory } from 'history'
import React from 'react'
import ReactDOM from 'react-dom'

import configureStore from './store.js'
import { lcaInit } from './ducks/actions.js'

import RootContainer from './containers/rootContainer.jsx'

export const history = createBrowserHistory()

const store = configureStore()

store.dispatch(lcaInit())

ReactDOM.render(
  <RootContainer store={store} history={history} />,
  document.getElementById('root')
)
<|endoftext|>


<commit_before>// -------------------------------------------------------------------------- \\
// File: PopOverView.js                                                       \\
// Module: PanelViews                                                         \\
// Requires: Core, Foundation, DOM, View                                      \\
// Author: Neil Jenkins                                                       \\
// License: © 2010–2013 FastMail Pty Ltd. All rights reserved.                \\
// -------------------------------------------------------------------------- \\

"use strict";

( function ( NS ) {

var PopOverView = NS.Class({

    Extends: NS.View,

    className: 'PopOverView',

    positioning: 'absolute',

    isVisible: false,
    parentPopOverView: null,

    /*
        Options
        - view -> The view to append to the pop over
        - alignWithView -> the view to align to
        - atNode -> the node within the view to align to
        - positionToThe -> 'bottom'/'top'/'left'/'right'
        - alignEdge -> 'left'/'centre'/'right'/'top'/'middle'/'bottom'
        - inParent -> The view to insert the pop over in (optional)
        - showCallout -> true/false
        - offsetLeft
        - offsetTop
        - onHide: fn
    */
    show: function ( options ) {
        if ( options.alignWithView === this ) {
            return this.get( 'subPopOverView' ).show( options );
        }
        this.hide();

        this._options = options;

        // Set layout and insert in the right place
        var eventHandler = this.get( 'eventHandler' ),
            view = options.view,
            alignWithView = options.alignWithView,
            atNode = options.atNode || alignWithView.get( 'layer' ),
            atNodeWidth = atNode.offsetWidth,
            atNodeHeight = atNode.offsetHeight,
            positionToThe = options.positionToThe || 'bottom',
            alignEdge = options.alignEdge || 'left',
            parent = options.inParent,
            deltaLeft = 0,
            deltaTop = 0,
            calloutDelta = 0,
            calloutIsAtTopOrBottom =
                ( positionToThe === 'top' || positionToThe === 'bottom' ),
            callout, layout, position, gap, layer,
            Element = NS.Element,
            el = Element.create,
            getPosition = Element.getPosition,
            RootView = NS.RootView,
            ScrollView = NS.ScrollView;

        // Want nearest parent scroll view (or root view if none).
        // Special case parent == parent pop-over view.
        if ( !parent ) {
            parent = options.atNode ?
                alignWithView : alignWithView.get( 'parentView' );
            while ( !( parent instanceof RootView ) &&
                    !( parent instanceof ScrollView ) &&
                    !( parent instanceof PopOverView ) ) {
                parent = parent.get( 'parentView' );
            }
        }

        // Now find out our offsets;
        layout = getPosition( atNode, parent instanceof ScrollView ?
            parent.get( 'scrollLayer' ) : parent.get( 'layer' ) );

        switch ( positionToThe ) {
        case 'right':
            layout.left += atNodeWidth;
            /* falls through */
        case 'left':
            switch ( alignEdge ) {
            // case 'top':
            //    break; // nothing to do
            case 'middle':
                atNodeHeight = atNodeHeight >> 1;
                /* falls through */
            case 'bottom':
                layout.top += atNodeHeight;
                break;
            }
            break;
        case 'bottom':
            layout.top += atNodeHeight;
            /* falls through */
        case 'top':
            switch ( alignEdge ) {
            // case 'left':
            //     break; // nothing to do
            case 'centre':
                atNodeWidth = atNodeWidth >> 1;
                /* falls through */
            case 'right':
                layout.left += atNodeWidth;
                break;
            }
            break;
        }

        layout.top += options.offsetTop || 0;
        layout.left += options.offsetLeft || 0;

        // Set layout
        this.set( 'layout', layout );

        // Insert view
        this.insertView( view );
        this.render();

        // Callout
        layer = this.get( 'layer' );
        if ( options.showCallout ) {
            layer.appendChild(
                el( 'b', {
                    className: 'callout ' +
                        positionToThe.charAt( 0 ) + ' ' + alignEdge
                }, [
                    callout = el( 'b', {
                        className: 'callout-inner ' + positionToThe.charAt( 0 )
                    })
                ])
            );
        }

        // Insert into parent.
        parent.insertView( this );

        // Adjust positioning
        switch ( positionToThe ) {
        case 'left':
            deltaLeft -= layer.offsetWidth;
            /* falls through */
        case 'right':
            switch ( alignEdge ) {
            // case 'top':
            //    break; // nothing to do
            case 'middle':
                deltaTop -= layer.offsetHeight >> 1;
                break;
            case 'bottom':
                deltaTop -= layer.offsetHeight;
                break;
            }
            break;
        case 'top':
            deltaTop -= layer.offsetHeight;
            /* falls through */
        case 'bottom':
            switch ( alignEdge ) {
            // case 'left':
            //     break; // nothing to do
            case 'centre':
                deltaLeft -= layer.offsetWidth >> 1;
                break;
            case 'right':
                deltaLeft -= layer.offsetWidth;
                break;
            }
            break;
        }

        // Check not run off screen.
        if ( parent instanceof PopOverView ) {
            parent = parent.getParent( ScrollView ) ||
                parent.getParent( RootView );
        }
        position = getPosition( layer, parent.get( 'layer' ) );
        // Check left edge
        gap = position.left + deltaLeft;
        if ( gap < 0 ) {
            deltaLeft -= gap;
            deltaLeft += 10;
            if ( callout && calloutIsAtTopOrBottom ) {
                calloutDelta -= gap;
                calloutDelta += 10;
            }
        }
        // Check right edge
        if ( !parent.get( 'showScrollbarX' ) ) {
            gap = parent.get( 'pxWidth' ) - gap - layer.offsetWidth;
            // If gap is negative, move the view.
            if ( gap < 0 ) {
                deltaLeft += gap;
                deltaLeft -= 10;
                if ( callout && calloutIsAtTopOrBottom ) {
                    calloutDelta += gap;
                    calloutDelta -= 10;
                }
            }
        }
        // Check top edge
        gap = position.top + deltaTop;
        if ( gap < 0 ) {
            deltaTop -= gap;
            deltaTop += 10;
            if ( callout && !calloutIsAtTopOrBottom ) {
                calloutDelta -= gap;
                calloutDelta += 10;
            }
        }
        // Check bottom edge
        if ( !parent.get( 'showScrollbarY' ) ) {
            gap = parent.get( 'pxHeight' )  - gap - layer.offsetHeight;
            if ( gap < 0 ) {
                deltaTop += gap;
                deltaTop -= 10;
                if ( callout && !calloutIsAtTopOrBottom ) {
                    calloutDelta += gap;
                    calloutDelta -= 10;
                }
            }
        }

        if ( deltaLeft || deltaTop ) {
            layout.left += deltaLeft;
            layout.top += deltaTop;
            // Redraw immediately to prevent "flashing"
            this.propertyDidChange( 'layout' )
                .redraw();
        }
        if ( calloutDelta ) {
            Element.setStyle( callout,
                calloutIsAtTopOrBottom ? 'left' : 'top',
                -calloutDelta + 'px'
            );
        }

        if ( eventHandler ) {
            NS.ViewEventsController.addEventTarget( eventHandler, 10 );
        }
        this.set( 'isVisible', true );

        return this;
    },

    hide: function () {
        if ( this.get( 'isVisible' ) ) {
            var subPopOverView = this.hasSubView() ?
                    this.get( 'subPopOverView' ) : null,
                eventHandler = this.get( 'eventHandler' ),
                options = this._options,
                onHide, view, layer;
            if ( subPopOverView ) {
                subPopOverView.hide();
            }
            this.set( 'isVisible', false );
            view = this.get( 'childViews' )[0];
            this.get( 'parentView' ).removeView( this );
            this.removeView( view );
            if ( options.showCallout ) {
                layer = this.get( 'layer' );
                layer.removeChild( layer.firstChild );
            }
            if ( eventHandler ) {
                NS.ViewEventsController.removeEventTarget( eventHandler );
                eventHandler._seenMouseDown = false;
            }
            this._options = null;
            if ( onHide = options.onHide ) {
                onHide( options, this );
            }
        }
        return this;
    },

    hasSubView: function () {
        return !!NS.meta( this ).cache.subPopOverView &&
            this.get( 'subPopOverView' ).get( 'isVisible' );
    },

    subPopOverView: function () {
        return new NS.PopOverView({ parentPopOverView: this });
    }.property(),

    eventHandler: function () {
        return this.get( 'parentPopOverView' ) ?
            null : new NS.ModalEventHandler({ view: this });
    }.property(),

    clickedOutside: function () {
        this.hide();
    },

    keyOutside: function ( event ) {
        var view = this;
        while ( view.hasSubView() ) {
            view = view.get( 'subPopOverView' );
        }
        view.get( 'childViews' )[0].fire( event.type, event );
        if ( event.type === 'keydown' &&
                NS.DOMEvent.lookupKey( event ) === 'esc' ) {
            view.hide();
        }
    },

    stopEvents: function ( event ) {
        event.stopPropagation();
    }.on( 'click', 'mousedown', 'mouseup',
        'keypress', 'keydown', 'keyup', 'tap' )
});

NS.PopOverView = PopOverView;

}( this.O ) );
<commit_msg>Always close PopOver on esc (unless child view stops propagation).<commit_after>// -------------------------------------------------------------------------- \\
// File: PopOverView.js                                                       \\
// Module: PanelViews                                                         \\
// Requires: Core, Foundation, DOM, View                                      \\
// Author: Neil Jenkins                                                       \\
// License: © 2010–2013 FastMail Pty Ltd. All rights reserved.                \\
// -------------------------------------------------------------------------- \\

"use strict";

( function ( NS ) {

var PopOverView = NS.Class({

    Extends: NS.View,

    className: 'PopOverView',

    positioning: 'absolute',

    isVisible: false,
    parentPopOverView: null,

    /*
        Options
        - view -> The view to append to the pop over
        - alignWithView -> the view to align to
        - atNode -> the node within the view to align to
        - positionToThe -> 'bottom'/'top'/'left'/'right'
        - alignEdge -> 'left'/'centre'/'right'/'top'/'middle'/'bottom'
        - inParent -> The view to insert the pop over in (optional)
        - showCallout -> true/false
        - offsetLeft
        - offsetTop
        - onHide: fn
    */
    show: function ( options ) {
        if ( options.alignWithView === this ) {
            return this.get( 'subPopOverView' ).show( options );
        }
        this.hide();

        this._options = options;

        // Set layout and insert in the right place
        var eventHandler = this.get( 'eventHandler' ),
            view = options.view,
            alignWithView = options.alignWithView,
            atNode = options.atNode || alignWithView.get( 'layer' ),
            atNodeWidth = atNode.offsetWidth,
            atNodeHeight = atNode.offsetHeight,
            positionToThe = options.positionToThe || 'bottom',
            alignEdge = options.alignEdge || 'left',
            parent = options.inParent,
            deltaLeft = 0,
            deltaTop = 0,
            calloutDelta = 0,
            calloutIsAtTopOrBottom =
                ( positionToThe === 'top' || positionToThe === 'bottom' ),
            callout, layout, position, gap, layer,
            Element = NS.Element,
            el = Element.create,
            getPosition = Element.getPosition,
            RootView = NS.RootView,
            ScrollView = NS.ScrollView;

        // Want nearest parent scroll view (or root view if none).
        // Special case parent == parent pop-over view.
        if ( !parent ) {
            parent = options.atNode ?
                alignWithView : alignWithView.get( 'parentView' );
            while ( !( parent instanceof RootView ) &&
                    !( parent instanceof ScrollView ) &&
                    !( parent instanceof PopOverView ) ) {
                parent = parent.get( 'parentView' );
            }
        }

        // Now find out our offsets;
        layout = getPosition( atNode, parent instanceof ScrollView ?
            parent.get( 'scrollLayer' ) : parent.get( 'layer' ) );

        switch ( positionToThe ) {
        case 'right':
            layout.left += atNodeWidth;
            /* falls through */
        case 'left':
            switch ( alignEdge ) {
            // case 'top':
            //    break; // nothing to do
            case 'middle':
                atNodeHeight = atNodeHeight >> 1;
                /* falls through */
            case 'bottom':
                layout.top += atNodeHeight;
                break;
            }
            break;
        case 'bottom':
            layout.top += atNodeHeight;
            /* falls through */
        case 'top':
            switch ( alignEdge ) {
            // case 'left':
            //     break; // nothing to do
            case 'centre':
                atNodeWidth = atNodeWidth >> 1;
                /* falls through */
            case 'right':
                layout.left += atNodeWidth;
                break;
            }
            break;
        }

        layout.top += options.offsetTop || 0;
        layout.left += options.offsetLeft || 0;

        // Set layout
        this.set( 'layout', layout );

        // Insert view
        this.insertView( view );
        this.render();

        // Callout
        layer = this.get( 'layer' );
        if ( options.showCallout ) {
            layer.appendChild(
                el( 'b', {
                    className: 'callout ' +
                        positionToThe.charAt( 0 ) + ' ' + alignEdge
                }, [
                    callout = el( 'b', {
                        className: 'callout-inner ' + positionToThe.charAt( 0 )
                    })
                ])
            );
        }

        // Insert into parent.
        parent.insertView( this );

        // Adjust positioning
        switch ( positionToThe ) {
        case 'left':
            deltaLeft -= layer.offsetWidth;
            /* falls through */
        case 'right':
            switch ( alignEdge ) {
            // case 'top':
            //    break; // nothing to do
            case 'middle':
                deltaTop -= layer.offsetHeight >> 1;
                break;
            case 'bottom':
                deltaTop -= layer.offsetHeight;
                break;
            }
            break;
        case 'top':
            deltaTop -= layer.offsetHeight;
            /* falls through */
        case 'bottom':
            switch ( alignEdge ) {
            // case 'left':
            //     break; // nothing to do
            case 'centre':
                deltaLeft -= layer.offsetWidth >> 1;
                break;
            case 'right':
                deltaLeft -= layer.offsetWidth;
                break;
            }
            break;
        }

        // Check not run off screen.
        if ( parent instanceof PopOverView ) {
            parent = parent.getParent( ScrollView ) ||
                parent.getParent( RootView );
        }
        position = getPosition( layer, parent.get( 'layer' ) );
        // Check left edge
        gap = position.left + deltaLeft;
        if ( gap < 0 ) {
            deltaLeft -= gap;
            deltaLeft += 10;
            if ( callout && calloutIsAtTopOrBottom ) {
                calloutDelta -= gap;
                calloutDelta += 10;
            }
        }
        // Check right edge
        if ( !parent.get( 'showScrollbarX' ) ) {
            gap = parent.get( 'pxWidth' ) - gap - layer.offsetWidth;
            // If gap is negative, move the view.
            if ( gap < 0 ) {
                deltaLeft += gap;
                deltaLeft -= 10;
                if ( callout && calloutIsAtTopOrBottom ) {
                    calloutDelta += gap;
                    calloutDelta -= 10;
                }
            }
        }
        // Check top edge
        gap = position.top + deltaTop;
        if ( gap < 0 ) {
            deltaTop -= gap;
            deltaTop += 10;
            if ( callout && !calloutIsAtTopOrBottom ) {
                calloutDelta -= gap;
                calloutDelta += 10;
            }
        }
        // Check bottom edge
        if ( !parent.get( 'showScrollbarY' ) ) {
            gap = parent.get( 'pxHeight' )  - gap - layer.offsetHeight;
            if ( gap < 0 ) {
                deltaTop += gap;
                deltaTop -= 10;
                if ( callout && !calloutIsAtTopOrBottom ) {
                    calloutDelta += gap;
                    calloutDelta -= 10;
                }
            }
        }

        if ( deltaLeft || deltaTop ) {
            layout.left += deltaLeft;
            layout.top += deltaTop;
            // Redraw immediately to prevent "flashing"
            this.propertyDidChange( 'layout' )
                .redraw();
        }
        if ( calloutDelta ) {
            Element.setStyle( callout,
                calloutIsAtTopOrBottom ? 'left' : 'top',
                -calloutDelta + 'px'
            );
        }

        if ( eventHandler ) {
            NS.ViewEventsController.addEventTarget( eventHandler, 10 );
        }
        this.set( 'isVisible', true );

        return this;
    },

    hide: function () {
        if ( this.get( 'isVisible' ) ) {
            var subPopOverView = this.hasSubView() ?
                    this.get( 'subPopOverView' ) : null,
                eventHandler = this.get( 'eventHandler' ),
                options = this._options,
                onHide, view, layer;
            if ( subPopOverView ) {
                subPopOverView.hide();
            }
            this.set( 'isVisible', false );
            view = this.get( 'childViews' )[0];
            this.get( 'parentView' ).removeView( this );
            this.removeView( view );
            if ( options.showCallout ) {
                layer = this.get( 'layer' );
                layer.removeChild( layer.firstChild );
            }
            if ( eventHandler ) {
                NS.ViewEventsController.removeEventTarget( eventHandler );
                eventHandler._seenMouseDown = false;
            }
            this._options = null;
            if ( onHide = options.onHide ) {
                onHide( options, this );
            }
        }
        return this;
    },

    hasSubView: function () {
        return !!NS.meta( this ).cache.subPopOverView &&
            this.get( 'subPopOverView' ).get( 'isVisible' );
    },

    subPopOverView: function () {
        return new NS.PopOverView({ parentPopOverView: this });
    }.property(),

    eventHandler: function () {
        return this.get( 'parentPopOverView' ) ?
            null : new NS.ModalEventHandler({ view: this });
    }.property(),

    clickedOutside: function () {
        this.hide();
    },

    keyOutside: function ( event ) {
        var view = this;
        while ( view.hasSubView() ) {
            view = view.get( 'subPopOverView' );
        }
        view.get( 'childViews' )[0].fire( event.type, event );
        if ( event.type === 'keydown' ) {
            view.closeOnEsc( event );
        }
    },

    closeOnEsc: function ( event ) {
        if ( NS.DOMEvent.lookupKey( event ) === 'esc' ) {
            this.hide();
        }
    }.on( 'keydown' ),

    stopEvents: function ( event ) {
        event.stopPropagation();
    }.on( 'click', 'mousedown', 'mouseup',
        'keypress', 'keydown', 'keyup', 'tap' )
});

NS.PopOverView = PopOverView;

}( this.O ) );
<|endoftext|>


<commit_before>/*! Copyright (c) 2010 Brandon Aaron (http://brandonaaron.net)
 * Licensed under the MIT License (LICENSE.txt).
 *
 * Thanks to: http://adomas.org/javascript-mouse-wheel/ for some pointers.
 * Thanks to: Mathias Bank(http://www.mathias-bank.de) for a scope bug fix.
 * Thanks to: Seamus Leahy for adding deltaX and deltaY
 *
 * Version: 3.0.3-pre
 *
 * Requires: 1.2.2+
 */

(function($) {

var types = ['DOMMouseScroll', 'mousewheel'];

$.event.special.mousewheel = {
    setup: function() {
        if ( this.addEventListener )
            for ( var i=types.length; i; )
                this.addEventListener( types[--i], handler, false );
        else
            this.onmousewheel = handler;
    },

    teardown: function() {
        if ( this.removeEventListener )
            for ( var i=types.length; i; )
                this.removeEventListener( types[--i], handler, false );
        else
            this.onmousewheel = null;
    }
};

$.fn.extend({
    mousewheel: function(fn) {
        return fn ? this.bind("mousewheel", fn) : this.trigger("mousewheel");
    },

    unmousewheel: function(fn) {
        return this.unbind("mousewheel", fn);
    }
});

function handler(event) {
    var orgEvent = event, args = [].slice.call( arguments, 1 ), delta = 0, returnValue = true, deltaX = 0, deltaY = 0;

    event = $.event.fix(event || window.event);
    event.type = "mousewheel";

    // Old school scrollwheel delta
    if ( event.wheelDelta ) delta = event.wheelDelta/120;
    if ( event.detail     ) delta = -event.detail/3;

    // New school multidimensional scroll (touchpads) deltas
    deltaY = delta;

    // Gecko
    if ( orgEvent.axis !== undefined && orgEvent.axis === orgEvent.HORIZONTAL_AXIS ) {
        deltaY = 0;
        deltaX = -1*delta;
    }

    // Webkit
    if ( orgEvent.wheelDeltaY !== undefined ) deltaY = orgEvent.wheelDeltaY/120;
    if ( orgEvent.wheelDeltaX !== undefined ) deltaX = -1*orgEvent.wheelDeltaX/120;

    // Add event and delta to the front of the arguments
    args.unshift(event, delta, deltaX, deltaY);

    return $.event.handle.apply(this, args);
}

})(jQuery);<commit_msg>Adding curly braces<commit_after>/*! Copyright (c) 2010 Brandon Aaron (http://brandonaaron.net)
 * Licensed under the MIT License (LICENSE.txt).
 *
 * Thanks to: http://adomas.org/javascript-mouse-wheel/ for some pointers.
 * Thanks to: Mathias Bank(http://www.mathias-bank.de) for a scope bug fix.
 * Thanks to: Seamus Leahy for adding deltaX and deltaY
 *
 * Version: 3.0.3-pre
 *
 * Requires: 1.2.2+
 */

(function($) {

var types = ['DOMMouseScroll', 'mousewheel'];

$.event.special.mousewheel = {
    setup: function() {
        if ( this.addEventListener ) {
            for ( var i=types.length; i; ) {
                this.addEventListener( types[--i], handler, false );
            }
        } else {
            this.onmousewheel = handler;
        }
    },

    teardown: function() {
        if ( this.removeEventListener ) {
            for ( var i=types.length; i; ) {
                this.removeEventListener( types[--i], handler, false );
            }
        } else {
            this.onmousewheel = null;
        }
    }
};

$.fn.extend({
    mousewheel: function(fn) {
        return fn ? this.bind("mousewheel", fn) : this.trigger("mousewheel");
    },

    unmousewheel: function(fn) {
        return this.unbind("mousewheel", fn);
    }
});

function handler(event) {
    var orgEvent = event, args = [].slice.call( arguments, 1 ), delta = 0, returnValue = true, deltaX = 0, deltaY = 0;

    event = $.event.fix(event || window.event);
    event.type = "mousewheel";

    // Old school scrollwheel delta
    if ( event.wheelDelta ) { delta = event.wheelDelta/120; }
    if ( event.detail     ) { delta = -event.detail/3; }

    // New school multidimensional scroll (touchpads) deltas
    deltaY = delta;

    // Gecko
    if ( orgEvent.axis !== undefined && orgEvent.axis === orgEvent.HORIZONTAL_AXIS ) {
        deltaY = 0;
        deltaX = -1*delta;
    }

    // Webkit
    if ( orgEvent.wheelDeltaY !== undefined ) { deltaY = orgEvent.wheelDeltaY/120; }
    if ( orgEvent.wheelDeltaX !== undefined ) { deltaX = -1*orgEvent.wheelDeltaX/120; }

    // Add event and delta to the front of the arguments
    args.unshift(event, delta, deltaX, deltaY);

    return $.event.handle.apply(this, args);
}

})(jQuery);<|endoftext|>


<commit_before>var NUM_COLUMNS = 12;

/*----------------------------------------------------------------------------------------------------------------------------------*/
function p_div_new(performance) {

  var div = document.createElement("div");
  div.className = "performance_div";
  div.id = makeid(20);
  var name = performance.name;

  div.comm = comm_new(div, performance.name); //Create comm object for communictiation with the server.
  performance.comm = div.comm;

  performance.add_notify_rank(p_div_rank_updated, div);
  performance.add_notify_score(p_div_score_updated, div);

  var row = document.createElement("div");
  row.className = 'row';
  var column = document.createElement('div');
  column.className = 'small-11 columns';
  column.innerHTML = "
 " + name + "
";
  row.appendChild(column);

  var column = document.createElement("div");
  column.className = 'small-2 columns';

  var remove_me = make_remove_me_div(div.id);
  column.appendChild(remove_me);
  row.appendChild(column);

  div.appendChild(row);

  div.column_length = {Judges: slam.num_judges, Time: 2, Penalty: 1};
  div.titles = ["Judges", "Time", "Penalty"];
  p_div_build_columns_hash(div);

  div.performance = performance;

  p_div_build_titles_row(div);
  p_div_build_sub_titles(div);
  p_div_build_data_row(div);
  p_div_build_footers(div);

  div.style.backgroundColor = '#F4F4F4';
  div.style.borderStyle = 'solid';
  div.style.borderWidth = '1px';

  row = document.createElement("div");
  row.className = "row";

  /*
  column = document.createElement("div");
  column.className = "small-12 columns";
  column.style.minHeight = "15px"; //http://stackoverflow.com/a/25431669

  row.appendChild(column);
  div.appendChild(row);
  */

  row = document.createElement("div");
  row.className = "row";

  column = document.createElement("div");
  column.className = "small-2 medium-1 columns";
  column.style.color = "blue";
  column.innerHTML = "
 Score:
";
  row.appendChild(column);

  div.score_column = document.createElement("div");
  div.score_column.className = "small-2 medium-1 columns";
  div.score_column.innerHTML = "";
  row.appendChild(div.score_column);

  if (div.performance.prev != null) {

    column = document.createElement("div");
    column.className = "small-2 medium-1 columns";
    column.style.color = "blue";
    column.innerHTML = "
 Total:
";
    row.appendChild(column);

    div.cumulative_column = document.createElement("div");
    div.cumulative_column.className = "small-2 medium-1 columns";
    div.cumulative_column.innerHTML = "";
    row.appendChild(div.cumulative_column);

  }

  column = document.createElement("div");
  column.className = "small-2 medium-1 columns";
  column.style.color = "blue";
  column.innerHTML = "
 Rank:
";
  row.appendChild(column);

  div.rank_column = document.createElement("div");
  div.rank_column.className = "small-2 medium-1 columns end";
  div.rank_column.innerHTML = "";
  row.appendChild(div.rank_column);

  div.appendChild(row);

  row = document.createElement("div");
  row.className = "row";

  div.tied_with = document.createElement("div");
  div.tied_with.className = "small-12 columns";
  row.appendChild(div.tied_with);
  div.appendChild(row);

  return div;
}

/*----------------------------------------------------------------------------------------------------------------------------------*/
function p_div_build_columns_hash(div) {

  var num_columns = 12;

  var columns = div.columns = {};
  var titles = div.titles;

  var remaining_columns = num_columns;
  for (var i=0; i<titles.length; i++) {
    columns[titles[i]] = remaining_columns;
    remaining_columns -= div.column_length[titles[i]];

    if (i > 0) {
      for (j=0; j<i; j++) {
	columns[titles[j]] = div.column_length[titles[j]];
      }
    }
  }
}
/*----------------------------------------------------------------------------------------------------------------------------------*/
function p_div_build_titles_row(div) {

  var row = document.createElement("div");
  row.className = "row";

  for (var i=0; i<div.titles.length; i++) {

    var column = document.createElement("div");
    column.className = "small-" + div.columns[div.titles[i]] + " columns";

    column.innerHTML = "" + div.titles[i] + "";

    row.appendChild(column);

  }
  div.appendChild(row);
}
/*----------------------------------------------------------------------------------------------------------------------------------*/
function p_div_build_sub_titles(div) {

  var num_columns = 12;

  var row = document.createElement("div");
  row.className = "row";

  // Add Judges
  var column;
  for (var i=0; i<slam.num_judges; i++) {

    column = document.createElement("div");

    column.className = "small-1 columns";
    column.innerHTML = "" + (i + 1) + "";

    row.appendChild(column);
  }
  // Add Time
  column = document.createElement("div");
  column.className = "small-1 columns";
  column.innerHTML = "m";
  row.appendChild(column);

  column = document.createElement("div");
  column.className = "small-1 columns end";
  column.innerHTML = "s";
  row.appendChild(column);

  div.appendChild(row);
}

/*----------------------------------------------------------------------------------------------------------------------------------*/
function p_div_setup_indexes(div) {

  div.data_columns = [];
  div.indexes = {};

  var i = slam.num_judges;

  div.indexes.minutes_i = i++;
  div.indexes.seconds_i = i++;
  div.indexes.penalty_i = i++;
  div.indexes.score_i = i++;
  div.indexes.subscore_i = i++;
  div.indexes.rank = i;
}
/*----------------------------------------------------------------------------------------------------------------------------------*/
function format_value(value) {

  // Return a value that has at most one decimal place.
  return Math.round(value * 100) / 100;
}
/*----------------------------------------------------------------------------------------------------------------------------------*/
function p_div_update_data_column(div, index, value) {
  div.data_columns[index].innerHTML = format_value(value);

  // Why bother displaying subscore when it equals score?
  if (div.performance.prev == null)
    div.data_columns[div.indexes.subscore_i].innerHTML = '';
}

/*----------------------------------------------------------------------------------------------------------------------------------*/
function p_div_score_updated(div, performance) {

  //p_div_update_data_column(div, div.indexes.score_i, performance.score);
  //p_div_update_data_column(div, div.indexes.subscore_i, performance.subscore);

  div.score_column.innerHTML = format_value(performance.score);

  if (div.performance.prev != null)
    div.cumulative_column.innerHTML = format_value(performance.subscore);

  var min_i = performance.min_judge;
  var max_i = performance.max_judge;

  if (slam.do_not_include_min_and_max_scores) {
    for (var i=0; i<slam.num_judges; i++) {
      div.footers[i].innerHTML = "

";
      div.data_columns[i].style.color = "black";
    }

    var min_max_color = "darkviolet";

    var low_str = "
L

LOW
";
    var high_str = "
H

HIGH
";

    div.data_columns[min_i].style.color = min_max_color;
    div.data_columns[max_i].style.color = min_max_color;

    div.footers[min_i].innerHTML = low_str;
    div.footers[min_i].style.color = min_max_color;

    div.footers[max_i].innerHTML = high_str;
    div.footers[max_i].style.color = min_max_color;
  }
  // Time Penalty

  var time_penalty = performance.calculate_time_penalty() * -1;
  if (time_penalty != 0){
    div.footers[slam.num_judges].innerHTML = "P:";
    div.footers[slam.num_judges].style.color = "green";
    div.footers[slam.num_judges + 1].innerHTML = time_penalty;
    div.footers[slam.num_judges + 1].style.color = "green";
  }
  else {
    div.footers[slam.num_judges].innerHTML = "

";
    div.footers[slam.num_judges + 1].innerHTML = "

";
  }
}
/*----------------------------------------------------------------------------------------------------------------------------------*/
function p_div_rank_updated (div, performance) {

  div.rank_column.innerHTML = performance.rank;

  div.tied_with.innerHTML = performance.is_tied ? "
  Tied With:  " + performance.names_tied_with.join() + "
" : "";
}
/*----------------------------------------------------------------------------------------------------------------------------------*/
function p_div_get_time(div) {

  var minutes = parse_int_or_return_zero(div.data_columns[div.indexes.minutes_i].value);
  var seconds = parse_int_or_return_zero(div.data_columns[div.indexes.seconds_i].value);

  return {minutes: minutes, seconds: seconds};
}

/*----------------------------------------------------------------------------------------------------------------------------------*/
function is_score_entered_fully(score) {

  if (score == "10")
    return false;

  if (score == "100")
    return true;

  if (score.length == 2)
    return true;

  return false;
}

/*----------------------------------------------------------------------------------------------------------------------------------*/

function p_div_input_onkeyup(inputs, input) {

  input.value = input.value.replace('\.', '');
  var index = parseInt(input.getAttribute('data-index'));

  if (is_score_entered_fully(input.value)) {

    if (index < inputs.length - 1)  {
      input.removeAttribute('onkeyup');
      next_input = inputs[index + 1];
      next_input.focus();
    }
    else {
      $(input).trigger("change");
      input.blur();
    }
  }
}

/*----------------------------------------------------------------------------------------------------------------------------------*/
function p_div_input_entered(input) {

  if (!login_info.is_logged_in)
    return;

  var i = parseInt(input.getAttribute('data-index'));
  var div = input.div;
  var performance = div.performance;

  var value = parse_float_or_return_zero(input.value);

  switch (i)
  {
    case div.indexes.minutes_i:
    case div.indexes.seconds_i:
      var time = p_div_get_time(div);
      performance.set_time(time.minutes, time.seconds);
      set_time_request(performance.comm, time.minutes, time.seconds);
      break;
    case div.indexes.penalty_i:
      performance.set_penalty(value);
      set_penalty_request(performance.comm, value);
      break;
    default:
      if (i >= 0 && i < div.indexes.minutes_i) {
	input.value = input.value.replace('\.', '');
	var value = input.value / 10;
	input.value = value;
	performance.judge(i, value);
	judge_request(performance.comm, i, value);
      }
  }
}

/*----------------------------------------------------------------------------------------------------------------------------------*/
function p_div_set_score(p_div, judge_i, value) {

  p_div.data_columns[judge_i].value = value;
  p_div.data_columns[judge_i].removeAttribute('onkeyup');
  p_div.performance.judge(judge_i, value);
}

/*----------------------------------------------------------------------------------------------------------------------------------*/
function p_div_set_time(p_div, minutes, seconds) {

  var i = p_div.indexes.minutes_i;

  p_div.data_columns[i].value = minutes;
  p_div.data_columns[++i].value = seconds;

  p_div.performance.set_time(minutes, seconds);
}

/*----------------------------------------------------------------------------------------------------------------------------------*/
function p_div_set_penalty(p_div, value) {

  var i = p_div.indexes.penalty_i;

  p_div.data_columns[i].value = value;

  p_div.performance.set_penalty(value);
}
/*----------------------------------------------------------------------------------------------------------------------------------*/
function p_div_build_data_row(div) {

  p_div_setup_indexes(div);

  var row = document.createElement("div");
  row.className = "row";

  var num_columns = slam.num_judges + 3; // Judges + Minutes + Seconds + Penalty

  var i;

  div.judge_inputs = [];

  for (i=0; i<num_columns; i++) {
    var column = document.createElement("div");
    column.className = "small-1 columns";

    var input = document.createElement("input");
    input.inputs = div.judge_inputs;
    input.className = "scorekeeper_input";

    // This (the if statement to follow) is to faciliate automatic refocusing of the next judge
    // after two digit are entered for the score (exception 10 and 100)
    // last input will be Minutes so that the last judge
    // (the one that comes before Minutes) will have another input to
    // focus on after the score has been entered.
    if (i <= slam.num_judges)
      div.judge_inputs.push(input);

    input.div = div;
    input.className =  "scorekeeper_input";
    input.setAttribute('size', 4);
    input.setAttribute('onchange', 'p_div_input_entered(this)');

    if (i < slam.num_judges)
      // Only do this for inputs that are judges
      input.setAttribute('onkeyup', 'p_div_input_onkeyup(this.inputs, this)');

    input.setAttribute('data-index', i);
    input.type = "number";
    input.style.width = "60px";
    input.setAttribute('data-max-width', '60');

    if (!login_info.is_logged_in)
      input.setAttribute('readonly', null);

    column.appendChild(input);
    div.data_columns.push(input);

    row.appendChild(column);
  }

  num_columns = 12;
  for (; i< num_columns; i++) {

    var column = document.createElement("div");
    column.className = "small-1 columns";
    row.appendChild(column);

    div.data_columns.push(column);
  }

  div.appendChild(row);
}
/*----------------------------------------------------------------------------------------------------------------------------------*/
function p_div_build_footers(div) {

  div.footers = [];

  var num_columns = 12;
  var row = document.createElement("div");
  row.className = "row";

  for (var i=0; i<num_columns; i++) {

    var column = document.createElement("div");
    column.className = "small-1 columns";
    column.innerHTML = "

";

    row.appendChild(column);
    div.footers.push(column);
  }

  div.appendChild(row);
}
/*----------------------------------------------------------------------------------------------------------------------------------*/

window.addEventListener("resize", function() {

  var performance_divs = document.getElementsByClassName('performance_div');

  if (performance_divs.length > 0) {

    var p_div = performance_divs[0];
    var x1 = p_div.data_columns[0].getBoundingClientRect().left;
    var x2 = p_div.data_columns[1].getBoundingClientRect().left;

    var distance = x2 - x1;
    var max_width = parseInt(p_div.data_columns[0].getAttribute('data-max-width'));
    var width = Math.min(distance, max_width);

    // Set Width for all inputs
    var inputs = document.getElementsByClassName('scorekeeper_input');

    for (var i=0; i<inputs.length; i++) {
      inputs[i].style.width = width + "px";
    }
  }
});

<commit_msg>nevermind<commit_after>var NUM_COLUMNS = 12;

/*----------------------------------------------------------------------------------------------------------------------------------*/
function p_div_new(performance) {

  var div = document.createElement("div");
  div.className = "performance_div";
  div.id = makeid(20);
  var name = performance.name;

  div.comm = comm_new(div, performance.name); //Create comm object for communictiation with the server.
  performance.comm = div.comm;

  performance.add_notify_rank(p_div_rank_updated, div);
  performance.add_notify_score(p_div_score_updated, div);

  var row = document.createElement("div");
  row.className = 'row';
  var column = document.createElement('div');
  column.className = 'small-11 columns';
  column.innerHTML = "
 " + name + "
";
  row.appendChild(column);

  var column = document.createElement("div");
  column.className = 'small-2 columns';

  var remove_me = make_remove_me_div(div.id);
  column.appendChild(remove_me);
  row.appendChild(column);

  div.appendChild(row);

  div.column_length = {Judges: slam.num_judges, Time: 2, Penalty: 1};
  div.titles = ["Judges", "Time", "Penalty"];
  p_div_build_columns_hash(div);

  div.performance = performance;

  p_div_build_titles_row(div);
  p_div_build_sub_titles(div);
  p_div_build_data_row(div);
  p_div_build_footers(div);

  div.style.backgroundColor = '#F4F4F4';
  div.style.borderStyle = 'solid';
  div.style.borderWidth = '1px';

  row = document.createElement("div");
  row.className = "row";

  /*
  column = document.createElement("div");
  column.className = "small-12 columns";
  column.style.minHeight = "15px"; //http://stackoverflow.com/a/25431669

  row.appendChild(column);
  div.appendChild(row);
  */

  row = document.createElement("div");
  row.className = "row";

  column = document.createElement("div");
  column.className = "small-2 medium-1 columns";
  column.style.color = "blue";
  column.innerHTML = "
 Score:
";
  row.appendChild(column);

  div.score_column = document.createElement("div");
  div.score_column.className = "small-2 medium-1 columns";
  div.score_column.innerHTML = "";
  row.appendChild(div.score_column);

  if (div.performance.prev != null) {

    column = document.createElement("div");
    column.className = "small-2 medium-1 columns";
    column.style.color = "blue";
    column.innerHTML = "
 Total:
";
    row.appendChild(column);

    div.cumulative_column = document.createElement("div");
    div.cumulative_column.className = "small-2 medium-1 columns";
    div.cumulative_column.innerHTML = "";
    row.appendChild(div.cumulative_column);

  }

  column = document.createElement("div");
  column.className = "small-2 medium-1 columns";
  column.style.color = "blue";
  column.innerHTML = "
 Rank:
";
  row.appendChild(column);

  div.rank_column = document.createElement("div");
  div.rank_column.className = "small-2 medium-1 columns end";
  div.rank_column.innerHTML = "";
  row.appendChild(div.rank_column);

  div.appendChild(row);

  row = document.createElement("div");
  row.className = "row";

  div.tied_with = document.createElement("div");
  div.tied_with.className = "small-12 columns";
  row.appendChild(div.tied_with);
  div.appendChild(row);

  return div;
}

/*----------------------------------------------------------------------------------------------------------------------------------*/
function p_div_build_columns_hash(div) {

  var num_columns = 12;

  var columns = div.columns = {};
  var titles = div.titles;

  var remaining_columns = num_columns;
  for (var i=0; i<titles.length; i++) {
    columns[titles[i]] = remaining_columns;
    remaining_columns -= div.column_length[titles[i]];

    if (i > 0) {
      for (j=0; j<i; j++) {
	columns[titles[j]] = div.column_length[titles[j]];
      }
    }
  }
}
/*----------------------------------------------------------------------------------------------------------------------------------*/
function p_div_build_titles_row(div) {

  var row = document.createElement("div");
  row.className = "row";

  for (var i=0; i<div.titles.length; i++) {

    var column = document.createElement("div");
    column.className = "small-" + div.columns[div.titles[i]] + " columns";

    column.innerHTML = "" + div.titles[i] + "";

    row.appendChild(column);

  }
  div.appendChild(row);
}
/*----------------------------------------------------------------------------------------------------------------------------------*/
function p_div_build_sub_titles(div) {

  var num_columns = 12;

  var row = document.createElement("div");
  row.className = "row";

  // Add Judges
  var column;
  for (var i=0; i<slam.num_judges; i++) {

    column = document.createElement("div");

    column.className = "small-1 columns";
    column.innerHTML = "" + (i + 1) + "";

    row.appendChild(column);
  }
  // Add Time
  column = document.createElement("div");
  column.className = "small-1 columns";
  column.innerHTML = "m";
  row.appendChild(column);

  column = document.createElement("div");
  column.className = "small-1 columns end";
  column.innerHTML = "s";
  row.appendChild(column);

  div.appendChild(row);
}

/*----------------------------------------------------------------------------------------------------------------------------------*/
function p_div_setup_indexes(div) {

  div.data_columns = [];
  div.indexes = {};

  var i = slam.num_judges;

  div.indexes.minutes_i = i++;
  div.indexes.seconds_i = i++;
  div.indexes.penalty_i = i++;
  div.indexes.score_i = i++;
  div.indexes.subscore_i = i++;
  div.indexes.rank = i;
}
/*----------------------------------------------------------------------------------------------------------------------------------*/
function format_value(value) {

  // Return a value that has at most one decimal place.
  return Math.round(value * 100) / 100;
}
/*----------------------------------------------------------------------------------------------------------------------------------*/
function p_div_update_data_column(div, index, value) {
  div.data_columns[index].innerHTML = format_value(value);

  // Why bother displaying subscore when it equals score?
  if (div.performance.prev == null)
    div.data_columns[div.indexes.subscore_i].innerHTML = '';
}

/*----------------------------------------------------------------------------------------------------------------------------------*/
function p_div_score_updated(div, performance) {

  //p_div_update_data_column(div, div.indexes.score_i, performance.score);
  //p_div_update_data_column(div, div.indexes.subscore_i, performance.subscore);

  div.score_column.innerHTML = format_value(performance.score);

  if (div.performance.prev != null)
    div.cumulative_column.innerHTML = format_value(performance.subscore);

  var min_i = performance.min_judge;
  var max_i = performance.max_judge;

  if (slam.do_not_include_min_and_max_scores) {
    for (var i=0; i<slam.num_judges; i++) {
      div.footers[i].innerHTML = "

";
      div.data_columns[i].style.color = "black";
    }

    var min_max_color = "darkviolet";

    var low_str = "
L

LOW
";
    var high_str = "
H

HIGH
";

    div.data_columns[min_i].style.color = min_max_color;
    div.data_columns[max_i].style.color = min_max_color;

    div.footers[min_i].innerHTML = low_str;
    div.footers[min_i].style.color = min_max_color;

    div.footers[max_i].innerHTML = high_str;
    div.footers[max_i].style.color = min_max_color;
  }
  // Time Penalty

  var time_penalty = performance.calculate_time_penalty() * -1;
  if (time_penalty != 0){
    div.footers[slam.num_judges].innerHTML = "P:";
    div.footers[slam.num_judges].style.color = "green";
    div.footers[slam.num_judges + 1].innerHTML = time_penalty;
    div.footers[slam.num_judges + 1].style.color = "green";
  }
  else {
    div.footers[slam.num_judges].innerHTML = "

";
    div.footers[slam.num_judges + 1].innerHTML = "

";
  }
}
/*----------------------------------------------------------------------------------------------------------------------------------*/
function p_div_rank_updated (div, performance) {

  div.rank_column.innerHTML = performance.rank;

  div.tied_with.innerHTML = performance.is_tied ? "
  Tied With:  " + performance.names_tied_with.join() + "
" : "";
}
/*----------------------------------------------------------------------------------------------------------------------------------*/
function p_div_get_time(div) {

  var minutes = parse_int_or_return_zero(div.data_columns[div.indexes.minutes_i].value);
  var seconds = parse_int_or_return_zero(div.data_columns[div.indexes.seconds_i].value);

  return {minutes: minutes, seconds: seconds};
}

/*----------------------------------------------------------------------------------------------------------------------------------*/
function is_score_entered_fully(score) {

  if (score == "10")
    return false;

  if (score == "100")
    return true;

  if (score.length == 2)
    return true;

  return false;
}

/*----------------------------------------------------------------------------------------------------------------------------------*/

function p_div_input_onkeyup(inputs, input) {

  input.value = input.value.replace('\.', '');
  var index = parseInt(input.getAttribute('data-index'));

  if (is_score_entered_fully(input.value)) {

    if (index < inputs.length - 1)  {
      input.removeAttribute('onkeyup');
      next_input = inputs[index + 1];
      next_input.focus();
    }
    else {
      $(input).trigger("change");
      input.blur();
    }
  }
}

/*----------------------------------------------------------------------------------------------------------------------------------*/
function p_div_input_entered(input) {

  if (!login_info.is_logged_in)
    return;

  var i = parseInt(input.getAttribute('data-index'));
  var div = input.div;
  var performance = div.performance;

  var value = parse_float_or_return_zero(input.value);

  switch (i)
  {
    case div.indexes.minutes_i:
    case div.indexes.seconds_i:
      var time = p_div_get_time(div);
      performance.set_time(time.minutes, time.seconds);
      set_time_request(performance.comm, time.minutes, time.seconds);
      break;
    case div.indexes.penalty_i:
      performance.set_penalty(value);
      set_penalty_request(performance.comm, value);
      break;
    default:
      if (i >= 0 && i < div.indexes.minutes_i) {
	input.value = input.value.replace('\.', '');
	var value = input.value / 10;
	input.value = value;
	performance.judge(i, value);
	judge_request(performance.comm, i, value);
      }
  }
}

/*----------------------------------------------------------------------------------------------------------------------------------*/
function p_div_set_score(p_div, judge_i, value) {

  p_div.data_columns[judge_i].value = value;
  p_div.data_columns[judge_i].removeAttribute('onkeyup');
  p_div.performance.judge(judge_i, value);
}

/*----------------------------------------------------------------------------------------------------------------------------------*/
function p_div_set_time(p_div, minutes, seconds) {

  var i = p_div.indexes.minutes_i;

  p_div.data_columns[i].value = minutes;
  p_div.data_columns[++i].value = seconds;

  p_div.performance.set_time(minutes, seconds);
}

/*----------------------------------------------------------------------------------------------------------------------------------*/
function p_div_set_penalty(p_div, value) {

  var i = p_div.indexes.penalty_i;

  p_div.data_columns[i].value = value;

  p_div.performance.set_penalty(value);
}
/*----------------------------------------------------------------------------------------------------------------------------------*/
function p_div_build_data_row(div) {

  p_div_setup_indexes(div);

  var row = document.createElement("div");
  row.className = "row";

  var num_columns = slam.num_judges + 3; // Judges + Minutes + Seconds + Penalty

  var i;

  div.judge_inputs = [];

  for (i=0; i<num_columns; i++) {
    var column = document.createElement("div");
    column.className = "small-1 columns";

    var input = document.createElement("input");
    input.inputs = div.judge_inputs;
    input.className = "scorekeeper_input";

    // This (the if statement to follow) is to faciliate automatic refocusing of the next judge
    // after two digit are entered for the score (exception 10 and 100)
    // last input will be Minutes so that the last judge
    // (the one that comes before Minutes) will have another input to
    // focus on after the score has been entered.
    if (i <= slam.num_judges)
      div.judge_inputs.push(input);

    input.div = div;
    input.className =  "scorekeeper_input";
    input.setAttribute('size', 4);
    input.setAttribute('onchange', 'p_div_input_entered(this)');

    if (i < slam.num_judges)
      // Only do this for inputs that are judges
      input.setAttribute('onkeyup', 'p_div_input_onkeyup(this.inputs, this)');

    input.setAttribute('data-index', i);
    input.type = "number";
    input.style.width = "60px";
    input.setAttribute('data-max-width', '60');

    if (!login_info.is_logged_in)
      input.setAttribute('readonly', null);

    column.appendChild(input);
    div.data_columns.push(input);

    row.appendChild(column);
  }

  num_columns = 12;
  for (; i< num_columns; i++) {

    var column = document.createElement("div");
    column.className = "small-1 columns";
    row.appendChild(column);

    div.data_columns.push(column);
  }

  div.appendChild(row);
}
/*----------------------------------------------------------------------------------------------------------------------------------*/
function p_div_build_footers(div) {

  div.footers = [];

  var num_columns = 12;
  var row = document.createElement("div");
  row.className = "row";

  for (var i=0; i<num_columns; i++) {

    var column = document.createElement("div");
    column.className = "small-1 columns";
    column.innerHTML = "

";

    row.appendChild(column);
    div.footers.push(column);
  }

  div.appendChild(row);
}
/*----------------------------------------------------------------------------------------------------------------------------------*/

/*
window.addEventListener("resize", function() {

  var performance_divs = document.getElementsByClassName('performance_div');

  if (performance_divs.length > 0) {

    var p_div = performance_divs[0];
    var x1 = p_div.data_columns[0].getBoundingClientRect().left;
    var x2 = p_div.data_columns[1].getBoundingClientRect().left;

    var distance = x2 - x1;
    var max_width = parseInt(p_div.data_columns[0].getAttribute('data-max-width'));
    var width = Math.min(distance, max_width);

    // Set Width for all inputs
    var inputs = document.getElementsByClassName('scorekeeper_input');

    for (var i=0; i<inputs.length; i++) {
      inputs[i].style.width = width + "px";
    }
  }
});
*/
<|endoftext|>


<commit_before>"use strict";

angular.module('arethusa').directive('plugin', function () {
  return {
    restrict: 'E',
    scope: true,
    link: function(scope, element, attrs) {
      scope.plugin = scope.$eval(attrs.name);
    },
    template: '

'
  };
});
<commit_msg>Render plugin id properly<commit_after>"use strict";

angular.module('arethusa').directive('plugin', function () {
  return {
    restrict: 'E',
    scope: true,
    link: function(scope, element, attrs) {
      scope.plugin = scope.$eval(attrs.name);
    },
    template: '

'
  };
});
<|endoftext|>