Changeset 2231084
- Timestamp:
- 01/21/2020 05:12:04 PM (6 years ago)
- Location:
- wp-search-category-admin/trunk
- Files:
-
- 5 added
- 3 edited
-
README.md (modified) (2 diffs)
-
admin (added)
-
admin/ConfigurationAdmin.php (added)
-
js/script.js (modified) (6 diffs)
-
views (added)
-
views/admin (added)
-
views/admin/option-page.php (added)
-
wp-search-cat-admin.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wp-search-category-admin/trunk/README.md
r2122082 r2231084 3 3 Tags: category, admin, post, search, box 4 4 Requires at least: 4.0 5 Tested up to: 5. 26 Stable tag: 1. 25 Tested up to: 5.0 6 Stable tag: 1.5 7 7 License: GPLv2 or later 8 8 License URI: https://www.gnu.org/licenses/gpl-2.0.html 9 9 10 Add a search input into a Post edit Page to add fast category for a Post .10 Add a search input into a Post edit Page to add fast category for a Post and in quick edit. 11 11 12 12 == Description == … … 25 25 == Changelog == 26 26 27 = 1.5 = 28 * Can display search input for custom taxonomies 29 * Create an admin option page "WPSCA Option" to activate search input 30 27 31 = 1.2 = 28 32 * Compatibility with the new editor in WordPress 5.0+ -
wp-search-category-admin/trunk/js/script.js
r1989484 r2231084 1 1 (function( $ ){ 2 console.log(wp);3 2 $(window).load(function(){ 4 3 adminSearch.init(); 5 4 }); 5 6 6 var adminSearch = { 7 isGutenberg: false, 7 isQuickEditPage: false, 8 listInputTaxononomiesId: 'wpsca_list_taxonomies', 9 listInputTaxononomiesNameId: 'wpsca_list_taxonomies_name', 10 injectInputEventName: 'wpsca-inject-search-input', 11 8 12 getNameSearchField: function(){ 9 13 return 'wpsca-search-field'; 10 },11 getNameSearchButton: function(){12 return 'wpsca-search-button';13 14 }, 14 15 init : function(){ … … 18 19 }; 19 20 21 this.isGutenberg = (typeof wp.element !== 'undefined'); 20 22 // Can edit in post edit page or in quick edit 21 varisQuickEditPage = $('.quick-edit-row').length > 0;23 this.isQuickEditPage = $('.quick-edit-row').length > 0; 22 24 23 if (isQuickEditPage === true) { 25 if (document.getElementById(this.listInputTaxononomiesId).length === 0) { 26 return; 27 } 28 if (this.isQuickEditPage === true) { 24 29 this.initQuickEdit(); 25 30 } else { 26 this.initEditPage(); 31 if (!this.isGutenberg) { 32 this.initEditPage(); 33 } 27 34 } 28 35 }, 29 36 30 getSearchBox: function() { 31 var nameSearchField = this.getNameSearchField(); 32 var nameButtonGo = this.getNameSearchButton(); 33 return '<input type="text" name="'+ nameSearchField +'" id="'+ nameSearchField +'" class="meta-box-search-field" placeholder="Search" />'; 37 getListTaxonomies: function() { 38 return document.getElementById(this.listInputTaxononomiesId).value.split(','); 39 }, 40 41 getSearchBox: function(taxonomyName) { 42 var nameSearchField = this.getNameSearchField() + taxonomyName; 43 return '<input type="text" name="'+ nameSearchField +'" id="'+ nameSearchField +'" data-taxonomy="' + taxonomyName +'" class="meta-box-search-field" placeholder="Search" />'; 34 44 }, 35 45 36 46 initEditPage: function() { 37 47 var globalObject = this; 38 var search_box = this.getSearchBox(); 39 var nameSearchField = this.getNameSearchField(); 40 setTimeout(function() { 41 // WordPress Guttenberg or version sup or equal to 5.0 42 globalObject.isGutenberg = $('.editor-post-taxonomies__hierarchical-terms-list').length > 0; 43 // Add search_box input 44 if (globalObject.isGutenberg) { 45 $('.editor-post-taxonomies__hierarchical-terms-list').before(search_box); 46 } else { 47 $('#category-tabs').before(search_box); 48 } 48 // get list input taxonomies and init initial vars 49 var listTaxonomies = this.getListTaxonomies(); 49 50 50 globalObject.initSearch('autocomplete', $('#'+nameSearchField), false); 51 }, 800); 51 listTaxonomies.forEach(function (taxonomy) { 52 var searchBox = globalObject.getSearchBox(taxonomy); 53 var divIdToInject = 'taxonomy-' + taxonomy; 54 var nameSearchField = globalObject.getNameSearchField() + taxonomy; 55 56 $('#' + divIdToInject).prepend(searchBox); 57 globalObject.initSearch($('#'+ nameSearchField), false); 58 }); 52 59 }, 53 60 54 61 initQuickEdit: function() { 55 62 var globalObject = this; 63 var listTaxonomies = this.getListTaxonomies(); 64 56 65 $('.editinline').on('click', function(event) { 66 $('.meta-box-search-field').remove(); 57 67 setTimeout(function() { 58 var search_box = globalObject.getSearchBox(); 59 var nameSearchField = globalObject.getNameSearchField(); 60 $('.meta-box-search-field').remove(); 61 $('.cat-checklist.category-checklist').before(search_box); 62 globalObject.initSearch('autocomplete', $('#'+nameSearchField), true); 68 listTaxonomies.forEach(function (taxonomy) { 69 var search_box = globalObject.getSearchBox(taxonomy); 70 var nameSearchField = globalObject.getNameSearchField() + taxonomy; 71 $('.' + taxonomy + '-checklist.cat-checklist').first().before(search_box); // first to not have duplicate id 72 globalObject.initSearch($('#'+nameSearchField), true); 73 }); 63 74 },50); 64 75 }); … … 66 77 }, 67 78 68 initSearch: function(method, element, isQuickEdit){ 69 switch(method){ 70 case 'click': 71 this.initClick(element); 72 break; 73 case 'autocomplete': 74 this.initAutocomplete(element, isQuickEdit); 75 break; 76 } 79 initSearch: function(element, isQuickEdit){ 80 this.initAutocomplete(element, isQuickEdit); 77 81 }, 78 82 … … 85 89 var $el = $(this); 86 90 var s = $el.siblings('#'+nameField).val(); 87 that.search Cat(s, $el);91 that.searchTaxonomyElement(s, $el); 88 92 }); 89 93 }, … … 93 97 element.keyup($.debounce(500, function(){ 94 98 var s = $(this).val(); 95 that.search Cat(s, element, isQuickEdit);99 that.searchTaxonomyElement(s, element, isQuickEdit); 96 100 })); 97 101 }, 98 102 99 search Cat: function(s, elementEvent, isQuickEdit){103 searchTaxonomyElement: function(s, elementEvent, isQuickEdit){ 100 104 var parentClass = 'categorydiv'; 101 var categoryChecklistClass = 'categorychecklist';105 var taxonomyChecklistClass = 'categorychecklist'; 102 106 var itemSelector = 'li'; 103 107 104 108 if (this.isGutenberg) { 105 109 parentClass = 'components-panel__body'; 106 categoryChecklistClass = 'editor-post-taxonomies__hierarchical-terms-list';110 taxonomyChecklistClass = 'editor-post-taxonomies__hierarchical-terms-list'; 107 111 itemSelector = '.editor-post-taxonomies__hierarchical-terms-choice'; 108 112 } 109 113 if (isQuickEdit) { 110 114 parentClass = 'inline-edit-col'; 111 categoryChecklistClass = 'category-checklist'; 115 var taxonomy = $(elementEvent).data('taxonomy') 116 taxonomyChecklistClass = taxonomy + '-checklist'; 112 117 } 113 118 114 119 if ( $.trim(s) == "" ){ 115 elementEvent.parents('.' + parentClass).first().find('.'+ categoryChecklistClass +' ' + itemSelector).show();120 elementEvent.parents('.' + parentClass).first().find('.'+ taxonomyChecklistClass +' ' + itemSelector).show(); 116 121 } else { 117 var result = elementEvent.parents('.' + parentClass).first().find('.'+ categoryChecklistClass+' ' + itemSelector + ':Contains("'+s+'")');122 var result = elementEvent.parents('.' + parentClass).first().find('.'+taxonomyChecklistClass+' ' + itemSelector + ':Contains("'+s+'")'); 118 123 119 elementEvent.parents('.' + parentClass).first().find('.' + categoryChecklistClass + ' ' + itemSelector).hide();124 elementEvent.parents('.' + parentClass).first().find('.' + taxonomyChecklistClass + ' ' + itemSelector).hide(); 120 125 result.each(function(){ 121 126 $(this).show(); … … 123 128 } 124 129 } 125 126 127 130 }; 128 131 })( jQuery ); -
wp-search-category-admin/trunk/wp-search-cat-admin.php
r1989487 r2231084 4 4 Plugin Name: WP search category admin 5 5 Description: Search dynamically a category in the box category in admin 6 Version: 1. 26 Version: 1.5 7 7 Author: Clément Décou 8 8 Author URI: http://www.clement-decou.fr 9 9 */ 10 11 require_once __DIR__ . '/admin/ConfigurationAdmin.php'; 12 13 // init admin 14 if (is_admin()) { 15 new ConfigurationAdmin(); 16 } 10 17 11 18 function register_wpsca_custom_script($hook) … … 22 29 wp_enqueue_style('wpsca_style', plugin_dir_url( __FILE__ ).'css/style.css'); 23 30 } 31 add_action( 'admin_enqueue_scripts', 'register_wpsca_custom_script'); 24 32 25 add_action( 'admin_enqueue_scripts', 'register_wpsca_custom_script'); 33 // Add list of taxonomy in input hidden in admin footer 34 function print_input_list_taxonomies() { 35 $screen = get_current_screen(); 36 if ($screen->parent_base !== 'edit') { 37 return; 38 } 39 40 $pluginOption = ConfigurationAdmin::getOption(); 41 $listTax = array_keys($pluginOption[ConfigurationAdmin::$registerTaxSectionName]); 42 echo '<input type="hidden" id="wpsca_list_taxonomies" value="' . implode(',', $listTax) . '">'; 43 } 44 add_action('admin_footer', 'print_input_list_taxonomies');
Note: See TracChangeset
for help on using the changeset viewer.