<commit_before>'use strict';
'browser-only';

/**
 * @license
 * (c) 2014 Cluster Labs, Inc. https://cluster.co/
 * License: MIT
 */

var util = skit.platform.util;
var zest = skit.thirdparty.zest;

var ELEMENT_NODE_TYPE = 1;

var ElementWrapper = function(element) {
  this.element = element;
};

ElementWrapper.elementsFromHtml = function(html) {
  var div = document.createElement('div');
  div.innerHTML = html;
  return (new ElementWrapper(div)).children();
};

ElementWrapper.fromHtml = function(html) {
  return ElementWrapper.elementsFromHtml(html)[0];
};

ElementWrapper.prototype.children = function() {
  var filtered;
  if (this.element.children) {
    filtered = util.toArray(this.element.children);
  } else {
    filtered = util.filter(this.element.childNodes, function(node) {
      return node.nodeType == ELEMENT_NODE_TYPE;
    });
  }

  return util.map(filtered, function(element) {
    return new ElementWrapper(element);
  });
};

ElementWrapper.prototype.contains = function(otherEl) {
  var current = otherEl.element || otherEl;
  while (current) {
    if (current == this.element) {
      return true;
    }
    current = current.parentNode;
  }
  return false;
};

ElementWrapper.prototype.parent = function() {
  if (this.element.parentNode && this.element.parentNode.nodeType == ELEMENT_NODE_TYPE) {
    return new ElementWrapper(this.element.parentNode);
  }
  return null;
};

ElementWrapper.prototype.matches = function(selector) {
  return zest.matches(this.element, selector);
};

ElementWrapper.prototype.find = function(selector) {
  return util.map(zest(selector, this.element), function(el) {
    return new ElementWrapper(el);
  });
};

ElementWrapper.prototype.get = function(selector) {
  var found = this.find(selector);
  return found.length ? found[0] : null;
};

ElementWrapper.prototype.$ = ElementWrapper.prototype.find;

ElementWrapper.prototype.first = function(selector) {
  var children = this.children();
  return children.length ? children[0] : null;
};

ElementWrapper.prototype.up = function(selector) {
  var current = this;
  while (current && !current.matches(selector)) {
    current = current.parent();
  }
  return current;
};

ElementWrapper.prototype.remove = function() {
  this.element.parentNode.removeChild(this.element);
};

ElementWrapper.prototype.replaceWith = function(htmlOrElement) {
  var replacement;
  if (typeof htmlOrElement == 'string') {
    replacement = ElementWrapper.fromHtml(htmlOrElement).element;
  } else {
    replacement = htmlOrElement.element || htmlOrElement;
  }

  this.element.parentNode.insertBefore(replacement, this.element);
  this.element.parentNode.removeChild(this.element);
  this.element = replacement;
};

ElementWrapper.prototype.removeChildren = function() {
  for (var i = this.element.childNodes.length - 1; i >= 0; i--) {
    this.element.removeChild(this.element.childNodes[i]);
  }
};

ElementWrapper.prototype.replaceChildren = function(htmlOrElement, opt_withChildren) {
  var replacement;
  if (typeof htmlOrElement == 'string') {
    replacement = ElementWrapper.fromHtml(htmlOrElement).element;
  } else {
    replacement = htmlOrElement.element || htmlOrElement;
  }

  this.removeChildren();

  if (!opt_withChildren) {
    this.element.appendChild(replacement);
  } else {
    for (var i = 0, len = replacement.childNodes.length; i < len; i++) {
      var child = replacement.childNodes[0];
      replacement.removeChild(child);
      this.element.appendChild(child);
    }
  }
};

ElementWrapper.prototype.classes = function() {
  return util.trim(this.element.className).split(/\s+/);
};

ElementWrapper.prototype.hasClass = function(className) {
  var classes = this.classes();
  for (var i = 0; i < classes.length; i++) {
    if (classes[i] == className) {
      return true;
    }
  }
  return false;
};

ElementWrapper.prototype.addClass = function(className) {
  if (!this.hasClass(className)) {
    this.element.className = util.trim(this.element.className + ' ' + className);
  }
};

ElementWrapper.prototype.removeClass = function(classToRemove) {
  var classes = util.filter(this.classes(), function(className) {
    return className != classToRemove;
  });

  this.element.className = classes.join(' ');
};

ElementWrapper.prototype.toggleClass = function(className) {
  if (this.hasClass(className)) {
    this.removeClass(className);
  } else {
    this.addClass(className);
  }
};

ElementWrapper.prototype.getData = function(key) {
  if (this.element.dataset) {
    return this.element.dataset[util.camelCase(key)];
  }
  return this.element.getAttribute('data-' + key);
};

ElementWrapper.prototype.setData = function(key, value) {
  if (this.element.dataset) {
    return this.element.dataset[util.camelCase(key)] = value;
  }
  return this.element.setAttribute('data-' + key, value);
};

ElementWrapper.prototype.getText = function() {
  if (typeof this.element.textContent !== 'undefined') {
    return this.element.textContent;
  } else if (typeof this.element.innerText !== 'undefined') {
    return this.element.innerText;
  } else {
    return this.element.innerHTML;
  }
};

ElementWrapper.prototype.setText = function(value) {
  this.element.innerHTML = util.escapeHtml(value);
};

ElementWrapper.prototype.value = function() {
  // TODO(Taylor): Implement for textareas.
  return this.element.value;
};

ElementWrapper.prototype.disable = function() {
  this.element.disabled = true;
};
ElementWrapper.prototype.enable = function() {
  this.element.disabled = false;
};

ElementWrapper.prototype.appendTo = function(toElement) {
  (toElement.element || toElement).appendChild(this.element);
};

ElementWrapper.prototype.append = function(htmlOrElement) {
  var elements;
  if (typeof htmlOrElement == 'string') {
    elements = ElementWrapper.elementsFromHtml(htmlOrElement);
  } else if (htmlOrElement.length) {
    elements = htmlOrElement;
  } else {
    elements = [htmlOrElement];
  }

  util.forEach(elements, function(element) {
    this.element.appendChild(element.element || element);
  }, this);
};

return ElementWrapper;
<commit_msg>Remove return from setData().<commit_after>'use strict';
'browser-only';

/**
 * @license
 * (c) 2014 Cluster Labs, Inc. https://cluster.co/
 * License: MIT
 */

var util = skit.platform.util;
var zest = skit.thirdparty.zest;

var ELEMENT_NODE_TYPE = 1;

var ElementWrapper = function(element) {
  this.element = element;
};

ElementWrapper.elementsFromHtml = function(html) {
  var div = document.createElement('div');
  div.innerHTML = html;
  return (new ElementWrapper(div)).children();
};

ElementWrapper.fromHtml = function(html) {
  return ElementWrapper.elementsFromHtml(html)[0];
};

ElementWrapper.prototype.children = function() {
  var filtered;
  if (this.element.children) {
    filtered = util.toArray(this.element.children);
  } else {
    filtered = util.filter(this.element.childNodes, function(node) {
      return node.nodeType == ELEMENT_NODE_TYPE;
    });
  }

  return util.map(filtered, function(element) {
    return new ElementWrapper(element);
  });
};

ElementWrapper.prototype.contains = function(otherEl) {
  var current = otherEl.element || otherEl;
  while (current) {
    if (current == this.element) {
      return true;
    }
    current = current.parentNode;
  }
  return false;
};

ElementWrapper.prototype.parent = function() {
  if (this.element.parentNode && this.element.parentNode.nodeType == ELEMENT_NODE_TYPE) {
    return new ElementWrapper(this.element.parentNode);
  }
  return null;
};

ElementWrapper.prototype.matches = function(selector) {
  return zest.matches(this.element, selector);
};

