Django Endless Pagination somehow blocking my custom javascript - django

I am using the twitter style endless pagination for one of my projects. the problem is that my ajax logic works just fine for my first 10 posts (so the first page) but when I go down and Endless Pagination loads more posts, my ajax stops working for them. I am not sure my.
Thats how I've been stacking my js
<script src="/site_media/endless_pagination/endless.js" type="text/javascript" charset="utf-8"></script>
<script src="/site_media/endless_pagination/endless_on_scroll.js" type="text/javascript" charset="utf-8"></script>
<script src="/site_media/bootstrap/js/bootstrap.min.js"></script>
<script src="http:/site_media/bootstrap/js/bootstrap-collapse.js"></script>
<script src="site_media/bootstrap/js/bootstrap-tooltip.js"></script>
so for example tooltip works just fine for my first 10 posts, but then when pagination loads the next posts, tooltip doesn't seem to work for them.

I finally figured out what the problem was, I was suposed to use .live(). This Attaches an event handler for all elements which match the current selector, now and in the future. So when new posts load, my jQuery logic applies to them as well.

Related

Ractive / Moustache Template for Head Tag

I have been searching for this all over, but can not find an answer or example.
Can a Ractive template be used to construct head elements that are consistant across pages, and can that be loaded from a separate file?
For example: all html, head, and title tag info is loaded via a referencable template from an external file into an index page.
+html+
+head+
+title+
+/title+
+/head+
And if so, how do you do it? As I try to wrap my head around it, jquery and ractive.js would need to load. Is there a different/better solution?
It is possible. But it's not practical and it raises other issues.
Here's a basic implementation that shows how <head> can be templated but without concentrating on putting the template in an external file. This works for me in Chrome and IE.
<html>
<head id="output"></head>
<script id="template" type="text/html">
<title>{{ title }}</title>
</script>
<script type="text/javascript" src="ractive.min.js"></script>
<script type="text/javascript">
var ractive = new Ractive({
template: "#template",
el: "#output",
data: {
title: "This is the title"
}
});
</script>
<body>
...
</body>
</html>
You'll run into problems with this approach because the head elements won't be loaded until after the page has loaded and Ractive kicks in. This may cause the following problems:
Search engines might not be able to read the page title and meta tags
Any javascript you need to load into <head> may not work (I tried some simple examples and was able to get the javascript to run but it failed to reference any elements in the body. Maybe it's a context issue and maybe Ractive has support to overcome this but this is an area I'm unfamiliar with.)
If you require valid HTML, this probably won't work for you because script tags can't be direct children of <html>, and <head> is supposed to have <title> as a direct child.
You're better off using a server-side solution to template <head>.

Access text in dynamic script with Ember using Protractor

How can I access the text "All changes saved" in the dynamically created Ember script below? I use Protractor to create functional test.
<div class="is-muted">
<script id="metamorph-191-start" type="text/x-placeholder"></script>
<script id="metamorph-191-start" type="text/x-placeholder"></script>
All changes saved
<script id="metamorph-191-end" type="text/x-placeholder"></script>
</div>
Thank you in advance for your help!
I ran into a similar issue earlier and solved it in a rather unelegant manner but it does the job, try the following:
//$$('#metamorph-191-start') will select all the elements on your page with ID metamorph-191-start
//.get(1) will get the second element that passes this requirement aka the script with your text 'all changes saved' in it.
//the .getText().then(function(foo)... gets the text from the element and resolves the promise around it.
$$('#metamorph-191-start').get(1).getText().then(function(foo){
console.log(foo);
});
I said this was unelegant since it is quite the bad practice to use the same ID more than once on a single HTML page.

Phileo Django Liking App

I have followed the instructions here Phileo Docs and I added my model to the LIKABLE_MODELS, I added a widget in my template but it is not working. In the admin the Phileo table Like is also emplty. When I press the like button i am redirected to this page http://localhost:8000/likes/like/19:1/ but nothing happens and the count ofcourse stays the same. When I add a like from the admin it does appear on the template but it doesn't work vice verse.
Has anyone faced a similar problem or anyn idea how to fix this?
This is what was missing.
From the docs
{% load staticfiles %}
<script src="{% static "js/eldarion-ajax.min.js" %}"></script>
This of course is optional. You can roll your own javascript handling
as the view also returns data in addition to rendered HTML.
Furthermore, if you don’t want ajax at all the view will handle a
regular POST and perform a redirect.

Foundation 5: Dropdown content not working

I am trying content dropdown from Foundation 5: http://foundation.zurb.com/docs/components/dropdown.html, but it does not work as you can see on this fiddle: http://jsfiddle.net/AQGd9/2/. Basically, the content does not appear upon clicking the link when it should.
Has Content Dropdown
<ul id="drop2" class="f-dropdown content" data-dropdown-content>
<li>This is a link</li>
<li>This is another</li>
<li>Yet another</li>
</ul>
Thanks
You need to explicitly initialize foundation with this piece of code before the end of your body, like this:
<body>
...
<script>
$(document).foundation();
</script>
</body>
I have the same problem right now. The doc says that you need include the javascript required files, there are two ways to do it:
1) All Js (core + plugins): foundation.min.js
2) Only the core, and add the plugins on demand: foundation.js + foundation.dropdown.js (in this case).
So, launch foundation Js:
$(document).foundation();
Source: Foundation 5 Js Doc
This work for me.

Django debug console shows double GET for a single page request

I'm running the developer's Django server while writing a simple view and it seems whenever I request a page, the console shows that there are 2 GETs for the same URL. What would cause this happen? I'm not using any redirects, so I don't see how a 2nd request would be made?
EDIT: It appears to be caused by the template. Changing to a blank html file for a template resolved the issue. The question is why? I have multiple {% if %} {% endif %} sections, with no elses. Could that be an issue?
It also could be Firefox following a WC3 directive under which it's supposed to dual load if certain tags come empty or broken, for example, a without a src="" etc. That being said, I saved off the rendered HTML on receipt and moved it into a static file, where I added the same headers as the real checkout and a small DB log of all accesses.
I just stumble upon this problem and fixed it removing my img wit src=""
Please confirm, if Django is redirecting after appending slash to your url. Its the property APPEND_SLASH in your settings.py controls that.
The second request is probably caused by a mis-configured asset link - a script, style or img tag which is empty or omits the initial / and is therefore re-requesting the page.
It could be your shortcut/favicon
Do you have link rel="shortcut icon" in your page template? Comment it out to see if it removes the second request
In my case : I have the same javascript code in 2 files : one in the base template and the same one in another template. As I use ajax to not reload all the page I got the call 2x, then 4x, and 8x, ...
The solution is the use the javascript code only in mybase.html
Hereafter my js code :
<script type="text/javascript">
// Code jQuery Ici
$(document).ready(function(){
// GET
$(".ajax_onglet_get").click(function(e){
var lien = $(this).attr('href');
$('#zone_travail').fadeOut('fast', function(){
$('#zone_travail').load(lien, function() {
$('#zone_travail').fadeIn('fast');
});
});
e.preventDefault()
});
});