<commit_before>/* global jQuery Markdown document setTimeout: true*/

(function ($) {
    "use strict";
    var preventClick = false;

    function Editor(element, options){
        var self = this;
        self.el = element;
        self.$el = $(element);
        self.options = options;
        self.init();
        return self;
    }

    Editor.prototype = {
        init: function(){

            var self = this;
            self.$el.on("click", function(){
                self.toggleEdition();
            });

            self.$el.on("blur", function(){
                self.saveEdition();
            });

            self.$el.on("mouseover mouseleave", function(event){
                self.hoverElement(event);
            });

            $(".editable").bind("hallomodified", function(event, data) {
                $("#modified").html("Editables modified");
            });

            if (self.options.preventBlurOnClick !== ""){
                $(document).on("mousedown", self.options.preventBlurOnClick, function(event){
                    event.stopPropagation();
                    preventClick = true;
                });
            }
        },

        hoverElement: function(event){
            var self = this;
            if (event.type === "mouseover"){
                self.$el.addClass("hover-editable");
            }else{
                self.$el.removeClass("hover-editable");
            }
        },

        getId: function() {
            var self = this;
            var slug = self.$el.attr(self.options.uniqueIdentifier);
            if( !slug ) {
                slug = self.$el.parents(
                    "[" + self.options.uniqueIdentifier + "]").attr(
                        self.options.uniqueIdentifier);
            }
            if( !slug ) {
                slug = "undefined";
            }
            return slug;
        },

        getOriginText: function(){
            var self = this;
            self.originText = $.trim(self.$el[0].outerHTML);
            return self.originText;
        },

        toogleStartOptional: function(){
            return true;
        },

        toogleEndOptional: function(){
            return true;
        },

        initHallo: function(){
            var self = this;
            self.$el.hallo().focus();
        },

        toggleEdition: function(){
            var self = this;
            self.initHallo();
            self.getOriginText();
            self.$el.attr("placeholder", self.options.emptyInputText);
        },

        getSavedText: function(){
            var self = this;
            return self.$el.html();
        },

        checkInput: function(){
            var self = this;
            if (self.$el.html() === ""){
                return false;
            }else{
                return true;
            }
        },

        formatDisplayedValue: function(){
            return true;
        },

        saveEdition: function(){
            var self = this;
            var savedText = self.getSavedText();
            if (!self.checkInput()){
                return false;
            }

            var data = {};
            var method = "PUT";

            if (self.$el.attr("data-key")){
                method = "PATCH";
                data[self.$el.attr("data-key")] = $.trim(savedText);
            } else {
                data = {
                    slug: self.getId(),
                    text: $.trim(savedText)
                };
            }

            if (self.options.debug){
                console.log(data);
            }else{
                $.ajax({
                    method: method,
                    url: self.options.baseUrl + self.getId() + "/",
                    data: data,
                    success: function(response) {<commit_msg>use PUT since phantomjs does not do PATCH correctly<commit_after>/* global jQuery Markdown document setTimeout: true*/

(function ($) {
    "use strict";
    var preventClick = false;

    function Editor(element, options){
        var self = this;
        self.el = element;
        self.$el = $(element);
        self.options = options;
        self.init();
        return self;
    }

    Editor.prototype = {
        init: function(){

            var self = this;
            self.$el.on("click", function(){
                self.toggleEdition();
            });

            self.$el.on("blur", function(){
                self.saveEdition();
            });

            self.$el.on("mouseover mouseleave", function(event){
                self.hoverElement(event);
            });

            $(".editable").bind("hallomodified", function(event, data) {
                $("#modified").html("Editables modified");
            });

            if (self.options.preventBlurOnClick !== ""){
                $(document).on("mousedown", self.options.preventBlurOnClick, function(event){
                    event.stopPropagation();
                    preventClick = true;
                });
            }
        },

        hoverElement: function(event){
            var self = this;
            if (event.type === "mouseover"){
                self.$el.addClass("hover-editable");
            }else{
                self.$el.removeClass("hover-editable");
            }
        },

        getId: function() {
            var self = this;
            var slug = self.$el.attr(self.options.uniqueIdentifier);
            if( !slug ) {
                slug = self.$el.parents(
                    "[" + self.options.uniqueIdentifier + "]").attr(
                        self.options.uniqueIdentifier);
            }
            if( !slug ) {
                slug = "undefined";
            }
            return slug;
        },

        getOriginText: function(){
            var self = this;
            self.originText = $.trim(self.$el[0].outerHTML);
            return self.originText;
        },

        toogleStartOptional: function(){
            return true;
        },

        toogleEndOptional: function(){
            return true;
        },

        initHallo: function(){
            var self = this;
            self.$el.hallo().focus();
        },

        toggleEdition: function(){
            var self = this;
            self.initHallo();
            self.getOriginText();
            self.$el.attr("placeholder", self.options.emptyInputText);
        },

        getSavedText: function(){
            var self = this;
            return self.$el.html();
        },

        checkInput: function(){
            var self = this;
            if (self.$el.html() === ""){
                return false;
            }else{
                return true;
            }
        },

        formatDisplayedValue: function(){
            return true;
        },

        saveEdition: function(){
            var self = this;
            var savedText = self.getSavedText();
            if (!self.checkInput()){
                return false;
            }

            var data = {};
            var method = "PUT";

            if (self.$el.attr("data-key")){
                data[self.$el.attr("data-key")] = $.trim(savedText);
            } else {
                data = {
                    slug: self.getId(),
                    text: $.trim(savedText)
                };
            }

            if( self.options.debug ){
                console.log(data);
            } else {
                $.ajax({
                    method: method,
                    url: self.options.baseUrl + self.getId() + "/",
                    data: JSON.stringify(data),
                    datatype: "json",
                    contentType: "application/json; charset=utf-8",
                    success: function(response) {
{'fraction_non_alphanumeric': 0.13037860188654865, 'fraction_numerical': 0.0003876469828143171, 'mean_word_length': 1.2032450896669513, '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': '4919244', 'n_tokens_mistral': 1988, 'n_tokens_neox': 1887, 'n_words': 385}