ElementWrapper.prototype.find = function(selector) {
  return util.map(zest(selector, this.element), function(el) {
    return new ElementWrapper(el);
  });
};

ElementWrapper.prototype.get = function(selector) {
  var found = this.find(selector);
  return found.length ? found[0] : null;
};

ElementWrapper.prototype.$ = ElementWrapper.prototype.find;

ElementWrapper.prototype.first = function(selector) {
  var children = this.children();
  return children.length ? children[0] : null;
};

ElementWrapper.prototype.up = function(selector) {
  var current = this;
  while (current && !current.matches(selector)) {
    current = current.parent();
  }
  return current;
};

ElementWrapper.prototype.remove = function() {
  this.element.parentNode.removeChild(this.element);
};

ElementWrapper.prototype.replaceWith = function(htmlOrElement) {
  var replacement;
  if (typeof htmlOrElement == 'string') {
    replacement = ElementWrapper.fromHtml(htmlOrElement).element;
  } else {
    replacement = htmlOrElement.element || htmlOrElement;
  }

  this.element.parentNode.insertBefore(replacement, this.element);
  this.element.parentNode.removeChild(this.element);
  this.element = replacement;
};

ElementWrapper.prototype.removeChildren = function() {
  for (var i = this.element.childNodes.length - 1; i >= 0; i--) {
    this.element.removeChild(this.element.childNodes[i]);
  }
};

ElementWrapper.prototype.replaceChildren = function(htmlOrElement, opt_withChildren) {
  var replacement;
  if (typeof htmlOrElement == 'string') {
    replacement = ElementWrapper.fromHtml(htmlOrElement).element;
  } else {
    replacement = htmlOrElement.element || htmlOrElement;
  }

  this.removeChildren();

  if (!opt_withChildren) {
    this.element.appendChild(replacement);
  } else {
    for (var i = 0, len = replacement.childNodes.length; i < len; i++) {
      var child = replacement.childNodes[0];
      replacement.removeChild(child);
      this.element.appendChild(child);
    }
  }
};

ElementWrapper.prototype.classes = function() {
  return util.trim(this.element.className).split(/\s+/);
};

ElementWrapper.prototype.hasClass = function(className) {
  var classes = this.classes();
  for (var i = 0; i < classes.length; i++) {
    if (classes[i] == className) {
      return true;
    }
  }
  return false;
};

ElementWrapper.prototype.addClass = function(className) {
  if (!this.hasClass(className)) {
    this.element.className = util.trim(this.element.className + ' ' + className);
  }
};

ElementWrapper.prototype.removeClass = function(classToRemove) {
  var classes = util.filter(this.classes(), function(className) {
    return className != classToRemove;
  });

  this.element.className = classes.join(' ');
};

ElementWrapper.prototype.toggleClass = function(className) {
  if (this.hasClass(className)) {
    this.removeClass(className);
  } else {
    this.addClass(className);
  }
};

ElementWrapper.prototype.getData = function(key) {
  if (this.element.dataset) {
    return this.element.dataset[util.camelCase(key)];
  }
  return this.element.getAttribute('data-' + key);
};

ElementWrapper.prototype.setData = function(key, value) {
  if (this.element.dataset) {
    this.element.dataset[util.camelCase(key)] = value;
  } else {
    this.element.setAttribute('data-' + key, value);
  }
};

ElementWrapper.prototype.getText = function() {
  if (typeof this.element.textContent !== 'undefined') {
    return this.element.textContent;
  } else if (typeof this.element.innerText !== 'undefined') {
    return this.element.innerText;
  } else {
    return this.element.innerHTML;
  }
};

ElementWrapper.prototype.setText = function(value) {
  this.element.innerHTML = util.escapeHtml(value);
};

ElementWrapper.prototype.value = function() {
  // TODO(Taylor): Implement for textareas.
  return this.element.value;
};

ElementWrapper.prototype.disable = function() {
  this.element.disabled = true;
};
ElementWrapper.prototype.enable = function() {
  this.element.disabled = false;
};

ElementWrapper.prototype.appendTo = function(toElement) {
  (toElement.element || toElement).appendChild(this.element);
};

ElementWrapper.prototype.append = function(htmlOrElement) {
  var elements;
  if (typeof htmlOrElement == 'string') {
    elements = ElementWrapper.elementsFromHtml(htmlOrElement);
  } else if (htmlOrElement.length) {
    elements = htmlOrElement;
  } else {
    elements = [htmlOrElement];
  }

  util.forEach(elements, function(element) {
    this.element.appendChild(element.element || element);
  }, this);
};

return ElementWrapper;
<|endoftext|>


<commit_before>"use strict";

// http://www.google.com/finance/match?matchtype=matchall&q=msft
// http://www.google.com/finance/match?&q=?matchtype=matchall&q=msft
(function () {
    angular
        .module("conpa")
        .factory("googleService", googleService);

    googleService.$inject = ["$http"];
    function googleService($http) {
        var service = {
            quoteLookup: quoteLookup
        };

        return service;

        function quoteLookup(query) {
            var url = "http://www.google.com/finance/match?" +
                    "matchtype=matchall";

            return $http.get(url, {
                params: {
                    q: query
                }
            }).then(function (res) {
                return res.data.matches.map(function (quote) {
                    return {
                        symbol: quote.t,
                        name: quote.n,
                        exchDisp: quote.e,
                        type: quote.id
                    };
                });
            });
        }
    }

}());
<commit_msg>Remove url commented in google sevice.<commit_after>"use strict";

(function () {
    angular
        .module("conpa")
        .factory("googleService", googleService);

    googleService.$inject = ["$http"];
    function googleService($http) {
        var service = {
            quoteLookup: quoteLookup
        };

        return service;

        function quoteLookup(query) {
            var url = "http://www.google.com/finance/match?" +
                    "matchtype=matchall";

            return $http.get(url, {
                params: {
                    q: query
                }
            }).then(function (res) {
                return res.data.matches.map(function (quote) {
                    return {
                        symbol: quote.t,
                        name: quote.n,
                        exchDisp: quote.e,
                        type: quote.id
                    };
                });
            });
        }
    }

}());
<|endoftext|>


<commit_before>/* global Plotly */
'use strict';

angular.module('metadatamanagementApp').directive('diagram',
  function($window, $timeout) {
    var link = function(scope, element) {
      scope.isNotLoaded = true;
      scope.isNotAvailable = false;
      var data = [{
        marker: {
          color: '#006AB2',
          opacity: 0.7
        }}];
      var drawDiagram = function() {
        $timeout(function() {
          scope.isNotLoaded = false;
          Plotly.newPlot('diagram', data);
        }, 1000);
      };
      function createString(object) {
        if (object === null) {
          return '';
        }
        return String(object);
      }
      function truncate(str, length) {
        str = createString(str);
        return str.length > length ? str.slice(0, length) + '...' : str;
      }
      if ((scope.type === 'nominal') || (scope.type === 'ordinal')) {
        data[0].x = [];
        data[0].text = [];
        data[0].y = [];
        data[0].type = 'bar';
        if (scope.statistics.validResponses) {
          scope.statistics.validResponses.forEach(function(obj) {
            var tempValue = truncate(obj.label[scope.language], 10);
            data[0].x.push(tempValue);
            data[0].text.push(obj.label[scope.language]);
            data[0].y.push(obj.absoluteFrequency);
          });
        } else {
          scope.isNotAvailable = true;
        }
      }
      if ((scope.type === 'kontinuierlich') || (scope.type === 'continous')) {
        /* should be discussed....
        data[0].x = [];
        data[0].type = 'histogram';
        */
        scope.isNotAvailable = true;
      }
      angular.element($window).on('resize', function() {
        drawDiagram();
      });
      element.on('$destroy', function() {
        angular.element($window).off('resize');
      });
      drawDiagram();
    };
    return {
      restrict: 'E',
      templateUrl: 'scripts/variablemanagement/directives/diagram.html.tmpl',
      link: link,
      scope: {
        statistics: '=',
        language: '=',
        type: '='
      }
    };
  });
