PluginProbe ʕ •ᴥ•ʔ
Nested Pages / 3.2.14
Nested Pages v3.2.14
3.3.1 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.quickedit-link.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 5 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 4 years ago nestedpages.menu-search.js 1 month 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 4 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.quickedit-link.js
229 lines
1 var NestedPages = NestedPages || {};
2
3 /**
4 * Quick Edit functionality for links
5 * @package Nested Pages
6 * @author Kyle Phillips - https://github.com/kylephillips/wp-nested-pages
7 */
8 NestedPages.QuickEditLink = function()
9 {
10 var plugin = this;
11 var $ = jQuery;
12
13 plugin.formatter = new NestedPages.Formatter;
14 plugin.button = ''; // The Active Quick Edit Button
15 plugin.postData = ''; // Data for Post being edited (before update)
16 plugin.newPostData = ''; // Data after update
17 plugin.form = ''; // The newly created Quick Edit Form
18
19 plugin.bindEvents = function()
20 {
21 $(document).on('click', NestedPages.selectors.quickEditButtonLink, function(e){
22 e.preventDefault();
23 plugin.formatter.removeQuickEdit();
24 plugin.button = $(this);
25 plugin.openQuickEdit();
26 });
27 $(document).on('click', NestedPages.selectors.quickEditLinkSaveButton, function(e){
28 e.preventDefault();
29 plugin.submitForm();
30 });
31 $(document).on('keydown', function(e){
32 if ( e.keyCode === 27 ) plugin.formatter.removeQuickEdit();
33 });
34 }
35
36
37 // Open the Quick Edit Form
38 plugin.openQuickEdit = function()
39 {
40 plugin.setData();
41 plugin.createForm();
42 plugin.populateForm();
43 }
44
45
46 // Set the Quick Edit Data
47 plugin.setData = function()
48 {
49 plugin.postData = {
50 id : $(plugin.button).attr('data-id'),
51 url : $(plugin.button).attr('data-url'),
52 title : $(plugin.button).attr('data-title'),
53 status : $(plugin.button).attr('data-status'),
54 navstatus : $(plugin.button).attr('data-navstatus'),
55 npstatus : $(plugin.button).attr('data-np-status'),
56 linktarget : $(plugin.button).attr('data-linktarget'),
57 parentid : $(plugin.button).attr('data-parentid'),
58 navtitleattr : $(plugin.button).attr('data-navtitleattr'),
59 navcss : $(plugin.button).attr('data-navcss'),
60 navtype : $(plugin.button).attr('data-nav-type'),
61 navobject : $(plugin.button).attr('data-nav-object'),
62 navobjectid : $(plugin.button).attr('data-nav-object-id'),
63 navoriginallink : $(plugin.button).attr('data-nav-original-link'),
64 navoriginaltitle : $(plugin.button).attr('data-nav-original-title')
65 };
66 }
67
68
69 // Create the quick edit form
70 plugin.createForm = function()
71 {
72 var parent_li = $(plugin.button).closest(NestedPages.selectors.row).parent('li');
73 plugin.form = $(NestedPages.selectors.quickEditLinkForm).clone();
74
75 // Append the form to the list item
76 if ( $(parent_li).children('ol').length > 0 ){
77 var child_ol = $(parent_li).children('ol');
78 $(plugin.form).insertBefore(child_ol);
79 } else {
80 $(plugin.form).appendTo(parent_li);
81 }
82
83 var row = $(plugin.form).siblings(NestedPages.selectors.row).hide();
84 }
85
86
87 // Populate the Quick Edit form with the post data
88 plugin.populateForm = function()
89 {
90 $(plugin.form).find('.np_id').val(plugin.postData.id);
91 $(plugin.form).find('.np_title').val(plugin.postData.title);
92 $(plugin.form).find('.np_author select').val(plugin.postData.author);
93 $(plugin.form).find('.np_status').val(plugin.postData.status);
94 $(plugin.form).find('.np_content').val(plugin.postData.url);
95 $(plugin.form).find('.np_parent_id').val(plugin.postData.parentid);
96 $(plugin.form).find('.np_title_attribute').val(plugin.postData.navtitleattr);
97 $(plugin.form).find('.np_nav_css_classes').val(plugin.postData.navcss);
98
99 if ( plugin.postData.npstatus === 'hide' ){
100 $(plugin.form).find('.np_status').prop('checked', 'checked');
101 } else {
102 $(plugin.form).find('.np_status').removeAttr('checked');
103 }
104
105 if ( plugin.postData.navstatus === 'hide' ) {
106 $(plugin.form).find('.np_nav_status').prop('checked', 'checked');
107 } else {
108 $(plugin.form).find('.np_nav_status').removeAttr('checked');
109 }
110
111 if ( plugin.postData.linktarget === "_blank" ) {
112 $(plugin.form).find('.link_target').prop('checked', 'checked');
113 } else {
114 $(plugin.form).find('.link_target').removeAttr('checked');
115 }
116
117 // Relationship Links
118 if ( plugin.postData.navobject !== 'custom' && plugin.postData.navobject !== '' ){
119 var html = '<div class="form-control original-link">Original: <a href="' + plugin.postData.navoriginallink + '" target="_blank">' + plugin.postData.navoriginaltitle + '</a></div>';
120 $(plugin.form).find('[data-url-field]').remove();
121 $(html).insertAfter($(plugin.form).find('h3'));
122 $(plugin.form).find('[data-np-menu-object-input]').val(plugin.postData.navobject);
123 $(plugin.form).find('[data-np-menu-objectid-input]').val(plugin.postData.navobjectid);
124 $(plugin.form).find('[data-np-menu-type-input]').val(plugin.postData.navtype);
125 $(plugin.form).find('h3').text('Link: ' + plugin.postData.navoriginaltitle);
126 } else {
127 $(plugin.form).find('h3').text('Link');
128 $(plugin.form).find('[data-np-menu-object-input]').val('custom');
129 $(plugin.form).find('[data-np-menu-type-input]').val('custom');
130 }
131
132 plugin.formatter.showQuickEdit();
133 $(plugin.form).show();
134 }
135
136
137 // Submit the form
138 plugin.submitForm = function()
139 {
140 plugin.toggleLoading(true);
141
142 $.ajax({
143 url: NestedPages.jsData.ajaxurl,
144 type: 'post',
145 datatype: 'json',
146 data: $(plugin.form).find('form').serialize() + '&action=' + NestedPages.formActions.quickEditLink + '&nonce=' + NestedPages.jsData.nonce + '&syncmenu=' + NestedPages.jsData.syncmenu + '&post_type=' + NestedPages.jsData.posttype,
147 success: function(data){
148 if (data.status === 'error'){
149 plugin.toggleLoading(false);
150 $(plugin.form).find(NestedPages.selectors.quickEditErrorDiv).text(data.message).show();
151 } else {
152 plugin.toggleLoading(false);
153 plugin.newPostData = data.post_data;
154 plugin.updateRow();
155 }
156 },
157 error: function(data){
158 plugin.toggleLoading(false);
159 $(plugin.form).find(NestedPages.selectors.quickEditErrorDiv).text('The form could not be saved at this time.').show();
160 }
161 });
162 }
163
164
165 // Update the row after successfully saving quick edit data
166 plugin.updateRow = function()
167 {
168 var row = $(plugin.form).siblings('.row');
169 $(row).find('.title').html(plugin.newPostData.post_title + ' <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>');
170
171 var status = $(row).find('.status');
172 if ( (plugin.newPostData._status !== 'publish') && (plugin.newPostData._status !== 'future') ){
173 $(status).text('(' + plugin.newPostData._status + ')');
174 } else {
175 $(status).text('');
176 }
177
178 // Hide / Show in Nav
179 var nav_status = $(row).find('.nav-status');
180 if ( (plugin.newPostData.nav_status == 'hide') ){
181 $(nav_status).text('(' + NestedPages.jsData.hiddenText + ')');
182 } else {
183 $(nav_status).text('');
184 }
185
186 // Hide / Show in Nested Pages
187 var li = $(row).parent('li');
188 if ( (plugin.newPostData.np_status == 'hide') ){
189 $(li).addClass('np-hide');
190 $(row).find('.status').after('<svg class="row-status-icon status-np-hidden" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M0 0h24v24H0zm0 0h24v24H0zm0 0h24v24H0zm0 0h24v24H0z" fill="none"/><path class="icon" d="M12 7c2.76 0 5 2.24 5 5 0 .65-.13 1.26-.36 1.83l2.92 2.92c1.51-1.26 2.7-2.89 3.43-4.75-1.73-4.39-6-7.5-11-7.5-1.4 0-2.74.25-3.98.7l2.16 2.16C10.74 7.13 11.35 7 12 7zM2 4.27l2.28 2.28.46.46C3.08 8.3 1.78 10.02 1 12c1.73 4.39 6 7.5 11 7.5 1.55 0 3.03-.3 4.38-.84l.42.42L19.73 22 21 20.73 3.27 3 2 4.27zM7.53 9.8l1.55 1.55c-.05.21-.08.43-.08.65 0 1.66 1.34 3 3 3 .22 0 .44-.03.65-.08l1.55 1.55c-.67.33-1.41.53-2.2.53-2.76 0-5-2.24-5-5 0-.79.2-1.53.53-2.2zm4.31-.78l3.15 3.15.02-.16c0-1.66-1.34-3-3-3l-.17.01z"/></svg>');
191 } else {
192 $(li).removeClass('np-hide');
193 $(row).find('.status-np-hidden').remove();
194 }
195
196 var button = $(row).find(NestedPages.selectors.quickEditButtonLink);
197
198 $(button).attr('data-id', plugin.newPostData.post_id);
199 $(button).attr('data-title', plugin.newPostData.post_title);
200 $(button).attr('data-url', plugin.newPostData.post_content);
201 $(button).attr('data-status', plugin.newPostData._status);
202 $(button).attr('data-navstatus', plugin.newPostData.nav_status);
203 $(button).attr('data-np-status', plugin.newPostData.np_status);
204 $(button).attr('data-linkTarget', plugin.newPostData.linkTarget);
205 $(button).attr('data-navtitleattr', plugin.newPostData.titleAttribute);
206 $(button).attr('data-navcss', plugin.newPostData.cssClasses);
207
208 plugin.formatter.removeQuickEdit();
209 plugin.formatter.flashRow(row);
210 }
211
212
213 // Toggle loading state in form
214 plugin.toggleLoading = function(loading)
215 {
216 $('.row').removeClass('np-updated').removeClass('np-updated-show');
217 if ( loading ){
218 $(NestedPages.selectors.quickEditErrorDiv).hide();
219 $(NestedPages.selectors.quickEditLinkSaveButton).attr('disabled', 'disabled');
220 $(NestedPages.selectors.quickEditLoadingIndicator).show();
221 return;
222 }
223 $(NestedPages.selectors.quickEditLinkSaveButton).attr('disabled', false);
224 $(NestedPages.selectors.quickEditLoadingIndicator).hide();
225 }
226
227 return plugin.bindEvents();
228
229 }