Django - Load template with jQuery into variable - javascript

I'm working with a client that has a view that, after a user logs in, this view loads a template, that dynamically draws a canvas with jQuery, and generates an image copy of the canvas.
They want to protect the jQuery code, hiding the process in the python code.
I tried using PyExecJS, but it doesn't support jQuery, since there is no DOM.
I've also tried urllib2, mechanize and Selenium, but none worked.
Is there an alternative or have I missed something?
Update/Resolution: In case someone stumbles onto this question: I ended up using Selenium for Python to load the JS function, fed it the necessary data and extracted the image from it. It has a bit of an overhead, but since the main goal was to keep the JS code obfuscated, it worked.

If I understand correctly, you are trying to hide jquery code.
You can't hide jquery code from the user, because django processes python code before it serves up the template, there's no way to protect jquery code with python. Really the best thing you can do is to minimize and obfuscate the code, but that only makes it difficult for human reading.

Related

How to use Javascript as a backend script to make server side api calls without using HTML in Jint

This link sets up the context for this question.
I am trying to use Javascript as the backend code for my mobile application(windows) which has a native UI(not HTML UI). That means I don't have HTML. Hence I don't have DOM.
I have successfully been able to create functions which does some computation locally like add, call them from my C# or Java code and get the return values.
Now I am running into 2 problems
1) I am trying to take my javascript functions one step further by trying to call server apis from the Javascript using XMLHttpRequest. But I am getting a script execution exception in my C#(This usually occurs if the script was unable to run). I think this is because XMLHttpRequest needs DOM and I don't have DOM.
If my first problem is solved then
2)How to get hold of a different Javascript file when I don't have DOM. For example let's say I want to use Jquery to simplify my requests using $.Ajax etc, but how do I load the Jquery library because I don't have the luxury of script tag neither do I have the luxury of using $.getScript because I am trying to get Jquery itself.
One possible solution
There is one solution that I can think on top of my head. Use a webview and load your html in the WebView and use Jint for Javascript. But then the question arises How do I use WebView in par with Jint.
I would be glad if someone can point me in the right direction.
Thanks in advance.

ruby on rails v2 prototype issues

am going with some background information first
I have a clash between Dojo and Prototype.js on the client side, so to fix this I rewrote the client side hooks in plain javascript.
But now the issue is since Prototype.js is not being imported, the ajax functions created by the render do not work. Is there anyway I could rewrite them? Or use jquery atleast. I am using RoR v2.3.8 and updating is out of the question, so is messing with the dojo or dojo content.
I thought I could try send the prototype.js tag with the response but I have no idea how, after reading a lot of documentation am told to insert some javascript tag but where.
also is there anyway to edit actioncontroller

JavascriptMVC and JQuery

I was put in charge of managing and enhancing a JavascriptMVC framework that works with python for the backend. I am more of a backend developer, but need to try to expedite some front end features.
Having dealt with jquery in the past, I thought I could apply some changes onto the DOM after it had loaded. Here is what I tried...
I did try to apply a raw jquery script directly to the end of the index.html page (and after the steal call).
I also tried to rap it into the main steal(); call in an init.js script.
Then attempted to place it in the section in question to be altered as a $.Controller .
Obviously this did not work.
My question: How should I inject jquery into the DOM after its been rendered?
I just learned the scheme that the previous people had created in this framework. It was quicker than I thought, but still painful and more to come.

JavaScript: Write to current HTML document using input from a separate HTML document?

Preface: Hi, all! Here goes. First and foremost, I am not familiar with jquery, so any jquery code posted will be irrelevant to me until i research it. I'm newly teaching myself JS. I have decent XHTML experience, decent CSS3 familiarity/understanding, and some (very little) application programming experience (C++, Java).
The Situation: I'm designing a website's home page whereon, with JavaScript enabled, links are overwritten and instead of loading a new HTML document/page for each main link, I alter sections of the home page using JS.
The challenge: I want to load new page content without loading an entirely separate page. A similar old HTML solution to such a challenge was to load page frames, right? I want to overwrite an entire container element using content from another separate HTML file on the server. (The external file could be tailored to fit into the main page, but it would be even better if I could pull a SECTION of an external HTML document, perhaps one element).
Can I do this using only JavaScript?
If not, what other scripting could be used in conjunction with JS?
Would I need to implement "AJAX"?
Must I use "HTML DOM"? - Edit: I see that DOM is just integral to the function of HTML etc.
Thank you all for your patience and your expert advice. I <3 StackExchange.
Yes you can do that using Javascript and jQuery, take a look at the load() method that's exactly what you need
http://api.jquery.com/load/
Yes it is using AJAX, but it's really easy to use don't worry.
Can I do this using only JavaScript?
No, because the server will need to serve you the content / data that you wish to place in the HTML page. You'll need to combine client-side scripting (JavaScript) with functionality on the web server (see your next question below).
If not, what other scripting could be used in conjunction with JS?
That would be your server-side language, such as PHP, Ruby, or Python.
Would I need to implement "AJAX"?
Yes, what you described is implemented using Ajax. You've mentioned the jQuery library and it indeed has functionality to perform an Ajax call to the server (see $.ajax). The basic idea is: your JavaScript code performs an Ajax call, your web server returns the HTML and then your JavaScript code receives it and places it in the HTML page.
Must I use "HTML DOM"?
Web pages always make use of "HTML DOM". You could read the article about Document Object Model on Wikipedia for more information: you have to use DOM but not by choice - it's part of how web pages work.

Accessing Local Files with jQuery

I believe that this question has been asked in a few different forms, but I've read quite a few different responses.
At first, I had a web-application written with mostly jQuery that would make use of servlets to retrieve information from various locations JavaScript could not access (ie. Feeds, images from a server, etc.). Now, however, I've been told to do away with the servlets and application configuration classes so that this project of mine contains only HTML, CSS, and JavaScript/jQuery. Rather than pulling the images off of the server, I need to retrieve them from a local file on the computer. I know that allowing this might seem like terrible design, but it's what I've been asked to do. At any rate, what I really need to do is count the number of image files in a directory and then perhaps compile an array of the filenames themselves. I could do this fine in Java when using the servlets, but without them, I'm not sure how or even if this can be done.
I'm basically trying to use the jQuery Cycle plug-in to cycle through these images like a slideshow. I inject (or $("#div").append()) these images into the div by using a loop based on the number of images present.
So, is there a way I can do this with using JavaScript, HTML, jQuery plug-in, etc? I'd like to avoid using PHP and Java at this point...
You can't just read a directory with JavaScript; however, there appears to be a way to "exploit" how browsers function using http://www.irt.org/articles/js014/. It may not be pretty, but the demo works in the latest Chrome and IE7-9 for me. I'm sure some of the techniques could be updated to use cleaner code if you'd like to improve upon it.
EDIT:
Another technique you could use can be found in Javascript read files in folder
It definitely looks to be a cleaner solution. What I'd recommend is extracting the body contents to inject into a hidden div or using the path for an iframe that you can read from.

Categories

Resources