<commit_msg>#616 fixed plotly string / number ignore problem <commit_after>/* global Plotly */
'use strict';

angular.module('metadatamanagementApp').directive('diagram',
  function($window, $timeout) {
    var link = function(scope, element) {
      scope.isNotLoaded = true;
      scope.isNotAvailable = false;
      var data = [{
        marker: {
          color: '#006AB2',
          opacity: 0.7
        }}];
      var drawDiagram = function() {
        $timeout(function() {
          scope.isNotLoaded = false;
          Plotly.newPlot('diagram', data);
        }, 1000);
      };
      function createString(object) {
        if (object === null) {
          return '';
        }
        return String(object);
      }
      function truncate(str, length) {
        str = createString(str);
        return str.length > length ? str.slice(0, length) + '...' : str;
      }
      if ((scope.type === 'nominal') || (scope.type === 'ordinal')) {
        data[0].x = [];
        data[0].text = [];
        data[0].y = [];
        data[0].type = 'bar';
        if (scope.statistics.validResponses) {
          scope.statistics.validResponses.forEach(function(obj) {
            var tempValue = truncate(' - ' + obj.label[scope.language] + ' - ',
            11);
            data[0].x.push(tempValue);
            data[0].text.push(obj.label[scope.language]);
            data[0].y.push(obj.absoluteFrequency);
          });
        } else {
          scope.isNotAvailable = true;
        }
      }
      if ((scope.type === 'kontinuierlich') || (scope.type === 'continous')) {
        /* should be discussed....
        data[0].x = [];
        data[0].type = 'histogram';
        */
        scope.isNotAvailable = true;
      }
      angular.element($window).on('resize', function() {
        drawDiagram();
      });
      element.on('$destroy', function() {
        angular.element($window).off('resize');
      });
      drawDiagram();
    };
    return {
      restrict: 'E',
      templateUrl: 'scripts/variablemanagement/directives/diagram.html.tmpl',
      link: link,
      scope: {
        statistics: '=',
        language: '=',
        type: '='
      }
    };
  });
<|endoftext|>


<commit_before>var _ = require('lodash');

module.exports = function (queryObj, encoding) {
    if (typeof encoding !== 'string') {
        throw new Error('transforms.setAssetEncoding: The \'encoding\' parameter is mandatory');
    }
    console.warn('The setAssetEncoding transform is deprecated, please use updateAsset(queryObj, {encoding: ...}) instead');
    return function setAssetEncoding(assetGraph) {
        assetGraph.findAssets(_.extend({isText: true}, queryObj)).forEach(function (asset) {
            asset.encoding = encoding;
        });
    };
};
<commit_msg>setAssetEncoding transform: Fixed deprecation message.<commit_after>var _ = require('lodash');

module.exports = function (queryObj, encoding) {
    if (typeof encoding !== 'string') {
        throw new Error('transforms.setAssetEncoding: The \'encoding\' parameter is mandatory');
    }
    console.warn('The setAssetEncoding transform is deprecated, please use updateAssets(queryObj, {encoding: ...}) instead');
    return function setAssetEncoding(assetGraph) {
        assetGraph.findAssets(_.extend({isText: true}, queryObj)).forEach(function (asset) {
            asset.encoding = encoding;
        });
    };
};
<|endoftext|>


