script-insert.js
67 lines
| 1 | (function($){ |
| 2 | |
| 3 | $(document).ready(function(){ |
| 4 | |
| 5 | var send_editor = function( content = '' ){ |
| 6 | if( typeof parent.send_to_editor === 'function' ){ |
| 7 | parent.send_to_editor( content ); |
| 8 | }else{ |
| 9 | alert( 'Editor does not exist. Cannot insert content !' ); |
| 10 | } |
| 11 | } |
| 12 | |
| 13 | var close_window = function(){ |
| 14 | if( typeof parent.tb_remove === 'function' ){ |
| 15 | parent.tb_remove(); |
| 16 | } |
| 17 | } |
| 18 | |
| 19 | $('.sc_shortcode_name').append('<span class="sc_toggle"></span>'); |
| 20 | |
| 21 | $( document ).on( 'click', '.sc_insert', function(){ |
| 22 | |
| 23 | var params = ''; |
| 24 | var scname = $(this).closest( '.sc_shortcode' ).attr( 'data-name' ); |
| 25 | var sc = ''; |
| 26 | |
| 27 | $(this).parent().children().find('input[type="text"]').each(function(){ |
| 28 | if($(this).val() != ''){ |
| 29 | attr = $(this).attr('data-param'); |
| 30 | val = $(this).val().replace( /\"/g, '' ); |
| 31 | params += attr + '="' + val + '" '; |
| 32 | } |
| 33 | }); |
| 34 | |
| 35 | sc = '[sc name="' + scname + '" ' + params + ']'; |
| 36 | send_editor( sc ); |
| 37 | close_window(); |
| 38 | |
| 39 | }); |
| 40 | |
| 41 | $( document ).on( 'click', '.sc_quick_insert', function(){ |
| 42 | |
| 43 | var scname = $(this).closest( '.sc_shortcode' ).attr( 'data-name' ); |
| 44 | var sc = '[sc name="' + scname + '"]'; |
| 45 | |
| 46 | send_editor( sc ); |
| 47 | close_window(); |
| 48 | |
| 49 | }); |
| 50 | |
| 51 | $( document ).on( 'click', '.sc_shortcode_name', function(e){ |
| 52 | $('.sc_params').slideUp(); |
| 53 | if($(this).next('.sc_params').is(':visible')){ |
| 54 | $(this).next('.sc_params').slideUp(); |
| 55 | }else{ |
| 56 | $(this).next('.sc_params').slideDown(); |
| 57 | } |
| 58 | }); |
| 59 | |
| 60 | $( document ).on( 'change', '.coffee_amt', function(){ |
| 61 | var btn = $( '.buy_coffee_btn' ); |
| 62 | btn.attr( 'href', btn.data( 'link' ) + $(this).val() ); |
| 63 | }); |
| 64 | |
| 65 | }); |
| 66 | |
| 67 | })( jQuery ); |