Skip to content

Loading…

Fix error in special chars to suggestion name of slug (stringToSlug special chars power convert) #145

Merged
merged 1 commit into from

2 participants

@leocaseiro

With the other jQuery plugin for conversion to slug, my language (Portuguese Brazilian) does not work very well. So enter another plugin that power convert special chars. System works full. Thanks

@gnuget
Collaborator

this looks very promising

I'm going to do a couple tests before to merge it, but looks very good.

Thank you.

@leocaseiro

Thank you! I believe in your language "Spanish" is also causing this error to use accented chars.
I tried leaving it exactly as it was working the other JS.

If you pass, I take this opportunity to also change the Magic Fields 2.0

@gnuget gnuget merged commit 41abb58 into hunk:master
@leocaseiro

Thanks to merge!

I will make the same change in the Magic Fields 2.0

@gnuget
Collaborator

Cool.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 5, 2011
  1. @leocaseiro

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

    leocaseiro committed
    …pecial chars power convert)
Showing with 30 additions and 32 deletions.
  1. +3 −3 MF_ManageWritePanels.php
  2. +15 −0 js/jquery.stringToSlug.min.js
  3. +12 −29 js/options.js
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!');
}
Something went wrong with that request. Please try again.