<commit_before>/*
The MIT License (MIT)

Copyright (c) 2014 Daniel Cohen Gindi (danielgindi@gmail.com)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/* global DGTable, _, Backbone */
DGTable.RowCollection = (function () {
    'use strict';

    // Define class RowCollection
    var RowCollection = function() {
        this.initialize.apply(this, arguments);
    };

    // Inherit Array
    RowCollection.prototype = [];

    // Add events model from Backbone
    _.extend(RowCollection.prototype, Backbone.Events);

    RowCollection.prototype.initialize = function(options) {

        options = options || {};

        /**
         * @private
         * @field {String} filterColumn */
        this.filterColumn = null;

        /**
         * @private
         * @field {String} filterString */
        this.filterString = null;

        /**
         * @private
         * @field {Boolean} filterCaseSensitive */
        this.filterCaseSensitive = false;

        /** @field {string} sortColumn */
        this.sortColumn = options.sortColumn == null ? [] : options.sortColumn;
    };

    /**
     * @param {Object|Object[]} rows Row or array of rows to add to this collection
     * @param {number?} at Position to insert rows. This will prevent the sort if it is active.
     */
    RowCollection.prototype.add = function (rows, at) {
        var isArray = ('splice' in rows && 'length' in rows), i, len;
        if (isArray) {
            if (at) {
                for (i = 0, len = rows.length; i < len; i++) {
                    this.splice(at++, 0, rows[i]);
                }
            } else {
                for (i = 0, len = rows.length; i < len; i++) {
                    this.push(rows[i]);
                }
            }
        } else {
            if (at) {
                this.splice(at, 0, rows);
            } else {
                this.push(rows);
            }
        }
    };

    /**
     * @param {Object|Object[]=} rows Row or array of rows to add to this collection
     */
    RowCollection.prototype.reset = function (rows) {
        this.length = 0;
        if (rows) {
            this.add(rows);
        }
    };

    /**
     * @param {string} columnName name of the column to filter on
     * @param {string} filter keyword to filter by
     * @param {boolean=false} caseSensitive is the filter case sensitive?
     * @returns {DGTable.RowCollection} success result
     */
    RowCollection.prototype.filteredCollection = function (columnName, filter, caseSensitive) {
        filter = filter.toString();
        if (filter && columnName != null) {
            var rows = new RowCollection({ sortColumn: this.sortColumn });
            this.filterColumn = columnName;
            this.filterString = filter;
            this.filterCaseSensitive = caseSensitive;
            for (var i = 0, len = this.length, row; i < len; i++) {
                row = this[i];
                if (this.shouldBeVisible(row)) {
                    rows.push(row);
                }
            }
            return rows;
        } else {
            this.filterColumn = null;
            this.filterString = null;
            return null;
        }
    };

    /**
     * @param {Array} row
     * @returns {boolean}
     */
    RowCollection.prototype.shouldBeVisible = function (row) {
        if (row && this.filterColumn) {
            var actualVal = row[this.filterColumn];
            if (actualVal == null) {
                return false;
            }
            actualVal = actualVal.toString();
            var filterVal = this.filterString;
            if (!this.filterCaseSensitive) {
                actualVal = actualVal.toUpperCase();
                filterVal = filterVal.toUpperCase();
            }
            return actualVal.indexOf(filterVal) !== -1;
        }
        return true;
    };

    (function(){
        var nativeSort = RowCollection.prototype.sort;

        function getDefaultComparator(column, descending) {
            var lessVal = descending ? 1 : -1, moreVal = descending ? -1 : 1;
            return function(leftRow, rightRow) {
                var col = column, leftVal = leftRow[col], rightVal = rightRow[col];
                return leftVal < rightVal ? lessVal : (leftVal > rightVal ? moreVal : 0);
            };
        }

        /**
         * @param {Boolean=false} silent
         * @returns {DGTable.RowCollection} self
         */
        RowCollection.prototype.sort = function(silent) {
            if (this.sortColumn.length) {
                var comparators = [], i, returnVal;
                for (i = 0; i < this.sortColumn.length; i++) {
                    returnVal = {};
                    this.trigger('requiresComparatorForColumn', returnVal, this.sortColumn[i].column, this.sortColumn[i].descending);
                    comparators.push(_.bind(returnVal.comparator || getDefaultComparator(this.sortColumn[i].column, this.sortColumn[i].descending), this));
                }
                if (comparators.length === 1) {
                    nativeSort.call(this, comparators[0]);
                } else {
                    var len = comparators.length,
                        value,
                        comparator = function(leftRow, rightRow) {
                            for (i = 0; i < len; i++) {
                                value = comparators[i](leftRow, rightRow);
                                if (value !== 0) {
                                    return value;
                                }
                            }
                            return value;
                        };
                    nativeSort.call(this, comparator);
                }

                if (!silent) {
                    this.trigger('sort');
                }
            }
            return this;
        };
    })();

    return RowCollection;

})();<commit_msg>removed private declaration<commit_after>/*
The MIT License (MIT)

Copyright (c) 2014 Daniel Cohen Gindi (danielgindi@gmail.com)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/* global DGTable, _, Backbone */
DGTable.RowCollection = (function () {
    'use strict';

    // Define class RowCollection
    var RowCollection = function() {
        this.initialize.apply(this, arguments);
    };

    // Inherit Array
    RowCollection.prototype = [];

    // Add events model from Backbone
    _.extend(RowCollection.prototype, Backbone.Events);

    RowCollection.prototype.initialize = function(options) {

        options = options || {};

        /** @field {String} filterColumn */
        this.filterColumn = null;

        /** @field {String} filterString */
        this.filterString = null;

        /** @field {Boolean} filterCaseSensitive */
        this.filterCaseSensitive = false;

        /** @field {string} sortColumn */
        this.sortColumn = options.sortColumn == null ? [] : options.sortColumn;
    };

    /**
     * @param {Object|Object[]} rows Row or array of rows to add to this collection
     * @param {number?} at Position to insert rows. This will prevent the sort if it is active.
     */
    RowCollection.prototype.add = function (rows, at) {
        var isArray = ('splice' in rows && 'length' in rows), i, len;
        if (isArray) {
            if (at) {
                for (i = 0, len = rows.length; i < len; i++) {
                    this.splice(at++, 0, rows[i]);
                }
            } else {
                for (i = 0, len = rows.length; i < len; i++) {
                    this.push(rows[i]);
                }
            }
        } else {
            if (at) {
                this.splice(at, 0, rows);
            } else {
                this.push(rows);
            }
        }
    };

    /**
     * @param {Object|Object[]=} rows Row or array of rows to add to this collection
     */
    RowCollection.prototype.reset = function (rows) {
        this.length = 0;
        if (rows) {
            this.add(rows);
        }
    };

    /**
     * @param {string} columnName name of the column to filter on
     * @param {string} filter keyword to filter by
     * @param {boolean=false} caseSensitive is the filter case sensitive?
     * @returns {DGTable.RowCollection} success result
     */
    RowCollection.prototype.filteredCollection = function (columnName, filter, caseSensitive) {
        filter = filter.toString();
        if (filter && columnName != null) {
            var rows = new RowCollection({ sortColumn: this.sortColumn });
            this.filterColumn = columnName;
            this.filterString = filter;
            this.filterCaseSensitive = caseSensitive;
            for (var i = 0, len = this.length, row; i < len; i++) {
                row = this[i];
                if (this.shouldBeVisible(row)) {
                    rows.push(row);
                }
            }
            return rows;
        } else {
            this.filterColumn = null;
            this.filterString = null;
            return null;
        }
    };

    /**
     * @param {Array} row
     * @returns {boolean}
     */
    RowCollection.prototype.shouldBeVisible = function (row) {
        if (row && this.filterColumn) {
            var actualVal = row[this.filterColumn];
            if (actualVal == null) {
                return false;
            }
            actualVal = actualVal.toString();
            var filterVal = this.filterString;
            if (!this.filterCaseSensitive) {
                actualVal = actualVal.toUpperCase();
                filterVal = filterVal.toUpperCase();
            }
            return actualVal.indexOf(filterVal) !== -1;
        }
        return true;
    };

    (function(){
        var nativeSort = RowCollection.prototype.sort;

        function getDefaultComparator(column, descending) {
            var lessVal = descending ? 1 : -1, moreVal = descending ? -1 : 1;
            return function(leftRow, rightRow) {
                var col = column, leftVal = leftRow[col], rightVal = rightRow[col];
                return leftVal < rightVal ? lessVal : (leftVal > rightVal ? moreVal : 0);
            };
        }

        /**
         * @param {Boolean=false} silent
         * @returns {DGTable.RowCollection} self
         */
        RowCollection.prototype.sort = function(silent) {
            if (this.sortColumn.length) {
                var comparators = [], i, returnVal;
                for (i = 0; i < this.sortColumn.length; i++) {
                    returnVal = {};
                    this.trigger('requiresComparatorForColumn', returnVal, this.sortColumn[i].column, this.sortColumn[i].descending);
                    comparators.push(_.bind(returnVal.comparator || getDefaultComparator(this.sortColumn[i].column, this.sortColumn[i].descending), this));
                }
                if (comparators.length === 1) {
                    nativeSort.call(this, comparators[0]);
                } else {
                    var len = comparators.length,
                        value,
                        comparator = function(leftRow, rightRow) {
                            for (i = 0; i < len; i++) {
                                value = comparators[i](leftRow, rightRow);
                                if (value !== 0) {
                                    return value;
                                }
                            }
                            return value;
                        };
                    nativeSort.call(this, comparator);
                }

                if (!silent) {
                    this.trigger('sort');
                }
            }
            return this;
        };
    })();

    return RowCollection;

})();<|endoftext|>


<commit_before>/**********************************************************************
    Freeciv-web - the web version of Freeciv. http://play.freeciv.org/
    Copyright (C) 2009-2016  The Freeciv-web project

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

***********************************************************************/

var container;
var camera, scene, renderer;
var group;
var mouseX = 0, mouseY = 0;
var controls;
var clock = null;
var dirLight;

var windowHalfX = window.innerWidth / 2;
var windowHalfY = window.innerHeight / 2;
var active_globeview = false;
var fullmap_canvas = null;

