This is not super relevant to my question, but it gives some background: I made a map using the MapBox API. I then wanted to implement a plugin called Leaflet-hash, which basically stores your current position in the map, in the URL hash, like so:
http://localhost/#5/12.123/60.123
So whenever you pan the map, the coordinates gets updated and the hash changes. This worked fine in a separate, clean, HTML page. But when I tried using the plugin in my Django site, it stopped working.
The plugin uses location.replace('#'+coordinates); to update the hash. For some reason, this reloads the page within the Django framework. Also, the coordinates gets added to the URL but without the hash sign. This obviously has some unwanted effects. I have no idea what causes this behavior, but I've found that:
location.replace('#') works as expected, i.e. adds the hash to the URL without reloading the page.
location.replace('#'+'randomWord') works as expected.
location.replace('#'+map.getCenter().toString()) reloads the page, with the string added to the URL, without the hash sign.
The same thing happens if I do location.replace('#'+d3.version) where D3 is a Javascript library. The page reloads.
I want to get this behavior (see the hash button): https://www.mapbox.com/mapbox.js/example/v1.0.0/toggling-ui/
Not reproducible with Django 1.7.7, django-leaflet 0.16.0 and the latest leaflet-hash.
Everything works as expected.
Related
I have implemented a Sitecore saveUI processor for moving news items to a specific location inside a year/month hierarchical structure. It does the job well, except for the fact that when used inside the Page Editor (navigating to an item's page and then trying to save, and implicitly move, the item) I am redirected to our 404 page, since Sitecore expects the original item's url to still be valid after the operation.
Is there any way to tell Sitecore that the item has been moved? I'm thinking at some property in SaveArgs, but any solution would do, as long as it's somewhat maintainable (for example, I'd prefer a server-side solution, not a client-side JavaScript-based one, if possible).
Off the top of my head, make sure your processor the last one in the pipeline and add the following code to the end of the process method:
if(Sitecore.Context.PageMode.IsPageEditor)
{
var item = args.SavedItems.First() // or perhaps Context.Item;
var url = LinkManager.GetItemUrl(item);
HttpContext.Current.Response.Redirect(url);
}
Have you tried using the Sitecore Newsmover Module?
This works seamlessly and could be the way to go instead of creating custom movers. We have used this plenty of times and it does seem to work well in all conditions.
Sample config for this:
<template id="User Defined/News Article" sort="Descending">
<DateField>Posted Date</DateField>
<YearTemplate formatString="yyyy">User Defined/Folders/Article Year Folder</YearTemplate>
<MonthTemplate formatString="MMMM">User Defined/Folders/Article Month Folder</MonthTemplate>
</template>
Right now I am using one webview to show data from my aplicationDatadirectory, here everything is working fine, I get content when user click next back respectively. Now what I am doing is in onload of webview I register "touchevent" and "touchmove" in webview's html like this :-
$.webview.evalJS('document.getElementsByTagName("body")[0].addEventListener("touchstart", function mytouch(){Ti.App.fireEvent("touch", {X:event.touches[0].pageX,Y:event.touches[0].pageY,length:event.touches.length});}, false);');
$.webview.evalJS('document.getElementsByTagName("body")[0].addEventListener("touchmove", function mymove(){Ti.App.fireEvent("move", {X:event.touches[0].pageX,Y:event.touches[0].pageY,length:event.touches.length});}, false);');
on the basis of this I find swipe event. I get correct html in webview(I can see images). But I am unable to get touchstart and move call. I dont know what is the problem here. I set data in webview using url here.
Now when I set data in webview using html(I used data of my html file(given below) in one var) now I am unable to see images it just shows me one black border(empty) but here my touchstart and touchmove events are firing also my swipe is also working as expected. I am checking this functionality in iPhone.
Can any one find the issue what is going wrong here? Thanks.
I think that this depends on the time when you apply
$.webview.evalJS('document.getElementsByTagName("body")[0].addEventListener("touchstart", function mytouch(){Ti.App.fireEvent("touch", {X:event.touches[0].pageX,Y:event.touches[0].pageY,length:event.touches.length});}, false);');
$.webview.evalJS('document.getElementsByTagName("body")[0].addEventListener("touchmove", function mymove(){Ti.App.fireEvent("move", {X:event.touches[0].pageX,Y:event.touches[0].pageY,length:event.touches.length});}, false);');
If you use the html property data is loaded immediately and you can use the code exactly after setting html content. If you use the url (even if it is located locally, which might be difficult for android) then you need to wait a short time until the page is loaded. There is also an event listener for that (web view-event load) but i can't say if that works for local resources but i don't think so.
In this case you should apply your javascript snippet into your html resources (if they are locally) instead of manually adding it using evalJS.
Please note that there is an issue on android that you can't use local images (resources folder) in your webview when you provide the content via html property.
I made it swipe working in iOS(in android it was working).
I did not expect this thing to be a reason but I do not know logic behind it. I was accessing .xhtml files from application data directory and it was working without any issue in android but in iOS it was not.
I just change(rename in my code) .xhtml file to .html and now it is working. :)
Hope this can help someone who is looking for the same.(or just for his interest)
Thanks.
I'm putting together a website, where one of the pages holds an interactive map. The map is implemented as a big table, where each node is a td.
Now this map takes a while to render, and so, I'd love for the site to be displayed as it renders, so that even if the map is not fully rendered, the user can click links or the part of the map that is rendered.
Is there an easy way to do this? AJAX is one option, but since it is a Django website and the map depends on data from the Django template, AJAX becomes a bit unwieldy.
So is there a way to make the page visible while rendering?
(I considered making each node an iframe, so that they would be rendered individually, but that seems a bit silly too)
the django template should only render an empty map (or a map holding the first 10 points) with the javascript code firing on page ready
this javascript script should do this:
request 10 nodes from django (using a different url/view)
render the fetched nodes into the page
if no more nodes: END
goto 1.
Hope this helps
After trying a few different things, it seems that the problem was too many database queries. Each of the nodes made calls to the database while rendering, which caused them to be very slow.
For reference:
Custom filters in Django should not make database queries, if they are used heavily on a page
I am using play framework 2.0 .I a page where I list all the elements that the user can edit/delete. one of the listed elements in a look up from another table. I have coded a select in the forms and that works fine.
I would like to include the combo box in the displayed list, so the user can update it right there without having to drill down into each element to update the field. Is there a way to do this? I want to listen to the change in the combobox and update the underlying model.
I tried a few iterations, but the select box seems to want a play.api.data.Field , and not the value I provide.
the parameters to the page is a pageable list like this
#(currentPage: Page[Deal], currentSortBy: String, currentOrder: String, currentFilter: String)
I don't know if I understand the issue, but I think the problem you are stating would be better solved at the client, with some ajax in it...
otherwise, you would be issuing a whole page refresh every time the user updates the items
I would expose the pageable list like a rest-json web service, and I wuld call it from javascript, binding the on-change event...
Here you have an example using select2 to do the lookup and consumign a rest web service: http://bb-jugar.rhcloud.com/assets/js/tmp/select2/demo.html
That's my first question in here, I've been looking through old questions, but nothing matched with my problem. Here it is.
I'm creating some site with one main functionality. We want this site to display content of other sites, but in a specific way. User chooses let's say two pages from five and want to see their content. He clicks button 'Display' and goes to next page where he finds let's say view from web cam, and here comes problem.
I want to cache image that is hidden behind the url from which image was downloaded, so after refresh image won't be downloaded again, but browser will get it from cache.
I've been looking through documentation of Django, but nothing seemed to be useful.
I know that I should:
1) create table which stores cache
2) add to settings.py some CACHE_BACKEND = ...
3) use #cache_page(300) before declaration of function which returns content which should be cached,
but... it doesn't seem to work.
I will be greateful if someone tells how to solve that problem, maybe with some sort of code showing the mechanism.
Cheers,
Chris.
I think that right way to do this will be to store image somewhere on your server and delete it later with cron or something similar.
Django cache framework wasn't created for the purpose you are trying to use it.