Recaptcha not rendering - django

This should be totaly simple, but I guess I must be missing something..
I put this in the html body, before the form:
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
Then inside a form I have this recaptcha div:
...
<form action="" method="post">
<div class="g-recaptcha" data-sitekey="[MY_API_KEY]"></div>
...
When the page loads, there's no recaptcha and also firebug's console doesn't output anything. What could be wrong?
EDIT: Now it actually works sometimes, but I have to refresh the page, but it's totally random if it works or not. This is really strange behaviour.

The reCAPTCHA page itself says to put the script tag inside the head tag, so it should load before everything else. Also, check if you have two script tags...wink

Try removing the async and defer attributes from your script tag and place it somewhere above your form.
<script src='https://www.google.com/recaptcha/api.js'></script>
This will ensure that your script is run before your form is parsed.
the api.js is only ~532 bytes (minified) and shouldn't add much overhead to your page loading.
Also I'm not sure if this question is related to django in anyway. I suggest you remove that tag from your question :)
Hope this helps and best of luck.

i got similar problem with chart.js on my website.
If, it is same case with me (when reload page works), i think js file doesn't downloaded until your html rendering.
check safari or chrome resource download time.
if your screen is ready and recapcha.js is until downloading, you should add set timeout or etc to wait for your javascript code.
i tried like this..
setTimeout(function(){
Chart.defaults.global.tooltipFontSize= 10;
Chart.defaults.global.scaleShowLabels=false;
}, 10)

Related

Jquery inside of CFDiv

