iwato Posted July 10, 2018 Share Posted July 10, 2018 BACKGROUND: I would like to insert a jQuery UI widget into my code. In order to make the widget work, however, it appears to require a more recent version of jQuery. Should I implement the widget, the HTML in which it resides, the controlling Javascript including the new version of jQuery, as well as the CSS would all be called dynamically when the widget is inserted. My concern is that the new inserted version of jQuery might interfere with the rest of the page not included in the insert. QUESTION: Do I have reason to be concerned? Please explain your answer. Link to comment Share on other sites More sharing options...
dsonesuk Posted July 10, 2018 Share Posted July 10, 2018 You can use multiple version of jQuery as explained here https://stackoverflow.com/questions/1566595/can-i-use-multiple-versions-of-jquery-on-the-same-page That is why sometimes you will see '$' for $(...) or 'jQuery' jQuery(...) there are used to separate jquery plugins that may cause conflict. Link to comment Share on other sites More sharing options...
justsomeguy Posted July 10, 2018 Share Posted July 10, 2018 Note that whichever version you include last will overwrite any other version, so if you want to use a particular version for something special then you should include it before your other version and save the reference. If you are dynamically adding a new version at some later point when some event happens, it's probably going to override your main version, so in that case you need to save a reference to your main version and use that reference in your code. Of course, it would be preferable to use plugins that will work in a recent version, but for older things that's not always possible. Link to comment Share on other sites More sharing options...
iwato Posted August 7, 2018 Author Share Posted August 7, 2018 (edited) No, I have not forgotten. Simply, I believe that I have found a way to avoid the problem. Use a technique that does not depend on jQuery. BACKGROUND: I have discovered a Javascript package called wordcloud2.js. In order to run this I need to create a list. in preparation for this moment I have managed to create an array of objects from the Matomo database that contain the information needed to create the list. Each object in the array takes the following form: category: "Site Search / [category]" count: "[number]" target: "[search string]" where the information contained in the brackets are the values of the respective properties of each object. The array takes on the following appearance: array {object, object, object, ..., object) THE GOAL: Create a list of the following format. [number] [search string] [number] [search string] [number] [search string] ... [number] [search string] DILEMMA: Now, there is plenty of information about how to create objects and arrays from lists. I need to know how to do just the opposite. Roddy Edited August 7, 2018 by iwato Link to comment Share on other sites More sharing options...
justsomeguy Posted August 7, 2018 Share Posted August 7, 2018 Just loop through the array and build the text from whatever information you want to use in each object. Link to comment Share on other sites More sharing options...
iwato Posted August 7, 2018 Author Share Posted August 7, 2018 Yes, but what is the format of the resulting list? 1) Is it pairs of elements separated by commas in a single line. [count] [search string], [count] [search string], [count] [search string], ... [count] [search string] \n 2) Is it pairs of elements separated by line breaks? [count] [search string] \n [count] [search string] \n [count] [search string] \n ... [count] [search string] \n Also, how does Javascript recognize a list as a list? Is everything closed in parantheses? Is there a special method that constitutes a list from either of the above two formats. Then too, what happens, if the search string is composed of multiple words? It is not as simple a problem, as it would first appear. Well, at least not for me, at any rate. Roddy Link to comment Share on other sites More sharing options...
justsomeguy Posted August 7, 2018 Share Posted August 7, 2018 Quote Yes, but what is the format of the resulting list? There's not a rule on what you have to build, so build what you need. An obvious way is to put each item you want into another array, and then join the array elements using whatever separator you want. Quote Also, how does Javascript recognize a list as a list? Javascript does not have a data structure called a list, that is not a well-defined term in Javascript. If it is string data that is structured a certain way, then you're the one who defines how it is structured (or whatever consumes the data defines what it expects). If it is a string that is composed of other strings separated by some separator, it makes sense to put them in an array then join them. Quote Then too, what happens, if the search string is composed of multiple words? These are questions that need to be answered by whatever is consuming the data. Maybe you need a CSV format, for example, with each field quoted. Quote It is not as simple a problem, as it would first appear. It's not as complex as you think. Step 1 is figuring out in exactly what format the data needs to be. If you want each item separated by a newline, it's this easy: var ar = []; for (var i = 0; i < items.length; i++) { ar.push(items[i].number + " " + items[i].search_string); } var list = ar.join("\n"); Link to comment Share on other sites More sharing options...
iwato Posted August 7, 2018 Author Share Posted August 7, 2018 OK. Then you appear to agree with the following: Quote Load wordcloud.js script to the web page, and run: WordCloud(document.getElementById('my_canvas'), { list: list } ); where list is an array that look like this: [['foo', 12], ['bar', 6]]. But then, how would you interpret the meaning of {list: list} in the above statement? Is the first list the name of an object property called list, and the second list an array called list of the form [['foo', 12], ['bar', 6]]. Is it just this simple? Roddy Link to comment Share on other sites More sharing options...
justsomeguy Posted August 7, 2018 Share Posted August 7, 2018 Yeah, that's what it looks like. 1 Link to comment Share on other sites More sharing options...
iwato Posted August 9, 2018 Author Share Posted August 9, 2018 I have managed to get wordcloud2.js to interact effectively with the Matomo database. Very soon Grammar Captive will have its own word cloud. Thank you! Roddy Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now