Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix error in special chars to suggestion name of slug (stringToSlug s…

…pecial chars power convert)
  • Loading branch information...
commit b8068d449400ca67388520523fc66e235b03af72 1 parent cdb3f7a
@leocaseiro leocaseiro authored
View
6 MF_ManageWritePanels.php
@@ -11,9 +11,9 @@ function manage_js(){
TRUE
);
- //load jquery slug plugin
- wp_enqueue_script( 'jqueryslug',
- MF_URI.'js/jquery.slug.js'
+ //load jquery stringToSlug plugin (special chars power convert)
+ wp_enqueue_script( 'jqueryStringToSlug',
+ MF_URI.'js/jquery.stringToSlug.min.js'
);
View
15 js/jquery.stringToSlug.min.js
@@ -0,0 +1,15 @@
+/*
+ * jQuery stringToSlug plug-in 1.2.0
+ *
+ * Plugin HomePage http://leocaseiro.com.br/jquery-plugin-string-to-slug/
+ *
+ * Copyright (c) 2009 Leo Caseiro
+ *
+ * Based on Edson Hilios (http://www.edsonhilios.com.br/ Algoritm
+ *
+ *
+ * Dual licensed under the MIT and GPL licenses:
+ * http://www.opensource.org/licenses/mit-license.php
+ * http://www.gnu.org/licenses/gpl.html
+ */
+jQuery.fn.stringToSlug=function(options){var defaults={setEvents:'keyup keydown blur',getPut:'#permalink',space:'-',prefix:'',sufix:'',replace:''};var opts=jQuery.extend(defaults,options);jQuery(this).bind(defaults.setEvents,function(){var text=jQuery(this).val();text=defaults.prefix+text+defaults.sufix;text=text.replace(defaults.replace,"");text=jQuery.trim(text.toString());var chars=[];for(var i=0;i<32;i++){chars.push('')}chars.push(defaults.space);chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push("");chars.push('-');chars.push('-');chars.push('');chars.push('');chars.push('-');chars.push('-');chars.push('-');chars.push('-');chars.push('0');chars.push('1');chars.push('2');chars.push('3');chars.push('4');chars.push('5');chars.push('6');chars.push('7');chars.push('8');chars.push('9');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('A');chars.push('B');chars.push('C');chars.push('D');chars.push('E');chars.push('F');chars.push('G');chars.push('H');chars.push('I');chars.push('J');chars.push('K');chars.push('L');chars.push('M');chars.push('N');chars.push('O');chars.push('P');chars.push('Q');chars.push('R');chars.push('S');chars.push('T');chars.push('U');chars.push('V');chars.push('W');chars.push('X');chars.push('Y');chars.push('Z');chars.push('-');chars.push("-");chars.push('-');chars.push('');chars.push('-');chars.push('');chars.push('a');chars.push('b');chars.push('c');chars.push('d');chars.push('e');chars.push('f');chars.push('g');chars.push('h');chars.push('i');chars.push('j');chars.push('k');chars.push('l');chars.push('m');chars.push('n');chars.push('o');chars.push('p');chars.push('q');chars.push('r');chars.push('s');chars.push('t');chars.push('u');chars.push('v');chars.push('w');chars.push('x');chars.push('y');chars.push('z');chars.push('-');chars.push('');chars.push('-');chars.push('');chars.push('');chars.push('C');chars.push('A');chars.push('');chars.push('f');chars.push('');chars.push('');chars.push('T');chars.push('t');chars.push('');chars.push('');chars.push('S');chars.push('');chars.push('CE');chars.push('A');chars.push('Z');chars.push('A');chars.push('A');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('-');chars.push('-');chars.push('');chars.push('TM');chars.push('s');chars.push('');chars.push('ae');chars.push('A');chars.push('z');chars.push('Y');chars.push('');chars.push('');chars.push('c');chars.push('L');chars.push('o');chars.push('Y');chars.push('');chars.push('S');chars.push('');chars.push('c');chars.push('a');chars.push('');chars.push('');chars.push('');chars.push('r');chars.push('-');chars.push('o');chars.push('');chars.push('2');chars.push('3');chars.push('');chars.push('u');chars.push('p');chars.push('');chars.push('');chars.push('1');chars.push('o');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('A');chars.push('A');chars.push('A');chars.push('A');chars.push('A');chars.push('A');chars.push('AE');chars.push('C');chars.push('E');chars.push('E');chars.push('E');chars.push('E');chars.push('I');chars.push('I');chars.push('I');chars.push('I');chars.push('D');chars.push('N');chars.push('O');chars.push('O');chars.push('O');chars.push('O');chars.push('O');chars.push('x');chars.push('O');chars.push('U');chars.push('U');chars.push('U');chars.push('U');chars.push('Y');chars.push('D');chars.push('B');chars.push('a');chars.push('a');chars.push('a');chars.push('a');chars.push('a');chars.push('a');chars.push('ae');chars.push('c');chars.push('e');chars.push('e');chars.push('e');chars.push('e');chars.push('i');chars.push('i');chars.push('i');chars.push('i');chars.push('o');chars.push('n');chars.push('o');chars.push('o');chars.push('o');chars.push('o');chars.push('o');chars.push('');chars.push('o');chars.push('u');chars.push('u');chars.push('u');chars.push('u');chars.push('y');chars.push('');chars.push('y');chars.push('z');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('C');chars.push('c');chars.push('D');chars.push('d');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('E');chars.push('e');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('N');chars.push('n');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('R');chars.push('r');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('S');chars.push('s');chars.push('');chars.push('');chars.push('T');chars.push('t');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('U');chars.push('u');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('');chars.push('Z');chars.push('z');for(var i=256;i<100;i++){chars.push('')}var stringToSlug=new String();for(var i=0;i<text.length;i++){stringToSlug+=chars[text.charCodeAt(i)]}stringToSlug=stringToSlug.replace(new RegExp('\\'+defaults.space+'{2,}','gmi'),defaults.space);stringToSlug=stringToSlug.replace(new RegExp('(^'+defaults.space+')|('+defaults.space+'$)','gmi'),'');stringToSlug=stringToSlug.toLowerCase();jQuery(defaults.getPut).val(stringToSlug);jQuery(defaults.getPut).html(stringToSlug);return this});return this}
View
41 js/options.js
@@ -43,41 +43,24 @@ jQuery(document).ready(function(){
/* Addition to allow suggestion of a field name based on the label */
+ var string_prefix = "";
+ if (mf_group_info && mf_group_info.safe_name && mf_group_info.safe_name != "" && mf_group_info.safe_name != "__default") {
+ string_prefix = mf_group_info.name + ' ';
+ if (string_prefix == " ") {
+ string_prefix = "";
+ }
+ }
- var suggestCustomFieldName = function() {
- var desc = jQuery('#custom-field-description').val();
-
- // first, try to extract bracketed items OUT of the field name
- // so a field labelled "Image File (640 X 480)" would have the extra
- // info removed from the suggestion
-
- desc = desc.replace(/\s?\([^\)]*\)/gi, "");
-
- var nv = jQuery.slug(desc, { sep: "_" });
-
-
- if (mf_group_info && mf_group_info.safe_name && mf_group_info.safe_name != "" && mf_group_info.safe_name != "__default") {
- var prefix = jQuery.slug(mf_group_info.singular_safe_name, { sep: "_" });
-
- if (prefix != "" && prefix != "_") {
- nv = prefix + "_" + nv;
- }
- }
-
- jQuery('#custom-field-name').val(nv);
-
- };
-
- jQuery('#custom-field-description').change(function(event) {
+ jQuery('#custom-field-description').focus(function(event) {
if (mf_create_field) { // only suggest names if user is CREATING the field
- suggestCustomFieldName();
+ jQuery("#custom-field-description").stringToSlug({space:'_', getPut:'#custom-field-name', prefix:string_prefix, replace:/\s?\([^\)]*\)/gi});
}
});
- jQuery('#bt-custom-field-name-suggest').click( function() {
-
+ jQuery('#bt-custom-field-name-suggest').click( function() {
if (jQuery.trim(jQuery('#custom-field-description').val()) != "") {
- suggestCustomFieldName();
+ jQuery("#custom-field-description").stringToSlug({space:'_', getPut:'#custom-field-name', prefix:string_prefix, replace:/\s?\([^\)]*\)/gi});
+ jQuery("#custom-field-description").trigger('blur');
} else {
alert('Please enter a field label first!');
}
Please sign in to comment.
Something went wrong with that request. Please try again.