I have a page that includes a CFDiv tag that displays content from another file.
<cfajaximport tags="cfwindow,cfform,cflayout-tab,cfdiv">
<cfoutput><cfdiv class="vehicle-log" bind="url:trip_tab.cfm?ticketid=#ticketnum#" ID="theDiv" bindOnLoad = "true"/></cfoutput>
The external file has jquery tabs and jquery datepicker. None of the jquery seems to work in the CFDiv. If I call the external page by itself, everything works fine.
The reason I'm using a CFDiv here (I know most people hate cf layout stuff) is because the external page has a form element that I can submit and add to data to the db without refreshing the whole parent page. This is the only way I know how to do this.
Anyways, does anyone know how to get my jquery elements to work in a CFDiv?
Thanks.
Brian
You've got more than one problem here. First, you are using <CFDiv>, which under the covers is using portions of a very old version of ExtJS. So you are likely going to run into some headaches with mixing ExtJS and jQuery (and jQuery plugins).
Second, since <CFDiv bind="..."> uses AJAX to load the external HTML window content, you would need to change your JavaScript strategy. <CFDiv> will not pull in and execute the JavaScript code (including jQuery) from the external page (trip_tab.cfm), unless you only use CF UI widgets inside that external page (then the <cfajaximport> tag handles that for you). It only loads the HTML DOM content. You will have to move any <script> and <link rel="stylesheet"> tags and custom JavaScript/jQuery code and CSS into the parent page (the page that has the <CFDiv> tag in it). Then you'll have to find a way to listen for the AJAX event (completion of loading the external page) and call the custom JavaScript/jQuery code.
As others suggested in the comments above, using <CFDiv> is only making things harder for you. If you switched to using one JavaScript library for your UI components (like jQuery/jQueryUI/jQuery plugins), and put all of the necessary code into your main page, what you desire can be accomplished fairly easily.
I found a simple work around... CFdiv creates what feels like a seperate browser window, but its not actually one. So it can't pull Javascript files in via:
<script type="text/javascript" src="/js/scripts/jquery-1.11.1.min.js"></script>
The above is telling the browser "go fetch this file" - but since your CFdiv is not really a browser (Its a controversial permutation of CFajax as described here) it doesn't do it.
Technically, the above makes the browser include it into the page, just as if you cfincluded it , or just pasted the Javascript in there.
So convert the above to:
<script type="text/javascript"><cfinclude template="/js/scripts/jquery-1.11.1.min.js"></script>
And included javascript will work! (provided there aren't any conflicts with cfajax et al)
I had a similar problem in that my jquery was not working, and doing this fixed it.

Ember.js handling jQuery location changes

Quick question.
I found handling site navigation (not the routing aprt, just a simple nav bar) with ember.js a little complex.
So I thought I will just code this aprt with jQuery, push history into location url and hope that Ember.js will detect this change and the router take action.
Scenario :
1) ember.js will use a DIV for rootElement and the navbar is declared in the body.
<body>
<div id="nav">
<ul><li><a>Item1</a></li></ul>
</div>
<div id="rootEmberApp"></div>
</body>
2) then a jQuery script will be bound to the links (item1) of the nav div and push changes to the URL but preventing default action without stopping the propgation (I didn't want to reload all the scripts). Something like :
$(document).ready(function(){
$("#navigation a").click(function(event){
App.router.location.setURL('/ember/listItems');
event.preventDefault();
});
3) I was hoping that Ember.js will fire at this time and take action.
I didn't succeed.
Is it silly ? Any idea how to do that ?
Thanks a lot.
Update 1 : thanks for the answer. Yes you're right. I was just not fully pleased with the solutions I tried or found about a nav bar. I will look again the todoMVC example and its use of the CollectionView. From a beginner point of view, the CollectionView seems a good way to describe (declare) the View and at the same times it's not easy to read (it's easier when the view is written with pure html and the js is bound to it ala jQuery).
Thanks again
This will probably not be a satisfactory answer, but... this is not the Ember Way. A core concept of Ember routing is that once the app loads, the source of truth is in Javascript. As you move through an Ember app, the router transitions from state to state and the URL is updated as a side effect. You're trying to turn that on it's head. It's not impossible -- you can definitely get what you're trying to do to work. However, I wanted you to know that it goes against the intention the designers had in mind.

One-time FancyBox popup like on Digg.com

How can I go about actioning a FancyBox popup that notifies new users of a quick sign-up button (or whatever is chosen) like on Digg.com ... and as with Digg just one time. I really have no experience with cookies but already have FancyBox running in other parts of the website, so the basis is already there. I require the popup to appear on page load. Any pointers very happily received!
My eventual solution uses the Reveal Modal plugin (click here) to trigger inline to 'fire' on page load using the modified following code for the popup to be displayed only once every three days. Remember also to load jquery.cookie.js and then add the following code:
<script type="text/javascript">
jQuery(document).ready(function(){
if (jQuery.cookie('test_status') != '1') {
jQuery('#myModal').reveal()
jQuery('#myModal').trigger('click');
jQuery.cookie('test_status', '1', { expires: 3}); }
});
</script>
Using something other than FancyBox was the answer to the original question as it seemed there was a conflict somewhere, so using Reveal made the two functions completely separate. I should also note that the .css contents from the Reveal download were added to our site's stylesheet.
Hopefully that will help someone else out.
You can find a code example here https://stackoverflow.com/a/8305703/1055987 including the link to the jQuery Cookie plugin.

Facebook JS SDK - "ga is undefined"

I am using Facebook JS SDK for integrating Like buttons in my Rails App. This sunny Monday the like buttons disappeared, and I opened Firebug to check what was going on. I found this error:
ga is undefined (line 25 of http://connect.facebook.net/en_US.all.js#xfbml=1)
So... I created an empty file not related to my Rails app, and I did something as simple as:
<html>
<body>
<script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><fb:like href="" layout="button_count" show_faces="false" width="450" font=""></fb:like>
</body>
</html>
And yes, the error is still there. Any thoughts?
I opened a ticket to Facebook, and apparently some other people were having the same problem. It seemed to be a temporary problem because now is up and running normally. I wasn't able to find the reason, and one of the Facebook employees replied when everything was running normally, so I can't give a clear answer of what was going on.
Please use <div class="fb-like"></div> instead of <fb:like></fb:like>
See http://developers.facebook.com/docs/reference/plugins/like/ and refetch the example code.
It took me a while before I noticed the change in HTML code provided by Facebook.
if you add <div id="fb-root"></div> to your page it will work again ... not sure if it's a temporary bug or a change within their API yet ... :-/
I have fix this bug (for sharrre, jquery plugin) by adding this div:
<div id="fb-root"></div>
Edit: oops I haven't seen the Hellkeeper answer's :)
Your href property is empty in the fb:like tag.

Importing HTML into TinyMCE using ColdFusion

Hey everyone, I would appreciate a pointing in the right direction with the problem I'm having. In short, I'm working on an application that will create PDFs using TinyMCE and ColdFusion 8. I have the ability to create a PDF by just entering in text, pictures, etc. However, I want to be able to import an html template and insert it into the TinyMCE .
Basically, I have a file directory code snippet that lets me browse through my 'HTMLTemplates' folder, and am able to select an HTML document. Now, I want to be able to take all the code from that selected HTML document and insert it into my TinyMCE box. Any tips on how I might do this, maybe?
Thanks!
If I understood you correctly, you already have a TinyMCE plugin which pops up a window and allows you to browse the certain directory using existing cfm page which you render within the popup window. Right?
If not, you should start with this. Not sure how easy it is done in current version, but in the older TinyMCE I've created the custom upload plugin (needed to track the site security permissions for current user) pretty quickly.
Next, I can see two quick ways to pass the server file contents to the client-side:
Make it available via HTTP so you can make the GET request and read contents into the variable.
Output it on the page using CF (say, on form submit when file selected) and grab using JavaScript.
I'd personally tried the second option. After you grab the text into the variable you can put it into the TinyMCE using it's API.
It can be as simple as output escaped text into the hidden div with known ID and read it using DOM operations (assuming that there is cfoutput around):
<div id="myTemplate">#HTMLEditFormat(myFileContents)#</div>
Also you can output the text directly into the JavaScript variable (of cource, with accurate escaping), maybe like this.
<script type="text/javascript">
var text = '#HTMLEditFormat(myFileContents)#';
</script>
Most advanced and possibly better for performance (and definitely "cooler") way is to use the concept of script tags as data containers, like this:
<script type="text/plain">
#HTMLEditFormat(myFileContents)#
</script>
Last time I've seen this in Nadel's blog, I think. Read it, pretty interesting.
Hope this helps.