/**************************************************************************
  Renders the world map on a globe using Three.js, with a loading message.
**************************************************************************/
function init_globe_view()
{
  $.blockUI({ message: "
Creating 3D globe view of map. Please wait.
" });
  setTimeout(show_globe_view, 100);
}

/**************************************************************************
  Renders the world map on a globe using Three.js.
**************************************************************************/
function show_globe_view()
{
  // reset dialog page.
  $("#globe_view_dialog").remove();
  $("

").appendTo("div#game_page");

  // load Three.js dynamically.
  $.ajax({
    async: false,
    url: "/javascript/libs/three.min.js",
    dataType: "script"
  });
  $.ajax({
    async: false,
    url: "/javascript/libs/Projector.js",
    dataType: "script"
  });
  $.ajax({
    async: false,
    url: "/javascript/libs/CanvasRenderer.js",
    dataType: "script"
  });
  $.ajax({
    async: false,
    url: "/javascript/libs/Detector.js",
    dataType: "script"
  });
  $.ajax({
    async: false,
    url: "/javascript/libs/FlyControls.js",
    dataType: "script"
  });

  $("#globe_view_dialog").html("

"
                               + "Controls: WASD move, R|F up | down, "
                               + "Q|E roll, up|down pitch, left|right yaw");

  $("#globe_view_dialog").attr("title", server_settings['metamessage']['val']);
  $("#globe_view_dialog").dialog({
			bgiframe: true,
			modal: true,
			width: "98%",
                        height: is_small_screen() ? $(window).height()-30 : $(window).height() - 10,
                        close : function(){
                          close_globe_view_dialog();
                        }
                     });

  $("#globe_view_dialog").dialog('open');

  // step 1: render whole map on a canvas using the Freeciv-web renderer.
  var tmpmap_canvas = document.createElement('canvas');
  var w = map['xsize'] * tileset_tile_width * 0.9;
  var h = map['ysize'] * tileset_tile_height * 1.4;

  tmpmap_canvas.width = w;
  tmpmap_canvas.height = h;

  mapview['width'] = w;
  mapview['height'] = h;
  mapview['store_width'] = w;
  mapview['store_height'] = h;

  center_tile_mapcanvas(map_pos_to_tile(map['xsize']/2, map['ysize']/2));

  mapview_canvas = tmpmap_canvas;
  mapview_canvas_ctx = mapview_canvas.getContext("2d");
  mapview_canvas_ctx.font = canvas_text_font;

  update_map_canvas_full();

  // step 2: change aspect ratio of map so that width = height,
  // rendering the result on a new canvas.
  var scaledmap_canvas = document.createElement('canvas');
  scaledmap_canvas.width = w;
  scaledmap_canvas.height = w;
  var scaledmap_ctx = scaledmap_canvas.getContext("2d");
  scaledmap_ctx.drawImage(tmpmap_canvas, 0,0, w, h, 0, 0, w, w);

  tmp_canvas = null;

  // step 3: rotate the image -41 degrees and render the result on a new canvas.
  // The canvas width and height must be a size in the power of 2, eg. 4096 and 2048.
  fullmap_canvas = document.createElement('canvas');
  fullmap_canvas.width = 4096;
  fullmap_canvas.height = 2048;
  fullmap_ctx = fullmap_canvas.getContext("2d");
  var x = fullmap_canvas.width * 0.5;
  var y = fullmap_canvas.height * 0.48;
  fullmap_ctx.translate(x, y);
  fullmap_ctx.rotate(-41 * Math.PI / 180);
  fullmap_ctx.drawImage(scaledmap_canvas, 0, 0, w, w, -4096 * 0.52, -2048 * 0.5 - 850, 4096, 4096 - 400);
  fullmap_ctx.rotate(41 * Math.PI / 180);
  fullmap_ctx.translate(-x, -y);

  // step 4: clip away left and right part of image, to make it look better.
  fullmap_ctx.drawImage(fullmap_canvas, 4096 * 0.1, 0, 4096 - 4096 * 0.1, 2048, 0, 0, 4096 * 1.22, 2048);

  // result: the fullmap_canvas now contains the image which will be rendered on a sphere.

  scaledmap_canvas = null;

  active_globeview = true;

  globe_view_init();
  globe_view_animate();

  $.unblockUI();

}

/**************************************************************************
  ...
**************************************************************************/
function close_globe_view_dialog()
{
  active_globeview = false;
  setup_window_size();
  set_default_mapview_active();
  center_tile_mapcanvas(map_pos_to_tile(map['xsize']/2, map['ysize']/2));
  setTimeout(set_default_mapview_active, 1000);

}

/**************************************************************************
  Init of Three.js rendering of the map on a 3d globe.
**************************************************************************/
function globe_view_init() {

  clock = new THREE.Clock();

  container = document.getElementById( 'globe_container' );
  var width = $("#globe_view_dialog").width() - 20;
  var height = $("#globe_view_dialog").height() - 26;
  if (width > height + 350) width = height + 350;

  camera = new THREE.PerspectiveCamera( 60, width / height, 1, 2000 );
  camera.position.z = 580;

  controls = new THREE.FlyControls(camera);
  controls.movementSpeed = 80;
  controls.domElement = container;
  controls.rollSpeed = Math.PI / 24;
  controls.autoForward = false;
  controls.dragToLook = false;

  scene = new THREE.Scene();
  scene.fog = new THREE.FogExp2( 0x000000, 0.00000025 );

  group = new THREE.Group();
  scene.add( group );

  var geometry = new THREE.SphereGeometry( 300, 36, 36 );

  var texture = new THREE.Texture(fullmap_canvas);
  texture.needsUpdate = true;

  var material = new THREE.MeshBasicMaterial( { map: texture, overdraw: 0.5 } );
  var mesh = new THREE.Mesh( geometry, material );
  group.add( mesh );

  renderer = Detector.webgl? new THREE.WebGLRenderer(): new THREE.CanvasRenderer();
  renderer.setClearColor(0x000000);
  renderer.setPixelRatio(window.devicePixelRatio);
  renderer.setSize(width, height);

  container.appendChild(renderer.domElement);

  document.addEventListener('mousemove', onDocumentMouseMove, false);

  window.addEventListener('resize', onWindowResize, false);

}

/**************************************************************************
  ...
**************************************************************************/
function onWindowResize() {

  var width = $("#globe_view_dialog").width() - 20;
  var height = $("#globe_view_dialog").height() - 26;
  if (width > height + 350) width = height + 350;

  windowHalfX = $("#globe_view_dialog").width() / 2;
  windowHalfY = $("#globe_view_dialog").height() / 2;

  camera.aspect = width / height;
  camera.updateProjectionMatrix();

  renderer.setSize( width, height);

}

/**************************************************************************
  ...
**************************************************************************/
function onDocumentMouseMove( event ) {

  mouseX = ( event.clientX - windowHalfX );
  mouseY = ( event.clientY - windowHalfY );

}

/**************************************************************************
  ...
**************************************************************************/
function globe_view_animate() {
  if (!active_globeview) return;

  requestAnimationFrame( globe_view_animate );

  globe_view_render();

}

/**************************************************************************
  ...
**************************************************************************/
function globe_view_render() {

  var delta = clock.getDelta();

  //camera.position.x += ( mouseX - camera.position.x ) * 0.05;
  //camera.position.y += ( - mouseY - camera.position.y ) * 0.05;
  //camera.lookAt( scene.position );

  group.rotation.y -= 0.001;

  controls.update( delta );

  renderer.render( scene, camera );

}

<commit_msg>Bugfixes to globeview.js.<commit_after>/**********************************************************************
    Freeciv-web - the web version of Freeciv. http://play.freeciv.org/
    Copyright (C) 2009-2016  The Freeciv-web project

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

***********************************************************************/

var container;
var camera, scene, renderer;
var group;
var mouseX = 0, mouseY = 0;
var controls;
var clock = null;
var dirLight;

var windowHalfX = window.innerWidth / 2;
var windowHalfY = window.innerHeight / 2;
var active_globeview = false;
var fullmap_canvas = null;

/**************************************************************************
  Renders the world map on a globe using Three.js, with a loading message.
**************************************************************************/
function init_globe_view()
{
  $.blockUI({ message: "
Creating 3D globe view of map. Please wait.
" });
  setTimeout(show_globe_view, 100);
  keyboard_input = false;
}

/**************************************************************************
  Renders the world map on a globe using Three.js.
**************************************************************************/
function show_globe_view()
{
  // reset dialog page.
  $("#globe_view_dialog").remove();
  $("

").appendTo("div#game_page");

  // load Three.js dynamically.
  $.ajax({
    async: false,
    url: "/javascript/libs/three.min.js",
    dataType: "script"
  });
  $.ajax({
    async: false,
    url: "/javascript/libs/Projector.js",
    dataType: "script"
  });
  $.ajax({
    async: false,
    url: "/javascript/libs/CanvasRenderer.js",
    dataType: "script"
  });
  $.ajax({
    async: false,
    url: "/javascript/libs/Detector.js",
    dataType: "script"
  });
  $.ajax({
    async: false,
    url: "/javascript/libs/FlyControls.js",
    dataType: "script"
  });

  $("#globe_view_dialog").html("

"
                               + "Controls: WASD move, R|F up | down, "
                               + "Q|E roll, up|down pitch, left|right yaw");

  $("#globe_view_dialog").attr("title", server_settings['metamessage']['val']);
  $("#globe_view_dialog").dialog({
			bgiframe: true,
			modal: true,
			width: "98%",
                        height: is_small_screen() ? $(window).height()-30 : $(window).height() - 10,
                        close : function(){
                          close_globe_view_dialog();
                        }
                     });

  $("#globe_view_dialog").dialog('open');

  // step 1: render whole map on a canvas using the Freeciv-web renderer.
  var tmpmap_canvas = document.createElement('canvas');
  var w = map['xsize'] * tileset_tile_width * 0.9;
  var h = map['ysize'] * tileset_tile_height * 1.4;

  tmpmap_canvas.width = w;
  tmpmap_canvas.height = h;

  mapview['width'] = w;
  mapview['height'] = h;
  mapview['store_width'] = w;
  mapview['store_height'] = h;

  center_tile_mapcanvas(map_pos_to_tile(map['xsize']/2, map['ysize']/2));

  mapview_canvas = tmpmap_canvas;
  mapview_canvas_ctx = mapview_canvas.getContext("2d");
  mapview_canvas_ctx.font = canvas_text_font;

  update_map_canvas_full();

  // step 2: change aspect ratio of map so that width = height,
  // rendering the result on a new canvas.
  var scaledmap_canvas = document.createElement('canvas');
  scaledmap_canvas.width = w;
  scaledmap_canvas.height = w;
  var scaledmap_ctx = scaledmap_canvas.getContext("2d");
  scaledmap_ctx.drawImage(tmpmap_canvas, 0,0, w, h, 0, 0, w, w);

  tmp_canvas = null;

  // step 3: rotate the image -41 degrees and render the result on a new canvas.
  // The canvas width and height must be a size in the power of 2, eg. 4096 and 2048.
  fullmap_canvas = document.createElement('canvas');
  fullmap_canvas.width = 4096;
  fullmap_canvas.height = 2048;
  fullmap_ctx = fullmap_canvas.getContext("2d");
  var x = fullmap_canvas.width * 0.5;
  var y = fullmap_canvas.height * 0.48;
  fullmap_ctx.translate(x, y);
  fullmap_ctx.rotate(-41 * Math.PI / 180);
  fullmap_ctx.drawImage(scaledmap_canvas, 0, 0, w, w, -4096 * 0.52, -2048 * 0.5 - 850, 4096, 4096 - 400);
  fullmap_ctx.rotate(41 * Math.PI / 180);
  fullmap_ctx.translate(-x, -y);

  // step 4: clip away left and right part of image, to make it look better.
  fullmap_ctx.drawImage(fullmap_canvas, 4096 * 0.1, 0, 4096 - 4096 * 0.1, 2048, 0, 0, 4096 * 1.22, 2048);

  // result: the fullmap_canvas now contains the image which will be rendered on a sphere.

  scaledmap_canvas = null;

  active_globeview = true;

  globe_view_init();
  globe_view_animate();

  $.unblockUI();

  // prevent array keys from scrolling window.
  window.addEventListener("keydown", function(e) {
    if([32, 37, 38, 39, 40].indexOf(e.keyCode) > -1) {
        e.preventDefault();
    }
  }, false);

}

/**************************************************************************
  ...
**************************************************************************/
function close_globe_view_dialog()
{
  active_globeview = false;
  setup_window_size();
  set_default_mapview_active();
  center_tile_mapcanvas(map_pos_to_tile(map['xsize']/2, map['ysize']/2));
  setTimeout(set_default_mapview_active, 1000);
  keyboard_input = true;
  $(".setting_button").tooltip("destroy");
}

/**************************************************************************
  Init of Three.js rendering of the map on a 3d globe.
**************************************************************************/
function globe_view_init() {

  clock = new THREE.Clock();

  container = document.getElementById( 'globe_container' );
  var width = $("#globe_view_dialog").width() - 20;
  var height = $("#globe_view_dialog").height() - 26;
  if (width > height + 350) width = height + 350;

  camera = new THREE.PerspectiveCamera( 60, width / height, 1, 2000 );
  camera.position.z = 580;

  controls = new THREE.FlyControls(camera);
  controls.movementSpeed = 80;
  controls.domElement = container;
  controls.rollSpeed = Math.PI / 24;
  controls.autoForward = false;
  controls.dragToLook = false;

  scene = new THREE.Scene();
  scene.fog = new THREE.FogExp2( 0x000000, 0.00000025 );

  group = new THREE.Group();
  scene.add( group );

  var geometry = new THREE.SphereGeometry( 300, 36, 36 );

  var texture = new THREE.Texture(fullmap_canvas);
  texture.needsUpdate = true;

  var material = new THREE.MeshBasicMaterial( { map: texture, overdraw: 0.5 } );
  var mesh = new THREE.Mesh( geometry, material );
  group.add( mesh );

  renderer = Detector.webgl? new THREE.WebGLRenderer(): new THREE.CanvasRenderer();
  renderer.setClearColor(0x0a0a0a);
  renderer.setPixelRatio(window.devicePixelRatio);
  renderer.setSize(width, height);

  container.appendChild(renderer.domElement);

  document.addEventListener('mousemove', onDocumentMouseMove, false);

  window.addEventListener('resize', onWindowResize, false);

}

/**************************************************************************
  ...
**************************************************************************/
function onWindowResize() {

  var width = $("#globe_view_dialog").width() - 20;
  var height = $("#globe_view_dialog").height() - 26;
  if (width > height + 350) width = height + 350;

  windowHalfX = $("#globe_view_dialog").width() / 2;
  windowHalfY = $("#globe_view_dialog").height() / 2;

  camera.aspect = width / height;
  camera.updateProjectionMatrix();

  renderer.setSize( width, height);

}

/**************************************************************************
  ...
**************************************************************************/
function onDocumentMouseMove( event ) {

  mouseX = ( event.clientX - windowHalfX );
  mouseY = ( event.clientY - windowHalfY );

}

/**************************************************************************
  ...
**************************************************************************/
function globe_view_animate() {
  if (!active_globeview) return;

  requestAnimationFrame( globe_view_animate );

  globe_view_render();

}

/**************************************************************************
  ...
**************************************************************************/
function globe_view_render() {

  var delta = clock.getDelta();

  group.rotation.y -= 0.001;

  controls.update( delta );

  renderer.render( scene, camera );

}

<|endoftext|>


<commit_before>var pseudoElements = [
    // pseudo-elements: https://developer.mozilla.org/en-US/docs/Web/CSS/pseudo-elements
    'after',
    'before',
    'first-letter',
    'first-line',
    'selection',
    'backdrop',
    'placeholder',
    'marker',
    'spelling-error',
    'grammar-error',

    // These occur in the default stylesheet we're using:
    '-webkit-textfield-decoration-container',
    '-internal-list-box',
    '-webkit-color-swatch-wrapper',
    '-webkit-media-slider-thumb',
    '-webkit-slider-thumb',
    '-webkit-slider-runnable-track',
    '-webkit-media-slider-container',
    '-webkit-slider-container',
    '-webkit-search-results-decoration',
    '-webkit-search-decoration',
    '-webkit-search-cancel-button',
    '-webkit-details-marker',
    '-webkit-calendar-picker-indicator',
    '-webkit-inner-spin-button',
    '-webkit-clear-button'
];

module.exports = new RegExp('::?(?:' + pseudoElements.join('|') + ')', 'gi');
<commit_msg>cssPseudoElementRegExp: Handle the weird :-moz-... classes used in the Firefox default stylesheet<commit_after>var pseudoElements = [
    // pseudo-elements: https://developer.mozilla.org/en-US/docs/Web/CSS/pseudo-elements
    'after',
    'before',
    'first-letter',
    'first-line',
    'selection',
    'backdrop',
    'placeholder',
    'marker',
    'spelling-error',
    'grammar-error',

    // These occur in the Chromium default stylesheet we're using:
    '-webkit-textfield-decoration-container',
    '-internal-list-box',
    '-webkit-color-swatch-wrapper',
    '-webkit-media-slider-thumb',
    '-webkit-slider-thumb',
    '-webkit-slider-runnable-track',
    '-webkit-media-slider-container',
    '-webkit-slider-container',
    '-webkit-search-results-decoration',
    '-webkit-search-decoration',
    '-webkit-search-cancel-button',
    '-webkit-details-marker',
    '-webkit-calendar-picker-indicator',
    '-webkit-inner-spin-button',
    '-webkit-clear-button',

    // These occur in the Firefox default stylesheet we're using:
    '-moz-native-anonymous',
    '-moz-is-html',
    '-moz-suppressed',
    '-moz-html-canvas-content',
    '-moz-loading',
    '-moz-user-disabled',
    '-moz-broken'
];

module.exports = new RegExp('::?(?:' + pseudoElements.join('|') + ')', 'gi');
<|endoftext|>


<commit_before>/**
 * @license
 * Copyright 2016 Google Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

foam.CLASS({
  package: 'com.google.flow',
  name: 'ReactiveDetailView',
  extends: 'foam.u2.DetailView',

  requires: [ 'com.google.flow.DetailPropertyView' ]
});

foam.CLASS({
  package: 'com.google.flow',
  name: 'DetailPropertyView',
  extends: 'foam.u2.DetailPropertyView',

  axioms: [
    foam.u2.CSS.create({
      code: function() {/*
      ^label {
        color: #444;
        display: block;
        float: left;
        font-size: 13px;
        padding-left: 6px;
        padding-top: 6px;
        text-align: right;
        vertical-align: top;
      }
      ^switch { color: #ccc; }
      ^ .reactive {
        font-weight: 600;
        color: red !important;
      }
      ^units  {
        color: #444;
        font-size: 12px;
        padding: 4px;
        text-align: right;
      }
      */}
    })
  ],

  properties: [
    {
      class: 'Boolean',
      name: 'reactive'
    },
    {
      class: 'String',
      name: 'formula',
      displayWidth: 50
    },
    'prop',
    [ 'nodeName', 'tr' ]
  ],

  methods: [
    function initE() {
      var prop = this.prop;
      var self = this;

      this.cssClass(this.myCls()).
          start('td').cssClass(this.myCls('label')).add(prop.label).end().
          start('td').
            cssClass(this.myCls('switch')).
            enableCls('reactive', this.reactive$).
            on('click', this.toggleMode).
            add(' = ').
          end().
          start('td').cssClass(this.myCls('view')).add(
            this.slot(function(reactive) { return reactive ? self.FORMULA : prop; }),
            prop.units && this.E('span').cssClass(this.myCls('units')).add(' ', prop.units)).
          end();
    }
  ],

  listeners: [
    function toggleMode() {
      this.reactive = ! this.reactive;
    }
  ]
});
<commit_msg>FLOW: Deleting a reactive formula switches mode.<commit_after>/**
 * @license
 * Copyright 2016 Google Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

foam.CLASS({
  package: 'com.google.flow',
  name: 'ReactiveDetailView',
  extends: 'foam.u2.DetailView',

  requires: [ 'com.google.flow.DetailPropertyView' ]
});

foam.CLASS({
  package: 'com.google.flow',
  name: 'DetailPropertyView',
  extends: 'foam.u2.DetailPropertyView',

  axioms: [
    foam.u2.CSS.create({
      code: function() {/*
      ^label {
        color: #444;
        display: block;
        float: left;
        font-size: 13px;
        padding-left: 6px;
        padding-top: 6px;
        text-align: right;
        vertical-align: top;
      }
      ^switch { color: #ccc; }
      ^ .reactive {
        font-weight: 600;
        color: red !important;
      }
      ^units  {
        color: #444;
        font-size: 12px;
        padding: 4px;
        text-align: right;
      }
      */}
    })
  ],

  properties: [
    {
      class: 'Boolean',
      name: 'reactive'
    },
    {
      class: 'String',
      name: 'formula',
      displayWidth: 50,
      postSet: function(_, f) {
        if ( ! f ) this.reactive = false;
      }
    },
    'prop',
    [ 'nodeName', 'tr' ]
  ],

  methods: [
    function initE() {
      var prop = this.prop;
      var self = this;

      this.cssClass(this.myCls()).
          start('td').cssClass(this.myCls('label')).add(prop.label).end().
          start('td').
            cssClass(this.myCls('switch')).
            enableCls('reactive', this.reactive$).
            on('click', this.toggleMode).
            add(' = ').
          end().
          start('td').cssClass(this.myCls('view')).add(
              this.slot(function(reactive) {
                return reactive ?
                    self.FORMULA.toE({data$: this.formula$}, this.__subSubContext__) :
                    prop ;
              }),
            prop.units && this.E('span').cssClass(this.myCls('units')).add(' ', prop.units)).
          end();
    }
  ],

  listeners: [
    function toggleMode() {
      this.reactive = ! this.reactive;
    }
  ]
});
<|endoftext|>


