You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Now I want to suggest some values to be shown if not available.
I read your code and learned something about coding tinymce plugins. I've modified your code so it fullfills my needs so far.
(function(){tinymce.PluginManager.add('editattributes',function(editor){functionshowDialog(){varselectedNode=editor.selection.getNode(),body=[],// There are some unwanted attributes in the popup - don't show themunwantedAttributes=['data-mce-href'],// Suggest some attributessuggestedAttributes={'data-event': {value: '',prefix: 'GA: '},'data-description': {value: '',prefix: 'GA: '},'data-parameter': {value: '',prefix: 'GA: '}};// Show availabe attributes except unwanted and suggestedfor(vari=0,j=selectedNode.attributes.length;i<j;i++){varattribute=selectedNode.attributes[i],attributeName=attribute.name;// Not the unwantedif(unwantedAttributes.includes(attributeName)){continue;};// Not the suggested. But give them the value if availableif(suggestedAttributes[attributeName]){suggestedAttributes[attributeName].value=attribute.value;continue;};body.push({type: 'textbox',name: attribute.name,size: 40,label: attribute.name,value: attribute.value});}// Show suggested attributesfor(varkeyinsuggestedAttributes){body.push({type: 'textbox',name: key,size: 40,label: suggestedAttributes[key].prefix+key,value: suggestedAttributes[key].value});}// New attribute fieldbody.push({type: 'container',label: 'New attribute',layout: 'flex',direction: 'row',align: 'center',spacing: 5,items: [{name: 'mce_new_name',type: 'textbox',ariaLabel: 'Name'},{name: 'mce_new_value',type: 'textbox',ariaLabel: 'Value'},]});editor.windowManager.open({title: 'Edit Attributes',body: body,onsubmit: function(e){editor.undoManager.transact(function(){varnew_name=e.data['mce_new_name'];varnew_value=e.data['mce_new_value'];deletee.data['mce_new_name'];deletee.data['mce_new_value'];if(new_name.length>0){e.data[new_name]=new_value;}for(keyine.data){editor.dom.setAttribs(selectedNode,e.data);}});}});}//editor.addCommand('mceEditAttributes', showDialog);editor.addButton('editattributes',{icon: 'anchor',tooltip: 'Edit Attributes',onclick: showDialog});editor.addMenuItem('editattributes',{icon: 'anchor',context: 'edit',text: 'Edit Attributes',onclick: showDialog});});}());
Do you know how we can make this configurable so we do not need to put the attribute suggestions hardcoded into the plugin.js?
How do you like the idea of attribute suggestions. Here I want to set data-attributes for links that should get tracked with Google Analytics (GA).
The text was updated successfully, but these errors were encountered:
Hi and thanks for the suggestion. I like it. I'm not really a TinyMCE developer though, I just did this plugin because I needed it for one of my project.
I advise you to look at other TinyMCE plugins to find out how it works, because the documentation isn't really helpful...
For example this smiley plugin has a customizable setting.
If you do a PR with your feature, I'll gladly review and merge it.
Hello Gagaro, thank you for this plugin.
Now I want to suggest some values to be shown if not available.
I read your code and learned something about coding tinymce plugins. I've modified your code so it fullfills my needs so far.
Do you know how we can make this configurable so we do not need to put the attribute suggestions hardcoded into the plugin.js?
How do you like the idea of attribute suggestions. Here I want to set data-attributes for links that should get tracked with Google Analytics (GA).
The text was updated successfully, but these errors were encountered: