We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3749
    • 24,544 Posts
    I fought with it also. This is what I ended up with for the front end:

    getFileCallback: function(file) {
           var fileUrl = file.url.replace('\\','/'); // normalize fileUrl
           var mybase = file.baseUrl.replace('\\','/'); // normalize baseUrl
           var finalUrl = fileUrl.replace(mybase, '');  // strip baseUrl
                  
           // This is for the preview window 
           var imgTag = '<img src="'+ file.tmb + '">';
    
           $('#np-[[+npx.fieldName]]').val(finalUrl); // put the file path in the input field
           $('#editor').remove(); //close the window after image is selected
           $('#np-[[+npx.fieldName]]_preview').html(imgTag);
          // console.log(file.path);
          // console.log(file.url);
          // console.log('FINAL: '+finalUrl);
          // console.log(file);
      }
      Did I help you? Buy me a beer
      Get my Book: MODX:The Official Guide
      MODX info for everyone: http://bobsguides.com/modx.html
      My MODX Extras
      Bob's Guides is now hosted at A2 MODX Hosting
      • 36760
      • 136 Posts
      Okay, in an embarrassing turn of events, my chunkSuffix property had become unset, so the whole time it wasn't loading from the chunks I was changing!

      The example plugin worked by adding the path to TinymceWrapperCommonCode with the other "external_plugins". Then, adding "example" to the "toolbar" list in TinymceWrapperContent.

      Thank you for your help, and sorry for using up your time!
        • 42562
        • 1,145 Posts
        Perfect! you got that settled.
          TinymceWrapper: Complete back/frontend content solution.
          Harden your MODX site by passwording your three main folders: core, manager, connectors and renaming your assets (thank me later!)
          5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.
          • 36760
          • 136 Posts
          I'm not sure if this is better suited for this thread or the TinyMCE forums, but I'll start here.

          I'm pretty close on the basics for my plugin, things are a bit messy, but it "works." The last problem is I get this error when clicking on my select box: Uncaught Error: Could not find control by type: { text: '4', value: 'spell 1' }, { text: '5', value: 'spell 2' } ...full list of data

          This is my plugin file:
          var spellValues = [];
          $(function() {
          	$.ajax({
          		url:"db-access.php",
          		dataType: 'json',
          		success:function(data){
          			//alert(data);
          			$.each(data,function(){
          				spellValues.push("{ text: '" + this.id + "', value: '" + this.name + "' }");
          			});
          		}
          	});
          	console.log(spellValues);
          });
          
          function getValues() {
           	//Set new values to myKeyValueList 
          	tinyMCE.activeEditor.settings.myKeyValueList = spellValues.join();
            	return tinyMCE.activeEditor.settings.myKeyValueList;
          }
          
          tinymce.PluginManager.add('example', function(editor, url) {
            // Add a button that opens a window
            editor.addButton('example', {
              text: 'My button',
              icon: false,
              onclick: function() {
                // Open window
                editor.windowManager.open({
                  title: 'Spell',
          		width : 270,
          		height : 70,
          		body: [
          		  {type: 'listbox',
          			name: 'spells',
          			label: 'Select :',
          			values: getValues()
          		  }
          		],
                  onsubmit: function(e) {
                    // Insert content when the window form is submitted
                    editor.insertContent('Title: ' + e.data.spells);
                  }
                });
              }
            });
          });


          If I replace 'values': getValues() with values: { text: '4', value: 'spell 1' }, { text: '5', value: 'spell 2' } everything works fine. I'm not sure what's breaking down with the "getValues" function, but I believe it's required so I can get the list of values from the database in "real time."
            • 42562
            • 1,145 Posts
            RE: firebot6

            Let's prepare a different sort of treat for your spellValues

            //var spellValues = [];
            var spellValues = ''; //***
            $(function() {
                $.ajax({
                    url:"db-access.php",
                    dataType: 'json',
                    success:function(data){
                        //alert(data);
                        $.each(data,function(){
                           // spellValues.push( "{ text: '" + this.id + "', value: '" + this.name + "' }");
                          spellValues += '{text: "' + this.id +  '", value: "' + this.name + '"}\n'; //***
                        });
                    }
                });
                console.log(spellValues);
            });
            
            function getValues() { //consider passing "editor" as arg
                var newSpellValues = spellValues.replace(/\n\s*$/, '').replace(/\n/g, ','); //***
                newSpellValues = '[' + newSpellValues + ']';
                newSpellValues = tinymce.util.JSON.parse(newSpellValues); //TinyMCE likes her cake baked in a certain way ..huh huh huh
                tinymce.activeEditor.settings.myKeyValueList = newSpellValues; //consider using  editor.settings.myKeyValueList
                return newSpellValues;
            }


            Hopefully that solves ya issue. [ed. note: donshakespeare last edited this post 7 years, 2 months ago.]
              TinymceWrapper: Complete back/frontend content solution.
              Harden your MODX site by passwording your three main folders: core, manager, connectors and renaming your assets (thank me later!)
              5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.
              • 42562
              • 1,145 Posts
              RE: BobRay
              Thanks for that piece of code ...
              I'll run that against what I have
                TinymceWrapper: Complete back/frontend content solution.
                Harden your MODX site by passwording your three main folders: core, manager, connectors and renaming your assets (thank me later!)
                5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.
                • 36760
                • 136 Posts
                Quote from: donshakespeare at Feb 21, 2017, 06:54 AM
                RE: firebot6

                Let's prepare a different sort of treat for your spellValues

                Hopefully that solves ya issue.

                That works the first time I insert something with the button/dropdown, but trying to insert a second item gives me this error when clicking "My button" on the toolbar: Uncaught TypeError: spellValues.replace is not a function. Recreated on the fiddle: http://fiddle.tinymce.com/fKfaab. I thought it might be it was trying to run the replace a second time, so I moved it outside the getValues function to the normal function, but that breaks everything. I probably should have started with something easier, but that's not my style. smiley Thanks for the help again!

                I'll ask this here too. I was looking into the Template Plugins you linked me earlier and they seem like what I ultimately want to do, but I wanted to run my full idea by you first in case there's something even better.

                My goal with all this is to be able to have a popup window from a button that has a listbox and several text fields. You'll select a spell by name from the dropdown which will populate the text fields with the separate pieces of data, which you can then edit and save back to the database if needed (editing from the popup is a luxury feature). Once you have a spell selected, you can insert it along with all of the data into the editor with the intended HTML markup (or if HTML markup doesn't work, I have a Modx snippet I can pass the data through to make the HTML, which is what I'm using currently).

                Am I correct that Template Plugins will let me handle as many data points as I need, where as the current listbox I'm working with is just "value" and "text"? I'm also assuming the text field population and saving back to the database could be handled similar to methods you'd use without TinyMCE in the picture, so that's something for me to work on by myself.
                  • 42562
                  • 1,145 Posts
                  RE: firebot6

                  That works the first time I insert something with the button/dropdown, but trying to insert a second item gives me this error when clicking "My button" on the toolbar: Uncaught TypeError: spellValues.replace is not a function. Recreated on the fiddle: http://fiddle.tinymce.com/fKfaab

                  We have textbook case/example of Mistaken Evolutionary Identity.

                  When spellValues was first set, it was a mere primordial string; and all worked fine, and all were happy

                  1. Firstly, then function getValues() laid hands on spellValues and taught it to grow an array of wings, thus thoroughly messing with the original string state.
                  2. Secondly, unbeknownst to function getValues(), the transformation of spellValues was immense and simply reactionary, so that when function getValues() tried again to lay hands on spellValues nothing short of a browser explosion occurred, since spellValues was now no longer a soup.
                  3. In short, string.replace = good but, array.replace = whut whut!!! is not a function

                  I updated the above code to
                  var newSpellValues = spellValues.replace(/\n\s*$/, '').replace(/\n/g, ','); //***


                  As for your second question, I'll think about it, and respond later.
                    TinymceWrapper: Complete back/frontend content solution.
                    Harden your MODX site by passwording your three main folders: core, manager, connectors and renaming your assets (thank me later!)
                    5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.
                    • 36931
                    • 206 Posts
                    Hello,
                    I am not sure if I understand the procedure. I need to personalize the toolbar. For exemple, I really need to add an option to add/edit a table and an option to add a class to a link or to a table (while editing the content.

                    If I correctly understand the above post, I would have to add a script to my modx.
                    <script src="[[++manager_url]]templates/jm/js/tinymcewrapper.js"></script>

                    In that file, I would add
                    <script type="text/javascript">
                    tinymce.init({
                        selector: "textarea",
                        plugins: "image link",
                        toolbar: "example image link unlink",
                    	external_plugins: {
                    		example: "http://myMODXsite.com/example.js"
                    	}
                    });
                    </script>
                    

                    and then I can personalize my toolbar. But wath's external_plugins?

                    How would I better do, to make sure to give the option to the user, to add a custom class to the content (link, table, image etc)

                    Thanks a lot [ed. note: pierrot1010 last edited this post 7 years, 1 month ago.]
                      • 40041
                      • 36 Posts
                      Hello there,

                      I have a frustrating issue on a fresh and current modx installation.

                      A migx template variable setup with an input type of "richtext" is not rendering correctly and it's driving me nuts trying to figure out why.

                      Some screenshots attached.

                      You can see in the one it renders as simply a text area sort of, with an unlabeled checkbox. You can type in both fields, including the malrendered richtext box, but you cannot correctly click the "Done" button. Doing so generates a java script error - see attached screenshot.

                      Any tips?