PluginProbe ʕ •ᴥ•ʔ
Nested Pages / 3.2.14
Nested Pages v3.2.14
3.2.15 3.2.14 3.1.8 3.1.9 3.2.0 3.2.1 3.2.10 3.2.11 3.2.12 3.2.13 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8 3.2.9 trunk 1.0 1.1 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.2.1 1.3.0 1.3.1 1.3.10 1.3.11 1.3.12 1.3.13 1.3.14 1.3.15 1.3.2 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.3.1 1.6.3.2 1.6.4 1.6.5 1.6.5.1 1.6.5.2 1.6.6 1.6.7 1.6.8 1.7.0 1.7.1 2.0.1 2.0.2 2.0.3 2.0.4 3.0.1 3.0.10 3.0.11 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.10 3.1.11 3.1.12 3.1.13 3.1.14 3.1.15 3.1.16 3.1.17 3.1.18 3.1.19 3.1.2 3.1.20 3.1.21 3.1.22 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7
wp-nested-pages / assets / js / lib / nestedpages.post-search.js
wp-nested-pages / assets / js / lib Last commit date
jquery.mjs.nestedSortable.js 4 years ago jquery.ui.touch-punch.min.js 11 years ago nestedpages-factory.js 3 years ago nestedpages.bulk-actions.js 4 years ago nestedpages.check-all.js 9 years ago nestedpages.clone.js 3 years ago nestedpages.confirm-delete.js 8 years ago nestedpages.dropdowns.js 8 years ago nestedpages.formatter.js 3 years ago nestedpages.hidden-item-count.js 9 years ago nestedpages.manual-sync.js 9 years ago nestedpages.menu-links.js 3 years ago nestedpages.menu-search.js 2 weeks ago nestedpages.menu-toggle.js 8 years ago nestedpages.modals.js 8 years ago nestedpages.move-post.js 8 years ago nestedpages.nesting.js 3 years ago nestedpages.new-post.js 6 years ago nestedpages.page-toggle.js 4 years ago nestedpages.post-search.js 9 years ago nestedpages.quickedit-link.js 8 years ago nestedpages.quickedit-post.js 3 years ago nestedpages.settings-admin-customization.js 7 years ago nestedpages.settings-reset.js 7 years ago nestedpages.settings.js 3 years ago nestedpages.sync-menu-setting.js 8 years ago nestedpages.tabs.js 6 years ago nestedpages.trash-with-children.js 6 years ago nestedpages.trash.js 8 years ago nestedpages.userprefs-reset.js 7 years ago nestedpages.wpml.js 8 years ago
nestedpages.post-search.js
138 lines
1 var NestedPages = NestedPages || {};
2
3 /**
4 * Perform an AJAX search for posts by type
5 * @package Nested Pages
6 * @author Kyle Phillips - https://github.com/kylephillips/wp-nested-pages
7 */
8 NestedPages.PostSearch = function()
9 {
10 var plugin = this;
11 var $ = jQuery;
12
13 plugin.selectors = {
14 input : 'data-nestedpages-post-search',
15 form : 'data-nestedpages-post-search-form',
16 loadingIndicator : 'data-nestedpages-loading',
17 noResults : 'data-nestedpages-no-results',
18 results: 'data-nestedpages-search-results'
19 }
20
21 plugin.changed = false;
22 plugin.activeInput = ''; // The active input
23 plugin.results = ''; // Search results
24 plugin.defaultResults = ''; // The default, loaded results
25 plugin.postType = ''; // The type of search (post_type, taxonomy)
26 plugin.activeForm = '';
27
28 plugin.bindEvents = function()
29 {
30 $('['+ plugin.selectors.input + ']').on('input', function(){
31 plugin.activeInput = $(this);
32 plugin.setOptions();
33 if ( !plugin.changed ) plugin.setDefaultResults();
34 if ( $(this).val() === '' ) {
35 $(plugin.activeForm).find('[' + plugin.selectors.noResults + ']').hide();
36 plugin.showDefaultResults();
37 return;
38 }
39 plugin.query();
40 });
41 }
42
43 /**
44 * Set the default results
45 */
46 plugin.setDefaultResults = function()
47 {
48 plugin.defaultResults = $(plugin.activeForm).find('[' + plugin.selectors.results + ']').html();
49 plugin.changed = true;
50 }
51
52 /**
53 * Show the default results
54 */
55 plugin.showDefaultResults = function()
56 {
57 $(plugin.activeForm).find('[' + plugin.selectors.results + ']').html(plugin.defaultResults);
58 }
59
60 /**
61 * Set the options
62 */
63 plugin.setOptions = function()
64 {
65 plugin.postType = $(plugin.activeInput).attr(plugin.selectors.input);
66 plugin.activeForm = $(plugin.activeInput).parents('[' + plugin.selectors.form + ']');
67 }
68
69 // Perform the search
70 plugin.performSearch = function()
71 {
72 plugin.defaultResults = $(plugin.activeForm).parent('li').siblings(plugin.selectors.defaultResults);
73 if ( $(plugin.activeForm).val().length > 2 ){
74 $(plugin.defaultResults).hide();
75 plugin.toggleLoading(true);
76 plugin.query();
77 return;
78 }
79 plugin.toggleLoading(false);
80 $(plugin.defaultResults).show();
81 }
82
83
84 // Query Search
85 plugin.query = function()
86 {
87 $(plugin.activeForm).find('[' + plugin.selectors.results + ']').empty();
88 plugin.toggleLoading(true);
89 $.ajax({
90 url: NestedPages.jsData.ajaxurl,
91 type: 'post',
92 datatype: 'json',
93 data: {
94 action : NestedPages.formActions.postSearch,
95 nonce : NestedPages.jsData.nonce,
96 term : $(plugin.activeInput).val(),
97 postType : plugin.postType
98 },
99 success: function(data){
100 if ( data.results ){
101 plugin.results = data.results;
102 plugin.loadResults();
103 plugin.toggleLoading(false);
104 } else {
105 plugin.toggleLoading(false);
106 $(plugin.activeForm).find('[' + plugin.selectors.noResults + ']').show();
107 }
108 }
109 });
110 }
111
112 // Load the results into view
113 plugin.loadResults = function()
114 {
115 var html = "<ul>";
116 $.each(plugin.results, function(i, v){
117 html += '<li><a href="#" data-assignment-page-id="' + v.ID + '" data-assignment-page-title="' + v.post_title + '">' + v.post_title + '</a></li>';
118 });
119 html += '</ul>';
120 $(plugin.activeForm).find('[' + plugin.selectors.results + ']').html(html);
121 plugin.toggleLoading(false);
122 }
123
124 // Toggle the loading indicator
125 plugin.toggleLoading = function(loading)
126 {
127 var loadingIndicator = $(plugin.activeForm).find('[' + plugin.selectors.loadingIndicator + ']');
128 var noResults = $(plugin.activeForm).find('[' + plugin.selectors.noResults + ']');
129 $(noResults).hide();
130 if ( loading ){
131 $(loadingIndicator).show();
132 return;
133 }
134 $(loadingIndicator).hide();
135 }
136
137 return plugin.bindEvents();
138 }