<commit_before>(function( $, undefined ) {
    $.KBWidget({
        name: "KBaseWSReferenceList",
        parent: "kbaseAuthenticatedWidget",
        version: "1.0.0",

        //wsUrl: "http://dev04.berkeley.kbase.us:7058",
        wsUrl:"https://kbase.us/services/ws",

        options: {
            wsNameOrId: null,
            objNameOrId: null,
            objVer: null,
            authToken: null,
            userId: null,
            wsUrl:null,
            width:700
        },

        objName:"",
        wsName:"",

        init: function(options) {
            this._super(options);
            var self = this;

            if (options.wsUrl) {
                self.wsUrl = options.wsUrl;
            }
            var tok = ""; // put token here for testing
            var kbws;
            if (tok) {
                kbws = new Workspace(self.wsUrl, {token: tok});
            } else {
                kbws = new Workspace(self.wsUrl);
            }

            self.objName = options.objNameOrId;
            self.wsName = options.wsNameOrId;

            self.$elem.append('

finding all data that references this object...

');
            self.$elem.append('
')
            //self.$elem.append(JSON.stringify(options)+"
");

            // get the refs
            var objectIdentity = self.getObjectIdentity(options.wsNameOrId, options.objNameOrId, options.objVer);
            kbws.list_referencing_objects([objectIdentity], function(data) {
                    if (data[0].length == 0) {
                        self.$elem.append("
No objects reference this object.
");
                    } else {
                        var refList = {};
                        for(var i = 0; i < data[0].length; i++) {
                            var objInfo = data[0][i];
                            //0:obj_id objid, 1:obj_name name, 2:type_string type,3:timestamp save_date, 4:int version, 5:username saved_by,
                            //6:ws_id wsid, 7:ws_name workspace, 8:string chsum, 9:int size, 10:usermeta meta>
                            //object_info;
                            if (!(objInfo[6]+"/"+objInfo[1] in refList)) {
                                refList[objInfo[6]+"/"+objInfo[1]] = objInfo;

                            } else {
                                if (refList[objInfo[6]+"/"+objInfo[1]][4] < objInfo[4]) {
                                    refList[objInfo[6]+"/"+objInfo[1]] = objInfo;

                            }
                        }

                        // load the data into a data object
                        var refTableData = [];
                        for(var ref in refList) {
                            var objInfo = refList[ref];
                            var savedate = new Date(objInfo[3]);
                                    refTableData.push({
                                            na:objInfo[1]+ " ("+objInfo[6]+"/"+objInfo[0]+"/"+objInfo[4]+")",
                                            ty:objInfo[2],
                                            de:"saved by "+objInfo[5]+" on "+self.monthLookup[savedate.getMonth()]+" "+savedate.getDate()+", "+savedate.getFullYear()
                                        })
                                }
                            //self.$elem.append(""+objInfo[1]+" "+objInfo[2]+" ("+objInfo[6]+"/"+objInfo[0]+"/"+objInfo[4]+", saved by "
                            //            +objInfo[5]+" on "+self.monthLookup[savedate.getMonth()]+" "+savedate.getDate()+", "+savedate.getFullYear()+")
")
                        }

                        self.$elem.find('#loading-mssg').remove();

                        var $maindiv = self.$elem.find('#mainview');
                        $maindiv.append('
');

            		var tblSettings = {
            				"sPaginationType": "full_numbers",
            				"iDisplayLength": 20,
            				"aoColumns": [
            				              {sTitle: "Object Name (reference)", mData: "na"},
            				              {sTitle: "Type", mData: "ty"},
            				              {sTitle: "Details", mData: "de"}
            				              ],
            				              "aaData": refTableData

            				              /*"fnDrawCallback": function() {}
                                                      	$('.'+pref+'contig-click').unbind('click');
                                                                $('.'+pref+'contig-click').click(function() {
                                                                var contigId = [$(this).data('contigname')];
                                                                showContig(contigId);
                                                        });
                                                        }*/
            		};
            		var refTable = self.$elem.find('#ref-table').dataTable(tblSettings);
                    }
                }, function(err) {
                    self.$elem.find('#loading-mssg').remove();
                    self.$elem.append("

Error in finding referencing objects!
");
                    console.error("Error in finding referencing objects!");
                    console.error(err);
                    self.$elem.append("

Error was:

"+err['error']['message']+"
");
                });

            return this;
        },

        getData: function() {
            return {title:"Data objects referencing "+ this.objName+"", workspace:this.wsName};
        },

        /* Construct an ObjectIdentity that can be used to query the WS*/
        getObjectIdentity: function(wsNameOrId, objNameOrId, objVer) {
            if (objVer) { return {ref:wsNameOrId+"/"+objNameOrId+"/"+objVer}; }
            return {ref:wsNameOrId+"/"+objNameOrId } ;
        },

        monthLookup : ["Jan", "Feb", "Mar","Apr", "May", "Jun", "Jul", "Aug", "Sep","Oct", "Nov", "Dec"]

    });
})( jQuery )<commit_msg>minor ref list edits<commit_after>(function( $, undefined ) {
    $.KBWidget({
        name: "KBaseWSReferenceList",
        parent: "kbaseAuthenticatedWidget",
        version: "1.0.0",

        //wsUrl: "http://dev04.berkeley.kbase.us:7058",
        wsUrl:"https://kbase.us/services/ws",

        options: {
            wsNameOrId: null,
            objNameOrId: null,
            objVer: null,
            authToken: null,
            userId: null,
            wsUrl:null,
            width:700
        },

        objName:"",
        wsName:"",

        init: function(options) {
            this._super(options);
            var self = this;

            if (options.wsUrl) {
                self.wsUrl = options.wsUrl;
            }
            var tok = ""; // put token here for testing
            var kbws;
            if (tok) {
                kbws = new Workspace(self.wsUrl, {token: tok});
            } else {
                kbws = new Workspace(self.wsUrl);
            }

            self.objName = options.objNameOrId;
            self.wsName = options.wsNameOrId;

            self.$elem.append('

finding all data that references this object...

');
            self.$elem.append('
')
            //self.$elem.append(JSON.stringify(options)+"
");

            // get the refs
            var objectIdentity = self.getObjectIdentity(options.wsNameOrId, options.objNameOrId, options.objVer);
            kbws.list_referencing_objects([objectIdentity], function(data) {
                    if (data[0].length == 0) {
                        self.$elem.append("
No objects reference this object.
");
                    } else {
                        var refList = {};
                        for(var i = 0; i < data[0].length; i++) {
                            var objInfo = data[0][i];
                            //0:obj_id objid, 1:obj_name name, 2:type_string type,3:timestamp save_date, 4:int version, 5:username saved_by,
                            //6:ws_id wsid, 7:ws_name workspace, 8:string chsum, 9:int size, 10:usermeta meta>
                            //object_info;
                            if (!(objInfo[6]+"/"+objInfo[1] in refList)) {
                                refList[objInfo[6]+"/"+objInfo[1]] = objInfo;

                            } else {
                                if (refList[objInfo[6]+"/"+objInfo[1]][4] < objInfo[4]) {
                                    refList[objInfo[6]+"/"+objInfo[1]] = objInfo;

                            }
                        }

                        // load the data into a data object
                        var refTableData = [];
                        for(var ref in refList) {
                            var objInfo = refList[ref];
                            var savedate = new Date(objInfo[3]);
                                    refTableData.push({
                                            na:objInfo[1]+ " ("+objInfo[6]+"/"+objInfo[0]+"/"+objInfo[4]+")",
                                            ty:objInfo[2],
                                            de:"saved by "+objInfo[5]+" on "+self.monthLookup[savedate.getMonth()]+" "+savedate.getDate()+", "+savedate.getFullYear()
                                        })
                                }
                            //self.$elem.append(""+objInfo[1]+" "+objInfo[2]+" ("+objInfo[6]+"/"+objInfo[0]+"/"+objInfo[4]+", saved by "
                            //            +objInfo[5]+" on "+self.monthLookup[savedate.getMonth()]+" "+savedate.getDate()+", "+savedate.getFullYear()+")
")
                        }

                        self.$elem.find('#loading-mssg').remove();

                        var $maindiv = self.$elem.find('#mainview');
                        $maindiv.append('
');

            		var tblSettings = {
            				"sPaginationType": "full_numbers",
            				"iDisplayLength": 10,
                                        "sDom": 't<flip>',
            				"aoColumns": [
            				              {sTitle: "Object Name (reference)", mData: "na"},
            				              {sTitle: "Type", mData: "ty"},
            				              {sTitle: "Details", mData: "de"}
            				              ],
            				              "aaData": refTableData

            				              /*"fnDrawCallback": function() {}
                                                      	$('.'+pref+'contig-click').unbind('click');
                                                                $('.'+pref+'contig-click').click(function() {
                                                                var contigId = [$(this).data('contigname')];
                                                                showContig(contigId);
                                                        });
                                                        }*/
            		};
            		var refTable = self.$elem.find('#ref-table').dataTable(tblSettings);
                    }
                }, function(err) {
                    self.$elem.find('#loading-mssg').remove();
                    self.$elem.append("

Error in finding referencing objects!
");
                    console.error("Error in finding referencing objects!");
                    console.error(err);
                    self.$elem.append("

Error was:

"+err['error']['message']+"

");
                });

            return this;
        },

        getData: function() {
            return {title:"Data objects referencing "+ this.objName+"", workspace:this.wsName};
        },

        /* Construct an ObjectIdentity that can be used to query the WS*/
        getObjectIdentity: function(wsNameOrId, objNameOrId, objVer) {
            if (objVer) { return {ref:wsNameOrId+"/"+objNameOrId+"/"+objVer}; }
            return {ref:wsNameOrId+"/"+objNameOrId } ;
        },

        monthLookup : ["Jan", "Feb", "Mar","Apr", "May", "Jun", "Jul", "Aug", "Sep","Oct", "Nov", "Dec"]

    });
})( jQuery )<|endoftext|>