<commit_before>/*
 * jquery.drag-n-crop
 * https://github.com/fiszer/drag-n-crop
 *
 * Copyright (c) 2012 <NAME>
 * Licensed under the MIT license.
 */

;(function ( $, window, document, undefined ) {

    $.widget( "fotomaton.drag2crop" , {

        options: {
            containmentClass: 'containment',
            overlayClass: 'overlay',
            containerActiveClass: 'dragging',
            position: { top: 0, left: 0 },
            centered: false,
            overlay: false
        },

        move: function ( position ) {

          if( !position ){
            throw new Error('position object must be provided');
          }

          if (position.left === undefined && position.top === undefined ) {
            throw new Error('position object must contain "left" or "top" props');
          }

          if( $.isNumeric(position.left) && this.axis === 'x'){

            var left = - position.left * this.offsetX;
            this.element.css('left', left);

          } else if( $.isNumeric(position.top) && this.axis === 'y'){

            var top = - position.top * this.offsetY;
            this.element.css('top', top);

          }
        },

        getPosition: function( position ) {

          return {
            left : ( - position.left / this.offsetX) || 0,
            top : (- position.top / this.offsetY) || 0
          };

        },

        //Setup widget (eg. element creation, apply theming
        // , bind events etc.)
        _create: function () {

            this.container = $(this.element.parent());

            var dfd = this.element.imagesLoaded();
            var self = this;

            dfd.done( function( ){
              self._getDimensions.call(self);
              self._makeDraggable.call(self);
            } );

        },

        _getDimensions: function() {

          this.offsetX = this.element.width() - this.container.width();
          this.offsetY = this.element.height() - this.container.height();
          this.axis = this.element.width() / this.element.height() > 1 ? 'x' : 'y';

        },


        _makeDraggable : function () {

          var containement = this._insertContainment();
          var overlay      = this._insertOverlay();
          var axis         = this.axis;
          var position     = this.options.position;

          var draggable = this.draggable = this.element.draggable({
            axis: axis,
            containment: containement
          });

          draggable.bind('dragstart', $.proxy( function () {
            this.container.addClass( this.options.containerActiveClass );
          }, this) );

          draggable.bind('dragstop', $.proxy( function( event, ui ){
            this._dragStop( event , ui );
            this.container.removeClass( this.options.containerActiveClass );
          }, this) );

          if(this.options.overlay){
            draggable.bind('drag', $.proxy( function ( event, ui ) {
              this._adaptOverlay( ui );
            }, this) );
          }

          if(this.options.centered){
            position = {left: 0.5, top: 0.5};
          }

          if( position && ( position.top !== 0 || position.left !== 0)) {
            this.move(position);
          }

        },

        _dragStop: function( event, ui ) {

          this._trigger('dragged', event, this.getPosition(ui.position) );

        },

        _adaptOverlay: function( ui ) {

          if ( this.axis === 'x' ) {

            this.overlay.css('left', ui.position.left)
                        .css('border-left-width', -ui.position.left)
                        .css('right', -ui.position.left - this.offsetX)
                        .css('border-right-width', ui.position.left + this.offsetX);

          } else if ( this.axis === 'y' ){

            this.overlay.css('top', ui.position.top)
                        .css('border-top-width', -ui.position.top)
                        .css('bottom', -ui.position.top - this.offsetY )
                        .css('border-bottom-width', ui.position.top + this.offsetY );

          }

        },

        _insertContainment: function() {
<commit_msg>More custom classes, event binders, automatic proportion check etc...<commit_after>/*
 * jquery.drag-n-crop
 * https://github.com/fiszer/drag-n-crop
 *
 * Copyright (c) 2013 <NAME>
 * Licensed under the MIT license.
 */

;(function ( $, window, document, undefined ) {

    $.widget( "lukaszfiszer.dragncrop" , {

        options: {

            // Classes
            containmentClass: 'dragncrop-containment',
            containerActiveClass: 'dragncrop-dragging',
            noOverflowClass: 'dragncrop-no-overflow',
            horizontalClass: 'dragncrop-horizontal',
            verticalClass: 'dragncrop-vertical',

            // Initial position
            position: { x: 0, y: 0 },
            centered: false,

            // Overflow:
            overflow: true,

            // Overlay
            overlay: false,
            overlayClass: 'dragndrop-overlay'
        },

        move: function ( position ) {

          if( !position ){
            throw new Error('position object must be provided');
          }

          if (position.x === undefined && position.y === undefined ) {
            throw new Error('position object must contain "left" or "top" props');
          }

          if( $.isNumeric(position.x) && this.axis === 'x'){

            var left = - position.x * this.offsetX;
            this.element.css('left', left);

          } else if( $.isNumeric(position.y) && this.axis === 'y'){

            var top = - position.y * this.offsetY;
            this.element.css('top', top);

          }
        },

        _getPosition: function( ui ) {

          return {
            position : {
              x : ( -ui.position.left / this.offsetX) || null,
              y : ( -ui.position.top / this.offsetY) || null
            },
            offset : {
              x : ( -ui.position.left / this.containerWidth) || null,
              y : ( -ui.position.top / this.containerHeight) || null
            }
          };

        },

        //Setup widget (eg. element creation, apply theming
        // , bind events etc.)
        _create: function () {

            this.container = $(this.element.parent());

            if( !this.options.overflow){
              $(this.container).addClass(this.options.noOverflowClass);
            }

            var dfd = this.element.imagesLoaded();
            var self = this;

            dfd.done( function( ){
              if(self._checkProportions()){
                self._getDimensions.call(self);
                self._makeDraggable.call(self);
              }
            } );

        },

        _checkProportions: function() {

          this.width = this.element.width();
          this.height = this.element.height();
          this.containerWidth = this.container.width();
          this.containerHeight = this.container.height();

          if (this.width > this.height) {
            $(this.container).addClass(this.options.horizontalClass);
            return true;
          } else if (this.width < this.height) {
            $(this.container).addClass(this.options.verticalClass);
            return true;
          }else{
            return false;
          }

        },

        _getDimensions: function() {

          this.offsetX = this.element.width() - this.container.width();
          this.offsetY = this.element.height() - this.container.height();
          this.axis = this.element.width() / this.element.height() > 1 ? 'x' : 'y';

        },


        _makeDraggable : function () {

          var axis         = this.axis;
          var position     = this.options.position;
          var containement = this._insertContainment();

          var draggable = this.draggable = this.element.draggable({
            axis: axis,
            containment: containement
          });

          draggable.bind('dragstart', $.proxy( function (event, ui) {
            this._dragStart( event , ui );
            this.container.addClass( this.options.containerActiveClass );
          }, this) );

          draggable.bind('drag', $.proxy( function( event, ui ){
            this._dragging( event , ui );
          }, this) );

          draggable.bind('dragstop', $.proxy( function( event, ui ){
            this._dragStop( event , ui );
            this.container.removeClass( this.options.containerActiveClass );
          }, this) );

          if(this.options.overlay){
            var overlay      = this._insertOverlay();
            draggable.bind('drag', $.proxy( function ( event, ui ) {
              this._adaptOverlay( ui );
            }, this) );
          }

          if(this.options.centered){
            position = {x: 0.5, y: 0.5};
          }

          if( position && ( position.x !== 0 || position.y !== 0)) {
            this.move(position);
          }

        },

        _dragStart: function( event, ui ) {
          this._trigger('start', event, this._getPosition(ui) );
        },

        _dragging: function( event, ui ) {
          this._trigger('drag', event, this._getPosition(ui) );
        },

        _dragStop: function( event, ui ) {
          this._trigger('stop', event, this._getPosition(ui) );
        },

        _adaptOverlay: function( ui ) {

          if ( this.axis === 'x' ) {

            this.overlay.css('left', ui.position.left)
                        .css('border-left-width', -ui.position.left)
                        .css('right', -ui.position.left - this.offsetX)
                        .css('border-right-width', ui.position.left + this.offsetX);

          } else if ( this.axis === 'y' ){

            this.overlay.css('top', ui.position.top)
                        .css('border-top-width', -ui.position.top)
                        .css('bottom', -ui.position.top - this.offsetY )
                        .css('border-bottom-width', ui.position.top + this.offsetY );

          }

        },

        _insertContainment: function() {

{'fraction_non_alphanumeric': 0.13992630216113933, 'fraction_numerical': 0.0028881585499452244, 'mean_word_length': 1.548084242578026, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 8, 'https://': 2, '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': '76116', 'n_tokens_mistral': 2835, 'n_tokens_neox': 2699, 'n_words': 553}