script.js
174 lines
| 1 | (function($){ |
| 2 | $(document).ready(function(){ |
| 3 | |
| 4 | var delete_ctext = 'Are you sure want to delete this shortcode ?'; |
| 5 | var last_sort = 'desc'; |
| 6 | |
| 7 | var sort = function( ele, orderby ){ |
| 8 | var total = ele.length; |
| 9 | while( total ){ |
| 10 | ele.each(function(){ |
| 11 | var $cur = $(this); |
| 12 | var $next = $cur.next(); |
| 13 | if( $next.length ){ |
| 14 | var cur_name = $cur.attr( 'data-name' ).toLowerCase(); |
| 15 | var nxt_name = $next.attr( 'data-name' ).toLowerCase(); |
| 16 | if( ( orderby == 'asc' && cur_name > nxt_name ) || ( orderby == 'desc' && cur_name < nxt_name ) ){ |
| 17 | $next.after( $cur ); |
| 18 | } |
| 19 | } |
| 20 | }); |
| 21 | total--; |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | $( document ).on( 'click', '.sc_delete', function(e){ |
| 26 | |
| 27 | e.preventDefault(); |
| 28 | |
| 29 | var del_btn = $(this); |
| 30 | var href = del_btn.attr( 'href' ); |
| 31 | var confirm_user = confirm( delete_ctext ); |
| 32 | |
| 33 | if( confirm_user ){ |
| 34 | |
| 35 | var ajax = $.get( href ); |
| 36 | del_btn.addClass( 'spin' ); |
| 37 | |
| 38 | ajax.done(function( data ){ |
| 39 | if( data.search( 'DELETED' ) != -1 ){ |
| 40 | del_btn.closest( 'li' ).fadeOut( 'slow', function(){ |
| 41 | $(this).remove(); |
| 42 | }); |
| 43 | }else{ |
| 44 | alert( 'Delete failed ! - ' + data ); |
| 45 | } |
| 46 | }); |
| 47 | |
| 48 | ajax.fail(function(){ |
| 49 | alert( 'Auth failed !' ); |
| 50 | }); |
| 51 | |
| 52 | } |
| 53 | |
| 54 | }); |
| 55 | |
| 56 | $( document ).on( 'click', '.sc_delete_ep', function(e){ |
| 57 | |
| 58 | e.preventDefault(); |
| 59 | |
| 60 | var $delete_btn = $(this); |
| 61 | var href = $delete_btn.attr( 'href' ); |
| 62 | var confirm_user = confirm( delete_ctext ); |
| 63 | |
| 64 | if( confirm_user ){ |
| 65 | |
| 66 | var ajax = $.get( href ); |
| 67 | $delete_btn.addClass( 'spin' ); |
| 68 | |
| 69 | ajax.done(function( data ){ |
| 70 | if( data.search( 'DELETED' ) != -1 ){ |
| 71 | var back_href = $( '.sc_back_btn' ).attr( 'href' ); |
| 72 | window.location = back_href + '&msg=3'; |
| 73 | }else{ |
| 74 | alert( 'Delete failed ! - ' + data ); |
| 75 | } |
| 76 | }); |
| 77 | |
| 78 | ajax.fail(function(){ |
| 79 | alert( 'Auth failed !' ); |
| 80 | }); |
| 81 | |
| 82 | $delete_btn.removeClass( 'spin' ); |
| 83 | |
| 84 | } |
| 85 | |
| 86 | }); |
| 87 | |
| 88 | $( document ).on( 'click', '.sc_copy', function(e){ |
| 89 | |
| 90 | e.preventDefault(); |
| 91 | |
| 92 | var btn = $(this); |
| 93 | var box = btn.closest( 'li' ).find( '.sc_copy_box' ); |
| 94 | |
| 95 | $( '.sc_copy_box' ).not( box ).hide(); |
| 96 | |
| 97 | box.fadeToggle(); |
| 98 | box.select(); |
| 99 | |
| 100 | }); |
| 101 | |
| 102 | $(window).load(function(){ |
| 103 | $( '.wp-media-buttons' ).append(function(){ |
| 104 | return '<button class="button button-primary sc_insert_params"><span class="dashicons dashicons-plus"></span> Insert shortcode paramerters <span class="dashicons dashicons-arrow-down"></span></button>'; |
| 105 | }); |
| 106 | $( '.params_wrap' ).appendTo( 'body' ); |
| 107 | $( '.quicktags-toolbar' ).append(function(){ |
| 108 | return '<a href="#" class="ed_button button button-small fright sc_enable_vedit" title="Enable visual editor"><span class="dashicons dashicons-visibility"></span></a>'; |
| 109 | }); |
| 110 | }); |
| 111 | |
| 112 | $( document ).on( 'click', '.sc_insert_params', function(e){ |
| 113 | |
| 114 | e.preventDefault(); |
| 115 | |
| 116 | var offset = $(this).offset(); |
| 117 | var mtop = offset.top + $(this).outerHeight(); |
| 118 | |
| 119 | $( '.params_wrap' ).css({ |
| 120 | top: mtop, |
| 121 | left: offset.left |
| 122 | }).toggle(); |
| 123 | }); |
| 124 | |
| 125 | $( document ).on( 'click', '.cp_btn', function(){ |
| 126 | |
| 127 | var $cp_box = $( '.cp_box' ); |
| 128 | var $cp_info = $( '.cp_info' ); |
| 129 | var param_val = $cp_box.val().trim(); |
| 130 | |
| 131 | if( param_val != '' && $cp_box[0].checkValidity() ){ |
| 132 | send_to_editor( '%%' + param_val + '%%' ); |
| 133 | $cp_info.removeClass( 'red' ); |
| 134 | $( '.params_wrap' ).hide(); |
| 135 | }else{ |
| 136 | $cp_info.addClass( 'red' ); |
| 137 | } |
| 138 | |
| 139 | }); |
| 140 | |
| 141 | $( document ).on( 'click', '.wp_params li', function(){ |
| 142 | |
| 143 | send_to_editor( '$$' + $(this).data( 'id' ) + '$$' ); |
| 144 | $( '.params_wrap' ).hide(); |
| 145 | |
| 146 | }); |
| 147 | |
| 148 | $( document ).on( 'change', '.coffee_amt', function(){ |
| 149 | var btn = $( '.buy_coffee_btn' ); |
| 150 | btn.attr( 'href', btn.data( 'link' ) + $(this).val() ); |
| 151 | }); |
| 152 | |
| 153 | $( document ).on( 'click', '.sort_btn', function(){ |
| 154 | last_sort = ( last_sort == 'asc' ) ? 'desc' : 'asc'; |
| 155 | sort( $( '.sc_list li' ), last_sort ); |
| 156 | $( '.sort_icon' ).toggleClass( 'dashicons-arrow-down-alt' ); |
| 157 | $( '.sort_icon' ).toggleClass( 'dashicons-arrow-up-alt' ); |
| 158 | }); |
| 159 | |
| 160 | $( document ).on( 'change', '#import', function(){ |
| 161 | |
| 162 | if( confirm( $( '.import_desc' ).text() ) ){ |
| 163 | $( '#import_form' ).submit(); |
| 164 | } |
| 165 | |
| 166 | }); |
| 167 | |
| 168 | $( document ).on( 'click', '.sc_enable_vedit', function(e){ |
| 169 | e.preventDefault(); |
| 170 | window.location = window.location + '&visual_edit=1'; |
| 171 | }); |
| 172 | |
| 173 | }); |
| 174 | })( jQuery ); |