PluginProbe ʕ •ᴥ•ʔ
Custom Post Type UI / 1.11.0
Custom Post Type UI v1.11.0
1.19.2 1.19.1 1.19.0 trunk 0.7.0.0 0.7.1.0 0.7.2.0 0.8.0.0 0.8.1 0.8.2 0.8.3 0.8.4 0.8.5 0.9.0 0.9.5 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.1.0 1.1.1 1.1.2 1.1.3 1.10.0 1.10.1 1.10.2 1.11.0 1.11.1 1.11.2 1.12.0 1.12.1 1.13.0 1.13.1 1.13.2 1.13.3 1.13.4 1.13.5 1.13.6 1.13.7 1.14.0 1.15.0 1.15.1 1.16.0 1.17.0 1.17.1 1.17.2 1.17.3 1.18.0 1.18.1 1.18.2 1.18.3 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6.0 1.6.1 1.6.2 1.7.0 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 1.8.0 1.8.1 1.8.2 1.9.0 1.9.1 1.9.2
custom-post-type-ui / js / cptui.js
custom-post-type-ui / js Last commit date
cptui.js 4 years ago cptui.min.js 4 years ago dashicons-picker.js 4 years ago dashicons-picker.min.js 4 years ago
cptui.js
282 lines
1 /**
2 * Add collapseable boxes to our editor screens.
3 */
4 postboxes.add_postbox_toggles(pagenow);
5
6 /**
7 * The rest of our customizations.
8 */
9 (function($) {
10
11 $('#cptui_select_post_type_submit').hide();
12 $('#cptui_select_taxonomy_submit').hide();
13
14 if ('edit' === getParameterByName('action')) {
15 // Store our original slug on page load for edit checking.
16 var original_slug = $('#name').val();
17 }
18
19 // Switch to newly selected post type or taxonomy automatically.
20 $('#post_type').on('change',function(){
21 $('#cptui_select_post_type').submit();
22 });
23
24 $('#taxonomy').on('change',function(){
25 $( '#cptui_select_taxonomy' ).submit();
26 });
27
28 // Confirm our deletions
29 $('.cptui-delete-top, .cptui-delete-bottom').on('click',function(e) {
30 e.preventDefault();
31 var msg = '';
32 if (typeof cptui_type_data !== 'undefined') {
33 msg = cptui_type_data.confirm;
34 } else if (typeof cptui_tax_data !== 'undefined') {
35 msg = cptui_tax_data.confirm;
36 }
37 var submit_delete_warning = $('<div class="cptui-submit-delete-dialog">' + msg + '</div>').appendTo('#poststuff').dialog({
38 'dialogClass' : 'wp-dialog',
39 'modal' : true,
40 'autoOpen' : true,
41 'buttons' : {
42 "OK": function() {
43 var form = $(e.target).closest('form');
44 $(e.target).off('click').click();
45 },
46 "Cancel": function() {
47 $(this).dialog('close');
48 }
49 }
50 });
51 });
52
53 // Toggles help/support accordions.
54 $('#support .question').each(function() {
55 var tis = $(this), state = false, answer = tis.next('div').slideUp();
56 tis.on('click keydown',function(e) {
57 // Helps with accessibility and keyboard navigation.
58 if(e.type==='keydown' && e.keyCode!==32 && e.keyCode!==13) {
59 return;
60 }
61 e.preventDefault();
62 state = !state;
63 answer.slideToggle(state);
64 tis.toggleClass('active',state);
65 tis.attr('aria-expanded', state.toString() );
66 tis.focus();
67 });
68 });
69
70 // Switch spaces for underscores on our slug fields.
71 $('#name').on('keyup',function(e){
72 var value, original_value;
73 value = original_value = $(this).val();
74 if ( e.keyCode !== 9 && e.keyCode !== 37 && e.keyCode !== 38 && e.keyCode !== 39 && e.keyCode !== 40 ) {
75 value = value.replace(/ /g, "_");
76 value = value.toLowerCase();
77 value = replaceDiacritics(value);
78 value = transliterate(value);
79 value = replaceSpecialCharacters(value);
80 if ( value !== original_value ) {
81 $(this).prop('value', value);
82 }
83 }
84
85 //Displays a message if slug changes.
86 if(typeof original_slug !== 'undefined') {
87 var $slugchanged = $('#slugchanged');
88 if(value != original_slug) {
89 $slugchanged.removeClass('hidemessage');
90 } else {
91 $slugchanged.addClass('hidemessage');
92 }
93 }
94
95 var $slugexists = $('#slugexists');
96 if ( typeof cptui_type_data != 'undefined' ) {
97 if (cptui_type_data.existing_post_types.hasOwnProperty(value) && value !== original_slug) {
98 $slugexists.removeClass('hidemessage');
99 } else {
100 $slugexists.addClass('hidemessage');
101 }
102 }
103 if ( typeof cptui_tax_data != 'undefined' ) {
104 if (cptui_tax_data.existing_taxonomies.hasOwnProperty(value) && value !== original_slug) {
105 $slugexists.removeClass('hidemessage');
106 } else {
107 $slugexists.addClass('hidemessage');
108 }
109 }
110 });
111
112 // Replace diacritic characters with latin characters.
113 function replaceDiacritics(s) {
114 var diacritics = [
115 /[\300-\306]/g, /[\340-\346]/g, // A, a
116 /[\310-\313]/g, /[\350-\353]/g, // E, e
117 /[\314-\317]/g, /[\354-\357]/g, // I, i
118 /[\322-\330]/g, /[\362-\370]/g, // O, o
119 /[\331-\334]/g, /[\371-\374]/g, // U, u
120 /[\321]/g, /[\361]/g, // N, n
121 /[\307]/g, /[\347]/g // C, c
122 ];
123
124 var chars = ['A', 'a', 'E', 'e', 'I', 'i', 'O', 'o', 'U', 'u', 'N', 'n', 'C', 'c'];
125
126 for (var i = 0; i < diacritics.length; i++) {
127 s = s.replace(diacritics[i], chars[i]);
128 }
129
130 return s;
131 }
132
133 function replaceSpecialCharacters(s) {
134 if ( 'cpt-ui_page_cptui_manage_post_types' === window.pagenow ) {
135 s = s.replace(/[^a-z0-9\s-]/gi, '_');
136 } else {
137 s = s.replace(/[^a-z0-9\s]/gi, '_');
138 }
139
140 return s;
141 }
142
143 function composePreviewContent(value) {
144
145 var re = /(http|https):\/\/[\w-]+(\.[\w-]+)+([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])?/;
146 var is_url = re.test(value);
147
148 if (!value) {
149 return '';
150 } else if (0 === value.indexOf('dashicons-')) {
151 return $('<div class="dashicons-before"><br></div>').addClass(htmlEncode(value));
152 } else if ( is_url ) {
153 var imgsrc = encodeURI(value);
154 var theimg = document.createElement('IMG');
155 theimg.src = imgsrc;
156 return theimg;
157 }
158 }
159
160 function htmlEncode(str) {
161 return String(str).replace(/[^-\w. ]/gi, function (c) {
162 return '&#' + c.charCodeAt(0) + ';';
163 });
164 }
165
166 var cyrillic = {
167 "Ё": "YO", "Й": "I", "Ц": "TS", "У": "U", "К": "K", "Е": "E", "Н": "N", "Г": "G", "Ш": "SH", "Щ": "SCH", "З": "Z", "Х": "H", "Ъ": "'", "ё": "yo", "й": "i", "ц": "ts", "у": "u", "к": "k", "е": "e", "н": "n", "г": "g", "ш": "sh", "щ": "sch", "з": "z", "�
168 ": "h", "ъ": "'", "Ф": "F", "Ы": "I", "В": "V", "А": "a", "П": "P", "Р": "R", "О": "O", "Л": "L", "Д": "D", "Ж": "ZH", "Э": "E", "ф": "f", "ы": "i", "в": "v", "а": "a", "п": "p", "р": "r", "о": "o", "л": "l", "д": "d", "ж": "zh", "э": "e", "Я": "Ya", "Ч": "CH", "С": "S", "М": "M", "И": "I", "Т": "T", "Ь": "'", "Б": "B", "Ю": "YU", "я": "ya", "ч": "ch", "с": "s", "м": "m", "и": "i", "т": "t", "ь": "'", "б": "b", "ю": "yu"
169 };
170
171 function transliterate(word) {
172 return word.split('').map(function (char) {
173 return cyrillic[char] || char;
174 }).join("");
175 }
176
177 if ( undefined != wp.media ) {
178 var _custom_media = true,
179 _orig_send_attachment = wp.media.editor.send.attachment;
180 }
181
182 function getParameterByName(name, url) {
183 if (!url) url = window.location.href;
184 name = name.replace(/[\[\]]/g, "\\$&");
185 var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
186 results = regex.exec(url);
187 if (!results) return null;
188 if (!results[2]) return '';
189 return decodeURIComponent(results[2].replace(/\+/g, " "));
190 }
191
192 $('#cptui_choose_icon').on('click',function(e){
193 e.preventDefault();
194
195 var button = $(this);
196 var id = jQuery('#menu_icon').attr('id');
197 _custom_media = true;
198 wp.media.editor.send.attachment = function (props, attachment) {
199 if (_custom_media) {
200 $("#" + id).val(attachment.url).change();
201 } else {
202 return _orig_send_attachment.apply(this, [props, attachment]);
203 }
204 };
205
206 wp.media.editor.open(button);
207 return false;
208 });
209
210 $('#menu_icon').on('change', function () {
211 var value = $(this).val();
212 value = value.trim();
213 $('#menu_icon_preview').html(composePreviewContent(value));
214 });
215
216 $('.cptui-help').on('click',function(e){
217 e.preventDefault();
218 });
219
220 $('.cptui-taxonomy-submit').on('click',function(e){
221 if ( $('.cptui-table :checkbox:checked').length == 0 ) {
222 e.preventDefault();
223 var no_associated_type_warning = $('<div class="cptui-taxonomy-empty-types-dialog">' + cptui_tax_data.no_associated_type + '</div>').appendTo('#poststuff').dialog({
224 'dialogClass' : 'wp-dialog',
225 'modal' : true,
226 'autoOpen' : true,
227 'buttons' : {
228 "OK": function() {
229 $(this).dialog('close');
230 }
231 }
232 });
233 }
234 });
235
236 $('#auto-populate').on( 'click tap', function(e){
237 e.preventDefault();
238
239 var slug = $('#name').val();
240 var plural = $('#label').val();
241 var singular = $('#singular_label').val();
242 var fields = $('.cptui-labels input[type="text"]');
243
244 if ( '' === slug ) {
245 return;
246 }
247 if ( '' === plural ) {
248 plural = slug;
249 }
250 if ( '' === singular ) {
251 singular = slug;
252 }
253
254 $(fields).each( function( i, el ) {
255 var newval = $( el ).data( 'label' );
256 var plurality = $( el ).data( 'plurality' );
257 if ( 'undefined' !== newval ) {
258 // "slug" is our placeholder from the labels.
259 if ( 'plural' === plurality ) {
260 newval = newval.replace(/item/gi, plural);
261 } else {
262 newval = newval.replace(/item/gi, singular);
263 }
264 if ( $( el ).val() === '' ) {
265 $(el).val(newval);
266 }
267 }
268 } );
269 });
270
271 $('#auto-clear').on( 'click tap', function(e) {
272 e.preventDefault();
273
274 var fields = $('.cptui-labels input[type="text"]');
275
276 $(fields).each( function( i, el ) {
277 $(el).val('');
278 });
279 });
280
281 })(jQuery);
282