<commit_before>
schnipp.ui.dialog_count = 5
/**
 * @constructor
 * @description
 * The schnipp dialog.
 **/
schnipp.ui.BaseDialog = function(config) {

    var self = {}
    self.events = schnipp.events.event_support()
    self.dom = {}
    self.dom.main = $('\
        <div class="schnipp-dialog">\
            <div class="schnipp-dialog-inner">\
                <a class="schnipp-dialog-close"><i class="fa fa-times"></i></a>\
                <div class="schnipp-dialog-header"></div>\
                <div class="schnipp-dialog-content"</div>\
            </div>\
        </div>\
    ')
    self.dom.content = self.dom.main.find('.schnipp-dialog-content')
    self.dom.header = self.dom.main.find('.schnipp-dialog-header')
    self.dom.close = self.dom.main.find('.schnipp-dialog-close')
    self._zindex = 1

    self.config = {
        draggable: false
    }
    self.config = $.extend(self.config, config)
    /**
     * The constructor containing the controler code binding events and appending
     * the dialog dom node to document. 
     **/
    self.init = function() {
        self.dom.close.click(self.close)
        self.dom.main.click(self.focus)
        $('body').append(self.dom.main)
        
        self.dom.main.css('z-index', self.get_new_zindex())
        
        if (self.config.draggable) {
            self.dom.main.draggable({handle: '.schnipp-dialog-header'})
            self.dom.main.addClass('schnipp-dialog-draggable')
        }
        
        return self
    }
    
    /**
     * Sets the content of the dialog. Triggers a content-change event on the dialog instance.
     *
     * @param {string} content The content that is set.
     **/
    self.set_content = function(content) {
        self.dom.content.empty()
        self.dom.content.append(content)
        self._center()
        self.events.fire('content-change', {
            evt: 'content-change',
            dialog: self,
            content: content
        })
    }  
      
    /**
     * Sets the title of the dialog. 
     * Triggers a title-change event on the dialog instance.
     *
     * @param {string} title The title that is set.
     **/
    self.set_title = function(title) {
        self.dom.header.empty()
        self.dom.header.addClass('dialog-has-title')
        self.dom.header.append(title)
        self.events.fire('title-change', {
            evt: 'title-change',
            dialog: self,
            content: title
        })
    }  
    
    /**
     * Shows the dialog if its display attribute is none. 
     * Triggers a show event on the dialog instance.
     **/    
    self.show = function() {
        self.events.trigger('show')
        self.dom.main.show('fade', function() {
            self.events.fire('show', {
                evt: 'show',
                dialog: self
            })
        })
        
    }
    
    /**
     * Closes and destroys the dialog of the dialog. Triggers a closes event on the dialog instance.
     **/
    self.close = function() {
        self.events.trigger('close')
        self.dom.main.hide('fade', function() {
            self.dom.main.remove()
                self.events.fire('close', {
                evt: 'close',
                dialog: self
            })
        })
        
    }
    
    /**
     * Private function to center the dialog. 
     **/
    self._center = function() {
        var top = $(window).scrollTop()
        var left = self.dom.main.offset().left
        var width = self.dom.main.width()
        var height = self.dom.main.height()
        
        var window_width = $(window).width()
        var window_height = $(window).height()
        
        var new_top = top + 80
        var new_left = (window_width - width) / 2
        
        self.dom.main.css({'top': new_top + 'px', 'left': new_left + 'px'})    <commit_msg>changed / extended dialog api<commit_after>
schnipp.ui.dialog_count = 5
/**
 * @constructor
 * @description
 * The schnipp dialog.
 **/
schnipp.ui.BaseDialog = function(config) {

    var self = {}
    self.events = schnipp.events.event_support()
    self.dom = {}
    self.dom.main = $('\
        <div class="schnipp-dialog">\
            <div class="schnipp-dialog-inner">\
                <a class="schnipp-dialog-close"><i class="fa fa-times"></i></a>\
                <div class="schnipp-dialog-header"></div>\
                <div class="schnipp-dialog-content"></div>\
            </div>\
        </div>\
    ')
    self.dom.content = self.dom.main.find('.schnipp-dialog-content')
    self.dom.header = self.dom.main.find('.schnipp-dialog-header')
    self.dom.close = self.dom.main.find('.schnipp-dialog-close')
    self._zindex = 1

    self.config = {
        draggable: false
    }
    self.config = $.extend(self.config, config)
    /**
     * The constructor containing the controler code binding events and appending
     * the dialog dom node to document. 
     **/
    self.init = function() {
        self.dom.close.click(self.close)
        self.dom.main.click(self.focus)
        
        self.dom.main.css('z-index', self.get_new_zindex())
        
        if (self.config.draggable) {
            self.dom.main.draggable({handle: '.schnipp-dialog-header'})
            self.dom.main.addClass('schnipp-dialog-draggable')
        }
        
        return self
    }
    
    /**
    *   Appends the dialog to the body in case it hasnt already been added to the dom.
    */
    self.create = function() {
    
        if (!self.exists()) {
            $('body').append(self.dom.main)
        }
    }
    
    self.exists = function() {
        return self.dom.main.closest('body').length > 0
    }
    
    /**
     * Sets the content of the dialog. Triggers a content-change event on the dialog instance.
     *
     * @param {string} content The content that is set.
     **/
    self.set_content = function(content) {
        self.dom.content.empty()
        self.dom.content.append(content)
        self.events.fire('content-change', {
            evt: 'content-change',
            dialog: self,
            content: content
        })
        self._center()
    }  
      
    /**
     * Sets the title of the dialog. 
     * Triggers a title-change event on the dialog instance.
     *
     * @param {string} title The title that is set.
     **/
    self.set_title = function(title) {
        self.dom.header.empty()
        self.dom.header.addClass('dialog-has-title')
        self.dom.header.append(title)
        self.events.fire('title-change', {
            evt: 'title-change',
            dialog: self,
            content: title
        })
    }  
    
    /**
     * Shows the dialog if its display attribute is none. 
     * Triggers a show event on the dialog instance.
     **/    
    self.show = function() {
        self.events.trigger('show')
        self.dom.main.css('display', 'inline-block')
        self.dom.main.show('fade', function() {
            self.events.fire('show', {
                evt: 'show',
                dialog: self
            })
        })
        
    }
    
    /**
     * Closes and destroys the dialog of the dialog. Triggers a closes event on the dialog instance.
     **/
    self.close = function(cb) {
        self.events.trigger('close')
        self.dom.main.hide('fade', cb || function() {})
        self.events.fire('close', {
            evt: 'close',
            dialog: self
        })
    }
    
    
    self.destroy = function() {
        self.close(function() {
            self.dom.main.remove()
        })
    }
    
    
    /**
     * Private function to center the dialog. 
     **/
    self._center = function() {
        var top = $(window).scrollTop()
        var left = self.dom.main.offset().left
        var width = self.dom.main.width()
        var height = self.dom.main.height()
        
        var window_width = $(window).width()
        var window_height = $(window).height()
        
        var new_top = top + 80
        var new_left = (window_width - width) / 2
        
        self.dom.main.css({'top': new_top + 'px', 'left': new_left + 'px', position: 'absolute'})    
{'fraction_non_alphanumeric': 0.1399531846741407, 'fraction_numerical': 0.0013551804854010103, 'mean_word_length': 1.7014975041597338, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, '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': '1747044', 'n_tokens_mistral': 2469, 'n_tokens_neox': 2440, 'n_words': 510}