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.menu-links.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 4 days 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 6 years ago nestedpages.settings-reset.js 6 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.menu-links.js
271 lines
1 var NestedPages = NestedPages || {};
2
3 /**
4 * Menu Item Selection in Modal Link Form
5 * @package Nested Pages
6 * @author Kyle Phillips - https://github.com/kylephillips/wp-nested-pages
7 */
8 NestedPages.MenuLinks = function()
9 {
10 var plugin = this;
11 var $ = jQuery;
12
13 plugin.typeButton = ''; // The Link Type selected button
14 plugin.post = ''; // The new post created
15
16 plugin.formatter = new NestedPages.Formatter;
17
18 plugin.selectors = {
19 form : '[data-np-menu-item-form]', // The form element
20 typeSelect : '[data-np-menu-selection]', // Link in left column to choose type of link
21 accordion : '[data-np-menu-accordion]', // Accordion of objects
22 accordionItem : '[data-np-menu-accordion-item]', // Single item in the accordion
23 formPlaceholder : '.np-menu-link-object-placeholder', // Placeholder element
24 formDetails : '.np-menu-link-details', // Right pane form details
25 searchResults : '[data-np-search-result]', // Appended search result rows
26 defaultResults : '[data-default-result]', // Default results,
27 originalLink : '[data-np-original-link]', // Original Link Preview
28 saveButton : '[data-np-save-link]', // The Form Submit Button
29 urlInputCont : '[data-np-menu-url-cont]', // Container for URL input (only for custom links)
30 errorDiv : '[data-np-error]', // The error notification
31 }
32
33 plugin.fields = {
34 object : '[data-np-menu-object-input]', // The object (ex: post/category/custom)
35 objectid : '[data-np-menu-objectid-input]', // ex: term id, post id
36 itemType : '[data-np-menu-type-input]', // ex: post_type, taxonomy
37 url : '[data-np-menu-url]', // custom url
38 navigationLabel : '[data-np-menu-navigation-label]',
39 titleAttribute : '[data-np-menu-title-attr]',
40 cssClasses : '[data-np-menu-css-classes]',
41 npStatus : '[data-np-menu-np-status]',
42 linkTarget : '[data-np-menu-link-target]',
43 menuTitle : '[data-np-menu-title]',
44 parentPostType : '[data-np-menu-parent-post-type]'
45 }
46
47 plugin.search = new NestedPages.MenuSearch;
48
49 plugin.bindEvents = function()
50 {
51 $(document).on('click', NestedPages.selectors.openLinkModal, function(e){
52 e.preventDefault();
53 plugin.postParent = $(this).attr('data-parentid');
54 $(plugin.selectors.form).find('.parent_id').val($(this).attr('data-parentid'));
55 plugin.openModal();
56 });
57 $(document).on('click', plugin.selectors.accordionItem, function(e){
58 e.preventDefault();
59 plugin.accordion($(this));
60 });
61 $(document).on('click', plugin.selectors.typeSelect, function(e){
62 e.preventDefault();
63 plugin.typeButton = $(this);
64 plugin.setLinkType();
65 });
66 $(document).on('keyup', plugin.fields.navigationLabel, function(){
67 plugin.updateTitle();
68 });
69 $(document).on('click', plugin.selectors.saveButton, function(e){
70 e.preventDefault();
71 plugin.submitForm();
72 });
73 $(document).on('keydown', function(e){
74 if ( e.keyCode === 27 ) $(document).trigger('close-modal-manual');
75 });
76 }
77
78 // Open the Modal and Clear/Populate hidden fields
79 plugin.openModal = function()
80 {
81 $(NestedPages.selectors.linkErrorDiv).hide();
82 $(NestedPages.selectors.linkModal).find('input').val('');
83 $(NestedPages.selectors.linkModal).find('.parent_id').val(plugin.postParent);
84 plugin.clearForm();
85 $(plugin.selectors.accordion).find('ul').hide();
86 $(plugin.selectors.typeSelect).removeClass('active');
87 $(document).trigger('open-modal-manual', NestedPages.selectors.linkModal);
88 }
89
90 // Accordion Menu
91 plugin.accordion = function(button)
92 {
93 plugin.clearForm();
94 var submenu = $(button).siblings('ul');
95 if ( $(submenu).is(':visible') ){
96 $(button).removeClass('active');
97 $(submenu).slideUp('fast');
98 return;
99 }
100 $(plugin.selectors.accordionItem).removeClass('active');
101 $(button).addClass('active');
102 $(button).parents(plugin.selectors.accordion).find('ul').slideUp('fast');
103 $(submenu).slideDown('fast');
104 }
105
106 // Set the link type
107 plugin.setLinkType = function()
108 {
109 if ( $(plugin.typeButton).hasClass('active') ){
110 plugin.clearForm();
111 return;
112 }
113 if ( $(plugin.typeButton).hasClass('np-custom-link') ){
114 $(plugin.selectors.accordionItem).removeClass('active');
115 $(plugin.selectors.accordion).find('ul').slideUp('fast');
116 }
117 $(plugin.selectors.formPlaceholder).hide();
118 plugin.populateForm();
119 }
120
121 // Populate the form
122 plugin.populateForm = function()
123 {
124 $(plugin.selectors.saveButton).show();
125 $(plugin.selectors.typeSelect).removeClass('active');
126 $(plugin.typeButton).addClass('active');
127 $(plugin.fields.menuTitle).text($(plugin.typeButton).text()).val($(plugin.typeButton).text());
128 $(plugin.selectors.form).find('h3').find('em').text($(plugin.typeButton).attr('data-np-object-name'));
129 if ( $(plugin.typeButton).attr('data-np-permalink') !== "" ){
130 $(plugin.selectors.form).find(plugin.selectors.urlInputCont).hide();
131 $(plugin.selectors.form).find(plugin.selectors.originalLink).html('<a href="' + $(plugin.typeButton).attr('data-np-permalink') + '">' + $(plugin.typeButton).text() + '</a>');
132 $(plugin.selectors.form).find(plugin.selectors.originalLink).parent('.original-link').show();
133 } else {
134 $(plugin.selectors.form).find(plugin.selectors.urlInputCont).show();
135 $(plugin.selectors.form).find(plugin.selectors.originalLink).parent('.original-link').hide();
136 }
137 $(plugin.fields.object).val($(plugin.typeButton).attr('data-np-menu-object'));
138 $(plugin.fields.objectid).val($(plugin.typeButton).attr('data-np-menu-objectid'));
139 $(plugin.fields.itemType).val($(plugin.typeButton).attr('data-np-menu-type'));
140 $(plugin.selectors.formDetails).show();
141 }
142
143 // Clear the form
144 plugin.clearForm = function()
145 {
146 $(plugin.selectors.form).find(plugin.selectors.errorDiv).hide();
147 $(plugin.selectors.saveButton).hide();
148 $(plugin.selectors.formDetails).hide();
149 $(plugin.selectors.formPlaceholder).show();
150 $(plugin.selectors.form).find('input').not('.parent_id').not('.parent-post-type').val('');
151 $(plugin.selectors.form).find(plugin.fields.linkTarget).val('_blank');
152 $(plugin.selectors.form).find('input[type="checkbox"]').attr('checked', false);
153 $(plugin.selectors.typeSelect).removeClass('active');
154 plugin.search.toggleLoading(false);
155 $(plugin.selectors.searchResults).remove();
156 $(plugin.selectors.defaultResults).show();
157 }
158
159 // Update the title text
160 plugin.updateTitle = function()
161 {
162 var value = $(plugin.fields.navigationLabel).val();
163 var title = $(plugin.selectors.form).find('h3').find('span');
164 if ( value !== "" ){
165 $(plugin.fields.menuTitle).val(value);
166 $(title).text(value);
167 } else {
168 $(plugin.fields.menuTitle).val($(plugin.typeButton).text());
169 $(title).text($(plugin.typeButton).text());
170 }
171 }
172
173 // Submit the Form
174 plugin.submitForm = function()
175 {
176 plugin.toggleLoading(true);
177 $.ajax({
178 url : NestedPages.jsData.ajaxurl,
179 type : 'post',
180 data: $(plugin.selectors.form).serialize() + '&action=' + NestedPages.formActions.newMenuItem + '&nonce=' + NestedPages.jsData.nonce + '&post_type=' + NestedPages.jsData.posttype + '&syncmenu=' + NestedPages.jsData.syncmenu,
181 success : function(data){
182 plugin.toggleLoading(false);
183 if ( data.status === 'error' ){
184 $(plugin.selectors.form).find(plugin.selectors.errorDiv).text(data.message).show();
185 return;
186 }
187 plugin.post = data.post_data;
188 plugin.createRow();
189 },
190 error : function(data){
191 console.log(data);
192 }
193 });
194 }
195
196 // Create the nested pages row for the new link
197 plugin.createRow = function()
198 {
199 var html = '<li id="menuItem_' + plugin.post.id + '" class="page-row post-type-np-redirect published';
200 html += '">'
201
202 html += '<div class="row"><div class="child-toggle"><div class="child-toggle-spacer"></div></div><div class="row-inner">';
203 html += '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" class="np-icon-sub-menu"><path fill="none" d="M0 0h24v24H0V0z"/><path d="M19 15l-6 6-1.42-1.42L15.17 16H4V4h2v10h9.17l-3.59-3.58L13 9l6 6z" class="arrow" /></svg>';
204 html += '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" class="handle np-icon-menu"><path d="M0 0h24v24H0z" fill="none" /><path d="M3 18h18v-2H3v2zm0-5h18v-2H3v2zm0-7v2h18V6H3z" class="bars" /></svg>';
205 html += '<a href="' + plugin.post.np_link_content + '" class="page-link page-title" target="_blank"><span class="title">' + plugin.post.menuTitle + ' <svg class="link-icon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M0 0h24v24H0z" fill="none"/><path class="icon" d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"/></svg></span>';
206
207 // Quick Edit Button
208 html += '</a><div class="action-buttons"><a href="#" class="np-btn np-quick-edit-redirect" ';
209 html += 'data-id="' + plugin.post.id + '"';
210 html += 'data-parentid="' + plugin.post.parent_id + '"';
211 html += 'data-title="' + plugin.post.menuTitle + '" ';
212 html += 'data-url="' + plugin.post.url + '" ';
213 html += 'data-status="publish" ';
214 html += 'data-np-status="show" ';
215 html += 'data-navstatus="show" ';
216 html += 'data-navcss="' + plugin.post.cssClasses + '" ';
217 html += 'data-navtitleattr="' + plugin.post.titleAttribute + '" ';
218 html += 'data-nav-type="' + plugin.post.menuType + '" ';
219 html += 'data-nav-object="' + plugin.post.objectType + '" ';
220 html += 'data-nav-object-id="' + plugin.post.objectId + '" ';
221 html += 'data-nav-original-link="' + plugin.post.original_link + '" ';
222 html += 'data-nav-original-title="' + plugin.post.original_title + '" ';
223 html += 'data-linktarget="' + plugin.post.link_target + '">';
224 html += NestedPages.jsData.quickEditText;
225 html += '</a>';
226
227 // Delete Link
228 html += '<a href="' + plugin.post.delete_link + '" class="np-btn np-btn-trash"><i class="np-icon-remove"></i></a>';
229
230 html += '</div></div></div></li>';
231
232 if ( plugin.post.parent_id === "0" ){
233 $('.nplist:first li:first').after(html);
234 } else {
235 plugin.appendChildRow(html);
236 }
237
238 $(document).trigger('close-modal-manual');
239
240 plugin.row = $('#menuItem_' + plugin.post.id).find('.row');
241 plugin.formatter.flashRow(plugin.row);
242 }
243
244 // Append a new child link to the appropriate menu
245 plugin.appendChildRow = function(html)
246 {
247 var parent_row = $('#menuItem_' + plugin.post.parent_id);
248 if ( $(parent_row).children('ol').length === 0 ){
249 html = '<ol class="sortable nplist" style="display:block;">' + html + '</ol>';
250 $(parent_row).append(html);
251 } else {
252 $(parent_row).find('ol:first').prepend(html);
253 }
254 plugin.formatter.updateSubMenuToggle();
255 }
256
257 // Toggle Loading
258 plugin.toggleLoading = function(loading)
259 {
260 if ( loading ){
261 $(plugin.selectors.form).find(plugin.selectors.errorDiv).hide();
262 $(plugin.selectors.form).find(NestedPages.selectors.quickEditLoadingIndicator).show();
263 $(plugin.selectors.saveButton).attr('disabled', 'disabled');
264 return;
265 }
266 $(plugin.selectors.form).find(NestedPages.selectors.quickEditLoadingIndicator).hide();
267 $(plugin.selectors.saveButton).attr('disabled', false);
268 }
269
270 return plugin.bindEvents();
271 }