window.CopyTheCodeToClipboard = (function(window, document, navigator) { var textArea, copy; function isOS() { return navigator.userAgent.match(/ipad|iphone/i); } function createTextArea(text) { textArea = document.createElement('textArea'); textArea.value = text; document.body.appendChild(textArea); } function selectText() { var range, selection; if (isOS()) { range = document.createRange(); range.selectNodeContents(textArea); selection = window.getSelection(); selection.removeAllRanges(); selection.addRange(range); textArea.setSelectionRange(0, 999999); } else { textArea.select(); } } function copyToClipboard() { document.execCommand('copy'); document.body.removeChild(textArea); } copy = function(text) { createTextArea(text); selectText(); copyToClipboard(); }; return { copy: copy }; })(window, document, navigator); (function($) { CopyTheCodePage = { /** * Init */ init: function() { this._bind(); this._preview(); $('.copy-the-code .nav-tab-wrapper > .nav-tab:first-child').addClass('nav-tab-active'); }, _bind: function() { $( document ).on('input', '[name="button-text"], [name="button-copy-text"], [name="button-title"]', CopyTheCodePage._preview ); $( document ).on('change', '[name="style"], [name="button-position"]', CopyTheCodePage._preview ); $( document ).on('click', '.copy-the-code-button', CopyTheCodePage.copyCode ); }, /** * Copy to Clipboard */ copyCode: function( event ) { var btn = $( this ), preview = $('#preview').find('pre'), source = btn.parents('.copy-the-code-wrap').find( preview ), oldText = btn.text(); var buttonMarkup = $('.copy-the-code-wrap').html() || ''; var copy_as = 'text'; var button_text = $( '[name="button-text"]' ).val() || ''; var button_copy_text = $( '[name="button-copy-text"]' ).val() || ''; var style = $( '[name="style"]' ).val() || 'button'; if( 'text' === copy_as ) { var html = source.text(); // Remove the 'copy' text. var tempHTML = html.replace(button_text, ''); } else { var html = source.html(); // Remove the button. var tempHTML = html.replace(buttonMarkup, ''); } // Copy the Code. var tempPre = $("