Skip to content

Commit

Permalink
Fix error in special chars to suggestion name of slug (stringToSlug s…
Browse files Browse the repository at this point in the history
…pecial chars power convert)
  • Loading branch information
leocaseiro committed Sep 5, 2011
1 parent cdb3f7a commit b8068d4
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 32 deletions.
6 changes: 3 additions & 3 deletions MF_ManageWritePanels.php
Expand Up @@ -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'
);


Expand Down
15 changes: 15 additions & 0 deletions js/jquery.stringToSlug.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 12 additions & 29 deletions js/options.js
Expand Up @@ -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!');
}
Expand Down

0 comments on commit b8068d4

Please sign in to comment.