| @@ -116,5 +116,79 @@ | ||
| 116 | 116 | |
| 117 | 117 | if ($('.winp-field-premium-element').length > 0) { |
| 118 | 118 | $('.winp-field-premium-element').wrap('<div class="winp-field-premium-icon"></div>'); |
| 119 | 119 | } |
| 120 | + | |
| 121 | + // Handle click on shortcode input to copy to clipboard | |
| 122 | + $('input.wbcr_inp_shortcode_input').on('click', function (e) { | |
| 123 | + var input = $(this); | |
| 124 | + var value = input.val(); | |
| 125 | + | |
| 126 | + // Select the text | |
| 127 | + this.setSelectionRange(0, this.value.length); | |
| 128 | + | |
| 129 | + // Copy to clipboard | |
| 130 | + if (navigator.clipboard && navigator.clipboard.writeText) { | |
| 131 | + // Modern clipboard API | |
| 132 | + navigator.clipboard.writeText(value).then(function() { | |
| 133 | + showCopyNotice(input); | |
| 134 | + }).catch(function(err) { | |
| 135 | + console.error('Failed to copy:', err); | |
| 136 | + fallbackCopy(input); | |
| 137 | + }); | |
| 138 | + } else { | |
| 139 | + // Fallback for older browsers | |
| 140 | + fallbackCopy(input); | |
| 141 | + } | |
| 142 | + }); | |
| 143 | + | |
| 144 | + function fallbackCopy(input) { | |
| 145 | + try { | |
| 146 | + input[0].select(); | |
| 147 | + var successful = document.execCommand('copy'); | |
| 148 | + if (successful) { | |
| 149 | + showCopyNotice(input); | |
| 150 | + } | |
| 151 | + } catch (err) { | |
| 152 | + console.error('Failed to copy:', err); | |
| 153 | + } | |
| 154 | + } | |
| 155 | + | |
| 156 | + function showCopyNotice(input) { | |
| 157 | + // Remove any existing notices | |
| 158 | + $('.winp-copy-notice').remove(); | |
| 159 | + | |
| 160 | + // Create and show notice | |
| 161 | + var notice = $('<div class="winp-copy-notice"><span>Copied to clipboard!</span></div>'); | |
| 162 | + input.after(notice); | |
| 163 | + | |
| 164 | + // Position the notice | |
| 165 | + notice.css({ | |
| 166 | + position: 'absolute', | |
| 167 | + background: '#6366f1', | |
| 168 | + color: '#fff', | |
| 169 | + borderRadius: '3px', | |
| 170 | + fontSize: '12px', | |
| 171 | + zIndex: 1000, | |
| 172 | + whiteSpace: 'nowrap', | |
| 173 | + boxShadow: '0 2px 5px rgba(0,0,0,0.2)', | |
| 174 | + height: '38px', | |
| 175 | + width: '100%', | |
| 176 | + marginTop: '-10px', | |
| 177 | + }); | |
| 178 | + | |
| 179 | + // Style the span | |
| 180 | + notice.find('span').css({ | |
| 181 | + display: 'flex', | |
| 182 | + justifyContent: 'center', | |
| 183 | + alignItems: 'center', | |
| 184 | + height: '100%' | |
| 185 | + }); | |
| 186 | + | |
| 187 | + // Fade out and remove after 2 seconds | |
| 188 | + setTimeout(function() { | |
| 189 | + notice.fadeOut(300, function() { | |
| 190 | + notice.remove(); | |
| 191 | + }); | |
| 192 | + }, 2000); | |
| 193 | + } | |
| 120 | 194 | }); |