<commit_before>var cdb = require('cartodb.js');
var VideoSteps = require('./preview/video_steps');

/**
 *  Create preview view
 *
 *  It will display the selected map template, a video
 *  with advices
 *
 */

module.exports = cdb.core.View.extend({

  className: 'CreateDialog-preview',

  initialize: function() {
    this.user = this.options.user;
    this.template = cdb.templates.getTemplate('new_common/views/create/create_preview');
    this.localStorage = new cdb.admin.localStorage("VideoPlayer");
    this._initBinds();
  },

  render: function() {
    this.clearSubViews();
    var d = this.model.getMapTemplate();
    if (d && d.name) {
      this.$el.html(this.template(d));
      this._initViews();
    }
    return this;
  },

  _initViews: function() {
    var template = this.model.getMapTemplate();

    // Preview map with steps?
    if (template.video && template.video.steps && template.video.steps.length > 0) {
      var videoSteps = new VideoSteps({
        el: this.$('.MapTemplate-infoSteps'),
        video: this.$('iframe'),
        templateModel: this.model.mapTemplate
      });
      videoSteps.render();
      this.addView(videoSteps);
    } else {
      this._loadScript();
    }
  },

  _storeVideoInfo: function(seconds) {

    this.localStorage.set({ currentVideo: { seconds: seconds } });

  },

  _storeVideoInfoWithId: function(seconds) {

    var id = this.model.mapTemplate.attributes.video.id;
    this.localStorage.set({ currentVideo: { id: id, seconds: seconds } });

  },

  _loadScript: function() {
    var self = this;
    $.getScript('//f.vimeocdn.com/js/froogaloop2.min.js', function() {
      self._initVideoBinds();
    });
  },

  _initVideoBinds: function() {
    this.player = $f(this.$("iframe")[0]);

    var self = this;

    this.player.addEvent('ready', function() {

      self._seekToStoredPosition();

      self.player.addEvent('playProgress', function(m) {
        self._storeVideoInfo(m.seconds);
      });

    });
  },

  _seekToStoredPosition: function() {

    var video = this.localStorage.get("currentVideo");

    if (video && this.model.mapTemplate.attributes.video.id === video.id) {

      if (video.seconds) {
        this.player.api('seekTo', video.seconds);
      }
    }

  },

  _initBinds: function() {
    this.model.bind('change:mapTemplate', this.render, this);
    this.model.bind('change:option', this._onOptionChange, this);<commit_msg>We don't need to seek here<commit_after>var cdb = require('cartodb.js');
var VideoSteps = require('./preview/video_steps');

/**
 *  Create preview view
 *
 *  It will display the selected map template, a video
 *  with advices
 *
 */

module.exports = cdb.core.View.extend({

  className: 'CreateDialog-preview',

  initialize: function() {
    this.user = this.options.user;
    this.template = cdb.templates.getTemplate('new_common/views/create/create_preview');
    this.localStorage = new cdb.admin.localStorage("VideoPlayer");
    this._initBinds();
  },

  render: function() {
    this.clearSubViews();
    var d = this.model.getMapTemplate();
    if (d && d.name) {
      this.$el.html(this.template(d));
      this._initViews();
    }
    return this;
  },

  _initViews: function() {
    var template = this.model.getMapTemplate();

    // Preview map with steps?
    if (template.video && template.video.steps && template.video.steps.length > 0) {
      var videoSteps = new VideoSteps({
        el: this.$('.MapTemplate-infoSteps'),
        video: this.$('iframe'),
        templateModel: this.model.mapTemplate
      });
      videoSteps.render();
      this.addView(videoSteps);
    } else {
      this._loadScript();
    }
  },

  _storeVideoInfo: function(seconds) {

    this.localStorage.set({ currentVideo: { seconds: seconds } });

  },

  _storeVideoInfoWithId: function(seconds) {

    var id = this.model.mapTemplate.attributes.video.id;
    this.localStorage.set({ currentVideo: { id: id, seconds: seconds } });

  },

  _loadScript: function() {
    var self = this;
    $.getScript('//f.vimeocdn.com/js/froogaloop2.min.js', function() {
      self._initVideoBinds();
    });
  },

  _initVideoBinds: function() {
    this.player = $f(this.$("iframe")[0]);

    var self = this;

    this.player.addEvent('ready', function() {

      self.player.addEvent('playProgress', function(m) {
        self._storeVideoInfo(m.seconds);
      });

    });
  },

  _initBinds: function() {
    this.model.bind('change:mapTemplate', this.render, this);
    this.model.bind('change:option', this._onOptionChange, this);
{'fraction_non_alphanumeric': 0.15891132572431957, 'fraction_numerical': 0.0013169446883230904, 'mean_word_length': 3.0398936170212765, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '4557576', 'n_tokens_mistral': 1490, 'n_tokens_neox': 1436, 'n_words': 258}