Permalink
Browse files

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

…pecial chars power convert)
  • Loading branch information...
leocaseiro committed Sep 5, 2011
1 parent cdb3f7a commit b8068d449400ca67388520523fc66e235b03af72
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
@@ -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'
);

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -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!');
}

0 comments on commit b8068d4

Please sign in to comment.