Skip to content

Commit

Permalink
Handle " and '
Browse files Browse the repository at this point in the history
git-svn-id: http://plugins.svn.wordpress.org/media-credit/trunk@1233715 b8457f37-d9ea-0310-8a92-e5e31aec5664
  • Loading branch information
mundschenk-at committed Aug 29, 2015
1 parent 4dace12 commit 7fd4faf
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions js/tinymce4/media-credit-tinymce.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,7 @@ tinymce.PluginManager.add( 'mediacredit', function( editor ) {
}

if ( name ) {
b = b.replace( name[0], '' );
} else {
name = ''; // otherwise null gets handled as a string
b = b.replace( name[0], '' );
}

c = trim( c );
Expand All @@ -228,7 +226,8 @@ tinymce.PluginManager.add( 'mediacredit', function( editor ) {
id = ( id && id[1] ) ? id[1] : '';
align = ( align && align[1] ) ? align[1] : 'alignnone';
link = ( link && link[1] ) ? link[1] : '';

name = ( name && name[1] ) ? name[1] : '';

if ( ! w && img ) {
w = img.match( /width=['"]([0-9]*)['"]/ );
}
Expand All @@ -248,16 +247,16 @@ tinymce.PluginManager.add( 'mediacredit', function( editor ) {

credit = '' + (name ? name : ($mediaCredit.id[id] + $mediaCredit.separator + $mediaCredit.organization));
credit = credit.replace(/<[^>]+>(.*)<\/[^>]+>/g, '$1'); // basic sanitation

out = img + wp.html.string({
tag: 'span',
content: credit,
attrs: {
'class': 'mceMediaCreditTemp mceNonEditable',
'data-media-credit-id': id,
'data-media-credit-name': name,
'data-media-credit-name': _.escape(name),
'data-media-credit-align': align,
'data-media-credit-link' : link
'data-media-credit-link' : _.escape(link)
}
});

Expand Down Expand Up @@ -366,7 +365,7 @@ tinymce.PluginManager.add( 'mediacredit', function( editor ) {
}

return content.replace( pattern , function( a, b, c, d) {
var out = '', id, name, w, align, link,
var out = '', id, name, w, align, link, quoted_name,
trim = tinymce.trim;

if ( b.indexOf('<img ') === -1 ) {
Expand All @@ -387,7 +386,13 @@ tinymce.PluginManager.add( 'mediacredit', function( editor ) {
return b;
}

credit = id ? ('id='+id) : ('name="'+name+'"');
if ( name.indexOf('"') > -1 ) {
quoted_name = "name='" + name + "'";
} else {
quoted_name = 'name="' + name + '"';
}

credit = id ? ('id='+id) : quoted_name;

if ( link ) {
credit += ' link="' + link + '"';
Expand Down Expand Up @@ -539,7 +544,7 @@ tinymce.PluginManager.add( 'mediacredit', function( editor ) {

if (mediaCreditBlock) {
metadata.align = (metadata.align && metadata.align != 'none' ) ? metadata.align : dom.getAttrib(mediaCreditBlock, 'data-media-credit-align', '').replace( 'align', '' );
metadata.mediaCreditName = dom.getAttrib(mediaCreditBlock, 'data-media-credit-name', '');
metadata.mediaCreditName = dom.getAttrib(mediaCreditBlock, 'data-media-credit-name', '');
metadata.mediaCreditID = dom.getAttrib(mediaCreditBlock, 'data-media-credit-id', '');
metadata.mediaCreditLink = dom.getAttrib(mediaCreditBlock, 'data-media-credit-link', '');
}
Expand Down

0 comments on commit 7fd4faf

Please sign in to comment.