<commit_before>/**
 * @fileoverview Main template logic, code shared by all platforms supported
 * by the template.
 *
 * The code is extended in sleek.[platform].js to add platform-specific logic.
 * To ease maintenance, the goal is to share as much code as possible between
 * versions.
 */

/*global define, Joshfire, document*/

define([
  'joshlib!collection',
  'joshlib!ui/dynamiccontainer',
  'joshlib!ui/item',
  'joshlib!ui/list',
  'joshlib!ui/cardpanel',
  'joshlib!ui/fadeinpanel',
  'joshlib!ui/factorymedia',
  'joshlib!ui/imageloader',
  'joshlib!ui/imagesloader',
  'joshlib!router',
  'joshlib!vendor/backbone',
  'joshlib!vendor/underscore',
  'joshlib!utils/dollar',
  'ui/imagegallery'],
function (Collection, DynamicContainer, Item, List, CardPanel, FadeInPanel, FactoryMedia, ImageLoader, ImagesLoader, Router, Backbone, _, $, ImageGallery) {

  var Sleek = function() {
    _.bindAll(this, 'initialize',  'setColor', 'slugify');
  };

  Sleek.extend = Backbone.View.extend;

  _.extend(Sleek.prototype, {
    /**
     * Device family that identifies the platform handled by a more specific class.
     * Override this property in derivated class as appropriate. For instance, set
     * the property to 'phone' in sleek.phone.js.
     *
     * The property is typically used to target platform-specific CSS files and
     * properties.
     */
    deviceFamily: 'all',

    /**
     * Client width available in CSS pixels
     *
     * Note the value is merely used as an indication to pick up a thumbnail
     * image for listing views. It is not correct in that it does not follow
     * orientation changes, but that's normally not a big deal.
     *
     * IMPORTANT: that value used to be computed in getThumbnail but, on iPad
     * at least, accessing document.body.clientWidth forces a refresh of the
     * screen which, in turn, means the screen will flicker for half a second,
     * hence the need to store it once and for all here.
     */
    clientWidth: document.body.clientWidth,


    /**
     * Converts a schema.org type into an internal type of items
     */
    convertItemType: function(type) {
      var outputType = null;
      switch (type) {
        case 'Article/Status':
          outputType = 'status';
          break;
        case 'NewsArticle':
        case 'BlogPosting':
        case 'Article':
        case 'CreativeWork':
          outputType = 'news';
          break;
        case 'Event':
          outputType = 'event';
          break;
        case 'ImageObject':
          outputType = 'photo';
          break;
        case 'VideoObject':
          outputType = 'video';
          break;
        case 'MusicRecording':
          outputType = 'sound';
          break;
        case 'Product':
          outputType = 'product';
          break;
        default:
          outputType = 'other';
          break;
      }
      return outputType;
    },


    /**
     * Initialization of the application.
     * The function is automatically called by the framework when the application
     * is loaded.
     *
     * @function
     */
    initialize: function(cb) {
      var self = this;

      this.title = Joshfire.factory.config.app.name;
      this.tabs = Joshfire.factory.config.template.options.tabs || [];
      this.tabicons = Joshfire.factory.config.template.options.tabicons || [];
      this.backgroundURL = Joshfire.factory.config.template.options.backgroundimage ? Joshfire.factory.config.template.options.backgroundimage.url : Joshfire.factory.config.template.options.backgroundurl;
      this.logoURL = Joshfire.factory.config.app.logo ?
                  Joshfire.factory.config.app.logo.contentURL : null;

      // Set the document's title to the application title
      document.title = this.title;

      // Set the template color based on the option selected by the user
      // (this loads the CSS)
      this.setColor(Joshfire.factory.config.template.options.color || 'gray', function () {
        //
        // Sections: one section per datasource
        //
        // (The way the list of datasources is retrieved actually depends
        // on whether the code is used in Sleek or in Spot)
        var datasources = self.getDatasources();
        var sections = new Array(datasources.length);
        var loaded = 0;

        // Prepare sections
        _.forEach(datasources, _.bind(function(datasource, index) {
          var name = this.tabs[index] || datasource.name || '';
          var icon = this.tabicons[index];
          var slug = index + '--' + this.slugify(name.toLowerCase());
          var collection = new Collection([], {
            dataSource: datasource,
            dataSourceQuery: {}
          });

          // Main section type depends on the type of content returned by the
          // datasource. Datasources that return mixed content typically fall
          // in the "other" category.
          var outputType = datasource.getOutputType();
          sections[index] = {
            name: name,
            slug: slug,
            icon: icon || self.convertItemType(outputType),
            outputType: self.convertItemType(outputType),
            collection: collection,
            index: index
          };
        }, self));

        // Create the views once all sections have been initialized
        var views = self.createViews(sections);
        var controllers = self.createRoutes(sections, views);
        var router = Router(controllers);
        router.historyStart();

        if (cb) cb();
      });
    },


    /**
     * Returns the list of datasources entered by the user, in the
     * right order.
     *
     * @function
     * @return {Array(Object)} The list of datasources, an empty
     *   array when no datasources are defined.<commit_msg>Dropped callback param from initialize function.<commit_after>/**
 * @fileoverview Main template logic, code shared by all platforms supported
 * by the template.
 *
 * The code is extended in sleek.[platform].js to add platform-specific logic.
 * To ease maintenance, the goal is to share as much code as possible between
 * versions.
 */

/*global define, Joshfire, document*/

define([
  'joshlib!collection',
  'joshlib!ui/dynamiccontainer',
  'joshlib!ui/item',
  'joshlib!ui/list',
  'joshlib!ui/cardpanel',
  'joshlib!ui/fadeinpanel',
  'joshlib!ui/factorymedia',
  'joshlib!ui/imageloader',
  'joshlib!ui/imagesloader',
  'joshlib!router',
  'joshlib!vendor/backbone',
  'joshlib!vendor/underscore',
  'joshlib!utils/dollar',
  'ui/imagegallery'],
function (Collection, DynamicContainer, Item, List, CardPanel, FadeInPanel, FactoryMedia, ImageLoader, ImagesLoader, Router, Backbone, _, $, ImageGallery) {

  var Sleek = function() {
    _.bindAll(this, 'initialize',  'setColor', 'slugify');
  };

  Sleek.extend = Backbone.View.extend;

  _.extend(Sleek.prototype, {
    /**
     * Device family that identifies the platform handled by a more specific class.
     * Override this property in derivated class as appropriate. For instance, set
     * the property to 'phone' in sleek.phone.js.
     *
     * The property is typically used to target platform-specific CSS files and
     * properties.
     */
    deviceFamily: 'all',

    /**
     * Client width available in CSS pixels
     *
     * Note the value is merely used as an indication to pick up a thumbnail
     * image for listing views. It is not correct in that it does not follow
     * orientation changes, but that's normally not a big deal.
     *
     * IMPORTANT: that value used to be computed in getThumbnail but, on iPad
     * at least, accessing document.body.clientWidth forces a refresh of the
     * screen which, in turn, means the screen will flicker for half a second,
     * hence the need to store it once and for all here.
     */
    clientWidth: document.body.clientWidth,


    /**
     * Converts a schema.org type into an internal type of items
     */
    convertItemType: function(type) {
      var outputType = null;
      switch (type) {
        case 'Article/Status':
          outputType = 'status';
          break;
        case 'NewsArticle':
        case 'BlogPosting':
        case 'Article':
        case 'CreativeWork':
          outputType = 'news';
          break;
        case 'Event':
          outputType = 'event';
          break;
        case 'ImageObject':
          outputType = 'photo';
          break;
        case 'VideoObject':
          outputType = 'video';
          break;
        case 'MusicRecording':
          outputType = 'sound';
          break;
        case 'Product':
          outputType = 'product';
          break;
        default:
          outputType = 'other';
          break;
      }
      return outputType;
    },


    /**
     * Initialization of the application.
     * The function is automatically called by the framework when the application
     * is loaded.
     *
     * @function
     */
    initialize: function() {
      var self = this;

      this.title = Joshfire.factory.config.app.name;
      this.tabs = Joshfire.factory.config.template.options.tabs || [];
      this.tabicons = Joshfire.factory.config.template.options.tabicons || [];
      this.backgroundURL = Joshfire.factory.config.template.options.backgroundimage ? Joshfire.factory.config.template.options.backgroundimage.url : Joshfire.factory.config.template.options.backgroundurl;
      this.logoURL = Joshfire.factory.config.app.logo ?
                  Joshfire.factory.config.app.logo.contentURL : null;

      // Set the document's title to the application title
      document.title = this.title;

      // Set the template color based on the option selected by the user
      // (this loads the CSS)
      this.setColor(Joshfire.factory.config.template.options.color || 'gray', function () {
        //
        // Sections: one section per datasource
        //
        // (The way the list of datasources is retrieved actually depends
        // on whether the code is used in Sleek or in Spot)
        var datasources = self.getDatasources();
        var sections = new Array(datasources.length);
        var loaded = 0;

        // Prepare sections
        _.forEach(datasources, _.bind(function(datasource, index) {
          var name = this.tabs[index] || datasource.name || '';
          var icon = this.tabicons[index];
          var slug = index + '--' + this.slugify(name.toLowerCase());
          var collection = new Collection([], {
            dataSource: datasource,
            dataSourceQuery: {}
          });

          // Main section type depends on the type of content returned by the
          // datasource. Datasources that return mixed content typically fall
          // in the "other" category.
          var outputType = datasource.getOutputType();
          sections[index] = {
            name: name,
            slug: slug,
            icon: icon || self.convertItemType(outputType),
            outputType: self.convertItemType(outputType),
            collection: collection,
            index: index
          };
        }, self));

        // Create the views once all sections have been initialized
        var views = self.createViews(sections);
        var controllers = self.createRoutes(sections, views);
        var router = Router(controllers);
        router.historyStart();
      });
    },


    /**
     * Returns the list of datasources entered by the user, in the
     * right order.
     *
     * @function
     * @return {Array(Object)} The list of datasources, an empty
     *   array when no datasources are defined.
{'fraction_non_alphanumeric': 0.10056925996204934, 'fraction_numerical': 0.00017250301880282904, 'mean_word_length': 2.315699170717758, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4279554', 'n_tokens_mistral': 3192, 'n_tokens_neox': 3092, 'n_words': 993}