<commit_before>/*
 * the media view
 *
 */

define(function(require){
    var Backbone = require('backbone'),
        _ = require('underscore'),
        main_view = require('app/task/main_view');

    var canvas = main_view.$el;

    var View = Backbone.View.extend({

        // build element according to simulus
        initialize: function(options){
            this.options = options || {}; // needed since backbone v1.1.0

            this.$el
                .addClass('stimulus')
                .attr('data-handle', this.model.handle)     // add data-handle for handeling of mouse/touch interactions
                .css("visibility", "hidden")
                .css(this.model.get('css'))
                .appendTo(canvas);

            this.render();
        },

        // we keep all stimuli appended to the canvas so that the render function can apply to them
        // they shouldn't affect each other because they have absolute positioning
        // we hide and show them using visibility

        render: function(){
            // these are the things that need recalibrating on refresh
            this.size();

            // if the element does not have a width it is meaningless to place it at this stage
            if (this.$el.width()){
                this.place();
            } else {
                // this is probably an image that hasn't been loaded yet
                // we need to defer "place" because safari needs time to load images
                // the preloader makes sure that the image is already in cache
                // but it appears that safari requires another round of the call stack before loading the image...
                _.defer(_.bind(this.place, this));
            }

            return this;
        },

        show: function(){
            // if this is a gif, reload it before displaying so that the gif is reset
            if (this.options.type === 'image' && this.options.image.indexOf('gif') !== -1){
                // weird IE bug that prevents refreshing gifs...
				// also, on IE11 you can't refresh a gif when it is not visibility:visible
                if(window.ActiveXObject || "ActiveXObject" in window){ // true only in IE
                    this.$el.css("visibility", "visible");
					this.$el[0].src =  this.options.image + '#' + Math.random();
                } else {
                    // Firefox requires to explicitly empty the "src" before resetting it.
                    this.$el[0].src = "";
                    this.$el[0].src = this.options.image;
					this.$el.css("visibility", "visible");
                }

				return this;
            }

            this.$el.css("visibility", "visible");
            return this;
        },

        hide: function(){
            this.$el.css("visibility", "hidden");
            return this;
        },

        size: function(){
            var size = this.model.get('size');

            if (size.font_size){
                this.$el.css('font-size', size.font_size);
            }
            // if this is a word, we don't want to set height (it breaks centering)
            if (size.height != 'auto' && this.options.type != 'word') {
                this.$el.height(size.height + '%');
            }
            if (size.width != 'auto'){
                this.$el.width(size.width + '%');
            }

            return this;
        },

        // places the element on the canvas (has to be called after size)
        // @TODO: this is way too complex to be left here, we should probably export this to a seperate file or something
        place: function(){
            // helper function: returns sizes of element;
            function size($elem){
                return {
                    height    : $elem.outerHeight(),
                    width    : $elem.outerWidth()
                };
            }

            var top, bottom, left, right; // will hold the offset for the locations<commit_msg>fix(mediaView): take canvas border into consideration when centering<commit_after>/*
 * the media view
 *
 */

define(function(require){
    var Backbone = require('backbone'),
        _ = require('underscore'),
        main_view = require('app/task/main_view');

    var canvas = main_view.$el;

    var View = Backbone.View.extend({

        // build element according to simulus
        initialize: function(options){
            this.options = options || {}; // needed since backbone v1.1.0

            this.$el
                .addClass('stimulus')
                .attr('data-handle', this.model.handle)     // add data-handle for handeling of mouse/touch interactions
                .css("visibility", "hidden")
                .css(this.model.get('css'))
                .appendTo(canvas);

            this.render();
        },

        // we keep all stimuli appended to the canvas so that the render function can apply to them
        // they shouldn't affect each other because they have absolute positioning
        // we hide and show them using visibility

        render: function(){
            // these are the things that need recalibrating on refresh
            this.size();

            // if the element does not have a width it is meaningless to place it at this stage
            if (this.$el.width()){
                this.place();
            } else {
                // this is probably an image that hasn't been loaded yet
                // we need to defer "place" because safari needs time to load images
                // the preloader makes sure that the image is already in cache
                // but it appears that safari requires another round of the call stack before loading the image...
                _.defer(_.bind(this.place, this));
            }

            return this;
        },

        show: function(){
            // if this is a gif, reload it before displaying so that the gif is reset
            if (this.options.type === 'image' && this.options.image.indexOf('gif') !== -1){
                // weird IE bug that prevents refreshing gifs...
				// also, on IE11 you can't refresh a gif when it is not visibility:visible
                if(window.ActiveXObject || "ActiveXObject" in window){ // true only in IE
                    this.$el.css("visibility", "visible");
					this.$el[0].src =  this.options.image + '#' + Math.random();
                } else {
                    // Firefox requires to explicitly empty the "src" before resetting it.
                    this.$el[0].src = "";
                    this.$el[0].src = this.options.image;
					this.$el.css("visibility", "visible");
                }

				return this;
            }

            this.$el.css("visibility", "visible");
            return this;
        },

        hide: function(){
            this.$el.css("visibility", "hidden");
            return this;
        },

        size: function(){
            var size = this.model.get('size');

            if (size.font_size){
                this.$el.css('font-size', size.font_size);
            }
            // if this is a word, we don't want to set height (it breaks centering)
            if (size.height != 'auto' && this.options.type != 'word') {
                this.$el.height(size.height + '%');
            }
            if (size.width != 'auto'){
                this.$el.width(size.width + '%');
            }

            return this;
        },

        // places the element on the canvas (has to be called after size)
        // @TODO: this is way too complex to be left here, we should probably export this to a seperate file or something
        place: function(){
            // helper function: returns sizes of element;
            function size($elem){
                return {
                    height    : $elem.innerHeight(),
                    width    : $elem.innerWidth()
                };
            }

            var top, bottom, left, right; // will hold the offset for the locations
{'fraction_non_alphanumeric': 0.11125047033738869, 'fraction_numerical': 0.0022576194656967266, 'mean_word_length': 1.54923273657289, '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': '3078793', 'n_tokens_mistral': 2071, 'n_tokens_neox': 1906, 'n_words': 694}