1(function ($) { 2 const CTCAIPromptGenerator = { 3 4 /** 5 * Init 6 */ 7 init: function () { 8 this._bind(); 9 this._generate(); 10 }, 11 12 /** 13 * Binds events 14 */ 15 _bind: function () { 16 $( document ).on( 'click', '.ctc-ai-generator-button', this.doCopy ); 17 $( document ).on( 'input', '.ctc-ai-prompt-generator input', this.doChange ); 18 }, 19 20 /** 21 * Do Change 22 */ 23 doChange: function (event) { 24 event.preventDefault(); 25 26 CTCAIPromptGenerator._generate(); 27 }, 28 29 /** 30 * Do Copy to Clipboard 31 */ 32 doCopy: function (event) { 33 event.preventDefault(); 34 35 const self = $( this ) 36 const parent = self.parents( '.ctc-ai-prompt-generator' ) 37 const textarea = parent.find( '.ctc-ai-prompt-generator-textarea' ) 38 let text = textarea.val() || '' 39 40 // Remove first and last new line. 41 text = $.trim( text ); 42 43 // Copy to clipboard. 44 CTCWP.copy( text ); 45 46 // Copied! 47 parent.addClass( 'copied' ); 48 setTimeout( 49 function () { 50 parent.removeClass( 'copied' ); 51 }, 52 1000 53 ); 54 }, 55 56 /** 57 * Generate 58 */ 59 _generate: function () { 60 const blocks = $( '.ctc-ai-prompt-generator' ) 61 62 blocks.each( 63 function() { 64 const fields = $( this ).find( '.ctc-block-field' ) 65 const textarea = $( this ).find( '.ctc-ai-prompt-generator-textarea' ) 66 let markup = '' 67 68 fields.each( 69 function() { 70 const label = $( this ).find( '.ctc-block-field-label' ).text() 71 const value = $( this ).find( 'input' ).val() || '' 72 73 if ( ! value ) { 74 return 75 } 76 77 markup += label + ': ' + value + '\n' 78 } 79 ) 80 81 textarea.val( markup ) 82 } 83 ) 84 } 85 86 }; 87 88 /** 89 * Initialization 90 */ 91 $( 92 function () { 93 CTCAIPromptGenerator.init(); 94 } 95 ); 96 97})( jQuery );
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.