<commit_before>jQuery(function ($) {
    
    'use strict';

    var
    cache                   = {},
    working                 = false,
    selectedHubId           = '',
    doneTypingInterval      = 500,
    keyword,
    typingTimer,
    selectedNode,
    gcwindow,
    gcwindowData,
    textbox;

    /* GC TinyMCE Plugin */
    tinymce.PluginManager.add('graphcommons', function(editor, url) {        

        $(document).on('click', '#insert-graphcommons-node', function(e){
            e.preventDefault();
            wp.mce.graphcommons.popupwindow(editor);                        
        });

    /*
        // contentEditable bug copying the last class used! remove it when enter key is pressed!
        tinyMCE.editors.content.on('keyup',function(e){
            if ( 13 === e.keyCode ) {
               $(tinyMCE.editors.content.selection.getNode()).closest('p').removeAttr('class');
            }
        });
    */

    }); // tinymce plugin ******************************************************************************


    var media = wp.media, shortcode_string = 'graphcommons';
    wp.mce = wp.mce || {};
    wp.mce.graphcommons = {
        shortcode_data: {},
        template: media.template( 'editor-graphcommons' ),
        getContent: function() {
            var options = this.shortcode.attrs.named;
            options['innercontent'] = this.shortcode.content;
            console.log("options", options);
            return this.template(options);
        },
        View: { // before WP 4.2:
            template: media.template( 'editor-graphcommons' ),
            postID: $('#post_ID').val(),
            initialize: function( options ) {
                this.shortcode = options.shortcode;
                wp.mce.graphcommons.shortcode_data = this.shortcode;
            },
            getHtml: function() {
                var options = this.shortcode.attrs.named;
                options['innercontent'] = this.shortcode.content;
                return this.template(options);
            }
        },
        edit: function( data, update ) {
            console.log("editting", data, update);
            var shortcode_data = wp.shortcode.next(shortcode_string, data);
            var values = shortcode_data.shortcode.attrs.named;
            values['innercontent'] = shortcode_data.shortcode.content;
            wp.mce.graphcommons.popupwindow(tinyMCE.activeEditor, values);
        },
        // this is called from our tinymce plugin, also can call from our "edit" function above
        // wp.mce.graphcommons.popupwindow(tinyMCE.activeEditor, "bird");
        popupwindow: function(editor, values, onsubmit_callback){
            values = values || [];
            if(typeof onsubmit_callback != 'function'){
                onsubmit_callback = function( e ) {
                    // Insert content when the window form is submitted (this also replaces during edit, handy!)
                    var s = '[' + shortcode_string;
                    for(var i in e.data){
                        if(e.data.hasOwnProperty(i) && i != 'innercontent'){
                            s += ' ' + i + '="' + e.data[i] + '"';
                        }
                    }
                    s += ']';
                    if(typeof e.data.innercontent != 'undefined'){
                        s += e.data.innercontent;
                        s += '[/' + shortcode_string + ']';
                    }
                    editor.insertContent( s );
                    console.log("onsubmit from popupwindow");
                };
            }
            editor.windowManager.open( {
                title: graphcommons.language.addgcnodecard,
                width: 800,
                height: 580,
                buttons: [],
                onPostRender: function(e){
                    // console.log(e.data.title);
                    var self = this;
                    textbox = $('#'+self._id).find('input');                    

                    $(textbox).attr('placeholder', graphcommons.language.searchkeyword);
                    $(textbox).attr('type', 'search');
                    $(textbox).css('padding-left', '10px');
                    
                    $(textbox).on('keyup', function(){
                        keyword = $(this).val().trim();
                        // console.log("typing", keyword);
                        clearTyperTimeout();
                    });

                    $(document).on('click', '.tt-suggestion', function(e){
                        e.preventDefault();
                        gcwindowData = $(this).data();
                        // editor.execCommand('open_preview');
                        // self.close();
                        // console.log("data",data);
                        wp.mce.graphcommons.popupwindowPreview(tinyMCE.activeEditor, "heyya");
                    } );            
                    console.log("values-->", values);
                },

                body:[
                        {
                            type    : 'textbox',
                            name    : 'search',
                            value  : values['name']
                        },

                        {
                            type: 'listbox', 
                            name: 'gc_hubs', 
                            value: values['hub'],
                            values: graphcommons.hubs,
                            onselect: function(e) {
                                selectedHubId = this.value();
                                cache = {};
                                clearTyperTimeout();
                                $(textbox).trigger('keyup');
                            }
                        },
                        {
                            type    : 'container',
                            name    : 'container',
                            html    : '<div id="gc_content" class="gc_content">' + graphcommons.language.typesomething + '</div>',
                        },

                    ],


                onsubmit: onsubmit_callback
            } );
        },
        popupwindowPreview: function(editor, values, onsubmit_callback){

            values = values || [];
            if(typeof onsubmit_callback != 'function'){
                onsubmit_callback = function( e ) {
                    // Insert content when the window form is submitted (this also replaces during edit, handy!)
                    var s = '[' + shortcode_string;
                    for(var i in e.data){
                        if(e.data.hasOwnProperty(i) && i != 'innercontent'){
                            s += ' ' + i + '="' + e.data[i] + '"';
                        }
                    }
                    s += ']';
                    if(typeof e.data.innercontent != 'undefined'){
                        s += e.data.innercontent;
                        s += '[/' + shortcode_string + ']';
                    }
                    editor.insertContent( s );
                    // console.log("onsubmit from popupwindowPreview");
                };
            }

            editor.windowManager.open( {
                title: graphcommons.language.nodepreview,
                body: [
                    {
                    type   : 'container',
                    name   : 'container',
                    html   : '<iframe src="https://graphcommons.com/nodes/'+gcwindowData.gcId+'/embed?p=&et=i%C5%9F%20orta%C4%9F%C4%B1d%C4%B1r&g=true" frameborder="0" style="overflow:auto;width:320px;min-width:320px;height:100%;min-height:460px;border:1px solid #CCCCCC;" width="320" height="460"></iframe>'
                    }

                ],
                onsubmit: function( e ) {                    
                    var self = this;
                    console.log("added");
                    var new_shortcode_str = '[graphcommons embed="node" id="'+gcwindowData.gcId+'" name="'+gcwindowData.gcName+'" type="'+gcwindowData.gcNodeType+'"][/graphcommons]';

                    editor.insertContent( new_shortcode_str );

                    wp.mce.graphcommons.shortcode_data = wp.shortcode.next('graphcommons', new_shortcode_str);

                    tinyMCE.activeEditor.windowManager.close();
                    tinyMCE.activeEditor.windowManager.windows[0].close();                    
                },
                onclose: function(){
                    keyword = '';
                    gcwindowData = {};
                },
                oncancel: function(){
                    // console.log("canceled");
                }
            });

        }
    };
    wp.mce.views.register( shortcode_string, wp.mce.graphcommons );

<commit_msg>cursor to the end of the input box when editing node card<commit_after>jQuery(function ($) {
    
    'use strict';

    var
    cache                   = {},
    working                 = false,
    selectedHubId           = '',
    doneTypingInterval      = 500,
    keyword,
    typingTimer,
    selectedNode,
    gcwindow,
    gcwindowData,
    textbox;

    /* GC TinyMCE Plugin */
    tinymce.PluginManager.add('graphcommons', function(editor, url) {        

        $(document).on('click', '#insert-graphcommons-node', function(e){
            e.preventDefault();
            wp.mce.graphcommons.popupwindow(editor);                        
        });

    /*
        // contentEditable bug copying the last class used! remove it when enter key is pressed!
        tinyMCE.editors.content.on('keyup',function(e){
            if ( 13 === e.keyCode ) {
               $(tinyMCE.editors.content.selection.getNode()).closest('p').removeAttr('class');
            }
        });
    */

    }); // tinymce plugin ******************************************************************************


    var media = wp.media, shortcode_string = 'graphcommons';
    wp.mce = wp.mce || {};
    wp.mce.graphcommons = {
        shortcode_data: {},
        template: media.template( 'editor-graphcommons' ),
        getContent: function() {
            var options = this.shortcode.attrs.named;
            options['innercontent'] = this.shortcode.content;
            console.log("options", options);
            return this.template(options);
        },
        View: { // before WP 4.2:
            template: media.template( 'editor-graphcommons' ),
            postID: $('#post_ID').val(),
            initialize: function( options ) {
                this.shortcode = options.shortcode;
                wp.mce.graphcommons.shortcode_data = this.shortcode;
            },
            getHtml: function() {
                var options = this.shortcode.attrs.named;
                options['innercontent'] = this.shortcode.content;
                return this.template(options);
            }
        },
        edit: function( data, update ) {
            console.log("editting", data, update);
            var shortcode_data = wp.shortcode.next(shortcode_string, data);
            var values = shortcode_data.shortcode.attrs.named;
            values['innercontent'] = shortcode_data.shortcode.content;
            wp.mce.graphcommons.popupwindow(tinyMCE.activeEditor, values);
        },
        // this is called from our tinymce plugin, also can call from our "edit" function above
        // wp.mce.graphcommons.popupwindow(tinyMCE.activeEditor, "bird");
        popupwindow: function(editor, values, onsubmit_callback){
            values = values || [];
            if(typeof onsubmit_callback != 'function'){
                onsubmit_callback = function( e ) {
                    // Insert content when the window form is submitted (this also replaces during edit, handy!)
                    var s = '[' + shortcode_string;
                    for(var i in e.data){
                        if(e.data.hasOwnProperty(i) && i != 'innercontent'){
                            s += ' ' + i + '="' + e.data[i] + '"';
                        }
                    }
                    s += ']';
                    if(typeof e.data.innercontent != 'undefined'){
                        s += e.data.innercontent;
                        s += '[/' + shortcode_string + ']';
                    }
                    editor.insertContent( s );
                    console.log("onsubmit from popupwindow");
                };
            }
            editor.windowManager.open( {
                title: graphcommons.language.addgcnodecard,
                width: 800,
                height: 580,
                buttons: [],
                onPostRender: function(e){
                    // console.log(e.data.title);
                    var self = this;
                    textbox = $('#'+self._id).find('input');                    

                    $(textbox).attr({
                        'placeholder'   : graphcommons.language.searchkeyword,
                        'type'          : 'search',
                        'onfocus'       : 'this.value = this.value;'
                    });

                    $(textbox).css('padding-left', '10px');
                    
                    $(textbox).on('keyup', function(){
                        keyword = $(this).val().trim();
                        // console.log("typing", keyword);
                        clearTyperTimeout();
                    });

                    $(document).on('click', '.tt-suggestion', function(e){
                        e.preventDefault();
                        gcwindowData = $(this).data();
                        // editor.execCommand('open_preview');
                        // self.close();
                        // console.log("data",data);
                        wp.mce.graphcommons.popupwindowPreview(tinyMCE.activeEditor, "n");
                    } );            

                },

                body:[
                        {
                            type    : 'textbox',
                            name    : 'search',
                            value  : values['name']
                        },

                        {
                            type: 'listbox', 
                            name: 'gc_hubs', 
                            value: values['hub'],
                            values: graphcommons.hubs,
                            onselect: function(e) {
                                selectedHubId = this.value();
                                cache = {};
                                clearTyperTimeout();
                                $(textbox).trigger('keyup');
                            }
                        },
                        {
                            type    : 'container',
                            name    : 'container',
                            html    : '<div id="gc_content" class="gc_content">' + graphcommons.language.typesomething + '</div>',
                        },

                    ],


                onsubmit: onsubmit_callback
            } );
        },
        popupwindowPreview: function(editor, values, onsubmit_callback){

            values = values || [];
            if(typeof onsubmit_callback != 'function'){
                onsubmit_callback = function( e ) {
                    // Insert content when the window form is submitted (this also replaces during edit, handy!)
                    var s = '[' + shortcode_string;
                    for(var i in e.data){
                        if(e.data.hasOwnProperty(i) && i != 'innercontent'){
                            s += ' ' + i + '="' + e.data[i] + '"';
                        }
                    }
                    s += ']';
                    if(typeof e.data.innercontent != 'undefined'){
                        s += e.data.innercontent;
                        s += '[/' + shortcode_string + ']';
                    }
                    editor.insertContent( s );
                    // console.log("onsubmit from popupwindowPreview");
                };
            }

            editor.windowManager.open( {
                title: graphcommons.language.nodepreview,
                body: [
                    {
                    type   : 'container',
                    name   : 'container',
                    html   : '<iframe src="https://graphcommons.com/nodes/'+gcwindowData.gcId+'/embed?p=&et=i%C5%9F%20orta%C4%9F%C4%B1d%C4%B1r&g=true" frameborder="0" style="overflow:auto;width:320px;min-width:320px;height:100%;min-height:460px;border:1px solid #CCCCCC;" width="320" height="460"></iframe>'
                    }

                ],
                onsubmit: function( e ) {                    
                    var self = this;
                    
                    var new_shortcode_str = '[graphcommons embed="node" id="'+gcwindowData.gcId+'" name="'+gcwindowData.gcName+'" type="'+gcwindowData.gcNodeType+'"][/graphcommons]';

                    wp.mce.graphcommons.shortcode_data = wp.shortcode.next('graphcommons', new_shortcode_str);

                    /*
                    tinyMCE.activeEditor.windowManager.close();
                    tinyMCE.activeEditor.windowManager.windows[0].close();    
                    */                

                    for (var i = tinyMCE.activeEditor.windowManager.windows.length - 1; i >= 0; i--) {
                        tinyMCE.activeEditor.windowManager.windows[i].close();
                    }
    
                    editor.insertContent( new_shortcode_str );

                    console.log("node card added");

                },
                onclose: function(){
                    keyword = '';
                    gcwindowData = {};
                },
                oncancel: function(){
                    // console.log("canceled");
                }
            });

        }
    };
    wp.mce.views.register( shortcode_string, wp.mce.graphcommons );


{'fraction_non_alphanumeric': 0.12898356256289836, 'fraction_numerical': 0.005255507100525551, 'mean_word_length': 1.1842715838319697, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4718438', 'n_tokens_mistral': 4547, 'n_tokens_neox': 4204, 'n_words': 742}