Changeset 1699247
- Timestamp:
- 07/20/2017 12:58:32 AM (9 years ago)
- Location:
- shortcode-mastery-lite
- Files:
-
- 4 edited
-
tags/1.0.1/css/shortcode-mastery-admin.css (modified) (1 diff)
-
tags/1.0.1/js/shortcode-mastery-ajax.js (modified) (1 diff)
-
trunk/css/shortcode-mastery-admin.css (modified) (1 diff)
-
trunk/js/shortcode-mastery-ajax.js (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
shortcode-mastery-lite/tags/1.0.1/css/shortcode-mastery-admin.css
r1699246 r1699247 752 752 753 753 h1 span.version { 754 font-size: 13px; 755 padding-top: 13px; 756 padding-left: 7px; 757 color: #555d66; 754 font-size: 11px; 755 padding: 1px 7px; 756 color: #f1f1f1; 757 font-weight: bold; 758 background: #3498db; 759 border-radius: 20px; 760 position: relative; 761 top: 0px; 762 left: 5px; 758 763 } 759 764 -
shortcode-mastery-lite/tags/1.0.1/js/shortcode-mastery-ajax.js
r1699217 r1699247 55 55 }); 56 56 }); 57 58 (function($) {59 60 list = {61 62 /**63 * Register our triggers64 *65 * We want to capture clicks on specific links, but also value change in66 * the pagination input field. The links contain all the information we67 * need concerning the wanted page number or ordering, so we'll just68 * parse the URL to extract these variables.69 *70 * The page number input is trickier: it has no URL so we have to find a71 * way around. We'll use the hidden inputs added in TT_Example_List_Table::display()72 * to recover the ordering variables, and the default paged input added73 * automatically by WordPress.74 */75 init: function() {76 77 // This will have its utility when dealing with the page number input78 var timer;79 var delay = 500;80 81 // Pagination links, sortable link82 $('.tablenav-pages a, .manage-column.sortable a, .manage-column.sorted a').on('click', function(e) {83 // We don't want to actually follow these links84 e.preventDefault();85 // Simple way: use the URL to extract our needed variables86 var query = this.search.substring( 1 );87 88 var data = {89 paged: list.__query( query, 'paged' ) || '1',90 order: list.__query( query, 'order' ) || 'asc',91 orderby: list.__query( query, 'orderby' ) || 'title'92 };93 list.update( data );94 });95 96 // Page number input97 $('input[name=paged]').on('keyup', function(e) {98 99 // If user hit enter, we don't want to submit the form100 // We don't preventDefault() for all keys because it would101 // also prevent to get the page number!102 if ( 13 == e.which )103 e.preventDefault();104 105 // This time we fetch the variables in inputs106 var data = {107 paged: parseInt( $('input[name=paged]').val() ) || '1',108 order: $('input[name=order]').val() || 'asc',109 orderby: $('input[name=orderby]').val() || 'title'110 };111 112 // Now the timer comes to use: we wait half a second after113 // the user stopped typing to actually send the call. If114 // we don't, the keyup event will trigger instantly and115 // thus may cause duplicate calls before sending the intended116 // value117 window.clearTimeout( timer );118 timer = window.setTimeout(function() {119 list.update( data );120 }, delay);121 });122 },123 124 /** AJAX call125 *126 * Send the call and replace table parts with updated version!127 *128 * @param object data The data to pass through AJAX129 */130 update: function( data ) {131 $.ajax({132 // /wp-admin/admin-ajax.php133 url: ajaxurl,134 // Add action and nonce to our collected data135 data: $.extend(136 {137 _ajax_custom_list_nonce: $('#_ajax_custom_list_nonce').val(),138 action: '_ajax_fetch_custom_list',139 },140 data141 ),142 // Handle the successful result143 success: function( response ) {144 145 // WP_List_Table::ajax_response() returns json146 var response = $.parseJSON( response );147 148 // Add the requested rows149 if ( response.rows.length )150 $('#the-list').html( response.rows );151 // Update column headers for sorting152 if ( response.column_headers.length )153 $('thead tr, tfoot tr').html( response.column_headers );154 // Update pagination for navigation155 if ( response.pagination.bottom.length )156 $('.tablenav.top .tablenav-pages').html( $(response.pagination.top).html() );157 if ( response.pagination.top.length )158 $('.tablenav.bottom .tablenav-pages').html( $(response.pagination.bottom).html() );159 160 // Init back our event handlers161 list.init();162 }163 });164 },165 166 /**167 * Filter the URL Query to extract variables168 *169 * @see http://css-tricks.com/snippets/javascript/get-url-variables/170 *171 * @param string query The URL query part containing the variables172 * @param string variable Name of the variable we want to get173 *174 * @return string|boolean The variable value if available, false else.175 */176 __query: function( query, variable ) {177 178 var vars = query.split("&");179 for ( var i = 0; i <vars.length; i++ ) {180 var pair = vars[ i ].split("=");181 if ( pair[0] == variable )182 return pair[1];183 }184 return false;185 },186 }187 188 list.init();189 190 })(jQuery); -
shortcode-mastery-lite/trunk/css/shortcode-mastery-admin.css
r1699246 r1699247 752 752 753 753 h1 span.version { 754 font-size: 13px; 755 padding-top: 13px; 756 padding-left: 7px; 757 color: #555d66; 754 font-size: 11px; 755 padding: 1px 7px; 756 color: #f1f1f1; 757 font-weight: bold; 758 background: #3498db; 759 border-radius: 20px; 760 position: relative; 761 top: 0px; 762 left: 5px; 758 763 } 759 764 -
shortcode-mastery-lite/trunk/js/shortcode-mastery-ajax.js
r1699217 r1699247 55 55 }); 56 56 }); 57 58 (function($) {59 60 list = {61 62 /**63 * Register our triggers64 *65 * We want to capture clicks on specific links, but also value change in66 * the pagination input field. The links contain all the information we67 * need concerning the wanted page number or ordering, so we'll just68 * parse the URL to extract these variables.69 *70 * The page number input is trickier: it has no URL so we have to find a71 * way around. We'll use the hidden inputs added in TT_Example_List_Table::display()72 * to recover the ordering variables, and the default paged input added73 * automatically by WordPress.74 */75 init: function() {76 77 // This will have its utility when dealing with the page number input78 var timer;79 var delay = 500;80 81 // Pagination links, sortable link82 $('.tablenav-pages a, .manage-column.sortable a, .manage-column.sorted a').on('click', function(e) {83 // We don't want to actually follow these links84 e.preventDefault();85 // Simple way: use the URL to extract our needed variables86 var query = this.search.substring( 1 );87 88 var data = {89 paged: list.__query( query, 'paged' ) || '1',90 order: list.__query( query, 'order' ) || 'asc',91 orderby: list.__query( query, 'orderby' ) || 'title'92 };93 list.update( data );94 });95 96 // Page number input97 $('input[name=paged]').on('keyup', function(e) {98 99 // If user hit enter, we don't want to submit the form100 // We don't preventDefault() for all keys because it would101 // also prevent to get the page number!102 if ( 13 == e.which )103 e.preventDefault();104 105 // This time we fetch the variables in inputs106 var data = {107 paged: parseInt( $('input[name=paged]').val() ) || '1',108 order: $('input[name=order]').val() || 'asc',109 orderby: $('input[name=orderby]').val() || 'title'110 };111 112 // Now the timer comes to use: we wait half a second after113 // the user stopped typing to actually send the call. If114 // we don't, the keyup event will trigger instantly and115 // thus may cause duplicate calls before sending the intended116 // value117 window.clearTimeout( timer );118 timer = window.setTimeout(function() {119 list.update( data );120 }, delay);121 });122 },123 124 /** AJAX call125 *126 * Send the call and replace table parts with updated version!127 *128 * @param object data The data to pass through AJAX129 */130 update: function( data ) {131 $.ajax({132 // /wp-admin/admin-ajax.php133 url: ajaxurl,134 // Add action and nonce to our collected data135 data: $.extend(136 {137 _ajax_custom_list_nonce: $('#_ajax_custom_list_nonce').val(),138 action: '_ajax_fetch_custom_list',139 },140 data141 ),142 // Handle the successful result143 success: function( response ) {144 145 // WP_List_Table::ajax_response() returns json146 var response = $.parseJSON( response );147 148 // Add the requested rows149 if ( response.rows.length )150 $('#the-list').html( response.rows );151 // Update column headers for sorting152 if ( response.column_headers.length )153 $('thead tr, tfoot tr').html( response.column_headers );154 // Update pagination for navigation155 if ( response.pagination.bottom.length )156 $('.tablenav.top .tablenav-pages').html( $(response.pagination.top).html() );157 if ( response.pagination.top.length )158 $('.tablenav.bottom .tablenav-pages').html( $(response.pagination.bottom).html() );159 160 // Init back our event handlers161 list.init();162 }163 });164 },165 166 /**167 * Filter the URL Query to extract variables168 *169 * @see http://css-tricks.com/snippets/javascript/get-url-variables/170 *171 * @param string query The URL query part containing the variables172 * @param string variable Name of the variable we want to get173 *174 * @return string|boolean The variable value if available, false else.175 */176 __query: function( query, variable ) {177 178 var vars = query.split("&");179 for ( var i = 0; i <vars.length; i++ ) {180 var pair = vars[ i ].split("=");181 if ( pair[0] == variable )182 return pair[1];183 }184 return false;185 },186 }187 188 list.init();189 190 })(jQuery);
Note: See TracChangeset
for help on using the changeset viewer.