can widgets be cached? - caching

Is there a way to cache widgets. For example if you place your widgets on high volume websites then each time when someone access that site, a call will be made to your server to get the widget code. This way my server can get too much overloaded just to display the widget . Can I cache the widget HTML code and place it on some server like Akamai. Any suggestions or tips highly appreciated.
Thanks in advance.

You sure could, but you'd need to be able to get at the widgets somehow. I've found much higher performance (faster response, faster downloads) from EdgeCast vs. Akamai, also.
Say, for instance, you've got the code for a form at http://cdn.mysite.com/form1.html and a user clicks on a link that would bring up that form.
Use something like this as a script:
$(document).ready( function() {
$(".widget .trigger").click( function() {
url = $(this).attr("rel");
$(this).parents(".widget").load(url, function () {
// Do what needs to be done to the widget code here
// Example: make it an AJAX form.
});
});
});
And then have this Markup:
<div class="widget">
Widget Trigger
</div>
And have this on your CDN:
<form action="/ajax/hander/" method="POST">
<fieldset>
<legend>This is a pretty cool form</legend>
<label for="form1input1">Make this cool:</label>
<input id="form3input1" name="something" type="text" />
<input type="submit" value="Coolify" />
</fieldset>
</form>
You could then have some code server side that uploads snippets to your CDN, saves their URL in a database, and generates the links with the appropriate rel tag by pulling that value from something fast like Memcached. That part will vary greatly based on your language of choice.

Related

How do I hide a field given a checked box?

I am trying to create a dynamic query page. I am more than happy to learn ruby on rails which is what I am currently doing. However there is a time constraint for this and I have been searching high and low on how to hide a field on a form if a checkbox is checked. I have next to nothing ruby skills and I cant change to another language. Any assistance would be greatly GREATLY appreciated. Also if you know a good tutorial for doing query pages would help!!!
For a form like:
<form ...>
<input id="hide-box" type="checkbox" />
<input id="field-to-hide" />
</form>
You'll need to use something like JQuery to listen for checking and hide accordingly.
$('#hide-box').on('change', function() {
$('#field-to-hide').toggle($(this).prop('checked'));
});

Where has an image been dropped with fineuploader?

Is it possible to know where an image has been dropped?
Assume we have a checkerboard with different divs
<div id="jquery-wrapped-fine-uploader"></div>
<div id="checkerboard">
<div id="A1" class="ffup"></div>
<div id="A2" class="ffup"></div>
<div id="A3" class="ffup"></div>
<div id="A4" class="ffup"></div>
......
</div>
<script>
$(document).ready(function () {
$('#jquery-wrapped-fine-uploader').fineUploader({
request: {
endpoint: 'endpoint.php'
},
dragAndDrop: {
extraDropzones: [$('.ffup')]
}
});
});
</script>
First of all, your code will only designate the first ffup div (A1) as it currently stands. You will need to pass a selector for each individual drop zone into your extraDropzones array. The jQuery wrapper will only pass the first element covered by your jQuery selector to the library. Ideally, it would pass along all items represented by the selector, but, to do this, it would have to be aware of the intended type of the parameter. The jQuery wrapper must convert all jQuery objects to HTMLElements before passing the data on to Fine Uploader's core code (which is not aware of jQuery). This is something I'd like to look into more in the future, but this is the way it has worked since 3.0. Note that this limitation does NOT apply to the target of a Fine Uploader plug-in instance, i.e. $(".myTarget").fineUploader(...).
As to your question, Fine Uploader does not currently pass any information along to callbacks that would allow you to determine which drop zone received an associated file. This is an interesting feature, and I can see how it may be useful. Please open up a feature request in the issue tracker so we can discuss and prioritize this for a future release.

How to store to browser auto-complete/auto-fill when using AJAX calls

I've noticed that browsers do not store form values until the form is submitted, which means that if you're using AJAX instead of a standard form submit, your browser's auto-fill is never populated. Is there a way to force populate your browsers auto-fill/auto-complete so that I can have this convenience with forms that are submitted via AJAX? It's annoying to go to my AJAX page and have to type in the same things in the form fields every time because the browser doesn't remember them.
My question is pretty much identical to the this one, except that only a work around in FireFox is provided as the accepted answer to that question. I'm looking for a solution that works in all major browsers (at least Chrome, FF, and IE), if there is one.
Note: I am not talking about AJAX auto-complete plugins, which is what almost always pops up when googling this question. I am talking about your browser's built-in auto-complete or auto-fill that helps you fill out forms by remembering what you entered in the past.
For anyone who's still trying to solve this, seem like I've found the answer.
Chromium tries to recognize the submit event, even if you preventDefault and handle the actual submission yourself.
That's it, you need to preventDefault the submit event, not the click event.
This worked on Chrome, Edge and IE 11 at the time of writing (I'm too lazy to download and test it on Firefox).
Here's your form:
<form method="POST" id="my-form">
<label>Email</label>
<input autocomplete="email" type="email" name="email">
<button type="submit">Subscribe</button>
</form>
Notice the autocomplete attribute. These are all the possible values that you can use for autocomplete.
In JavaScript, simply do this:
$("#my-form").on("submit", function (ev) {
ev.preventDefault();
// Do AJAX stuff here
});
The browser will remember whatever email you've entered on clicking subscribe button.
I have also come across this; there doesn't seem to be a great solution, certainly not a cross browser one, but here is one for IE I haven't seen anyone mention:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<SCRIPT>
function subForm()
{
window.external.AutoCompleteSaveForm(f1);
f1.submit();
}
</script>
</HEAD>
<BODY>
<FORM id=f1>
User ID : <input type=text name=id></input><br>
Password :<input type=password name=pw></input><br>
E-mail :<input type = text VCARD_NAME = "vCard.Email"> <br>
<input type=button value=submit onclick="subForm()">
</FORM>
</BODY>
</HTML>
From: http://support.microsoft.com/kb/329156
Use this Method:
AutoCompleteSaveForm = function(form){
var iframe = document.createElement('iframe');
iframe.name = 'uniqu_asdfaf';
iframe.style.cssText = 'position:absolute; height:1px; top:-100px; left:-100px';
document.body.appendChild(iframe);
var oldTarget = form.target;
var oldAction = form.action;
form.target = 'uniqu_asdfaf';
form.action = '/favicon.ico';
form.submit();
setTimeout(function(){
form.target = oldTarget;
form.action = oldAction;
document.body.removeChild(iframe);
});
}
Tested with ie10, ff latest, chrome latest
Test yourself: http://jsbin.com/abuhICu/1
Have you try the answer of my question that you mention?
The answer is using hidden iframe but seems he claim the idea is not working on IE and Chrome on that time.
Try to take the idea, and instead of using hidden iframe, just put the username/password/submit visible input element in a form POST, in an iframe. So user will enter login details directly into iframe. With proper Javascript you can put loading image, get success or denied from server and update the parent or the whole page. I believe it should work on any browser.
Or if you still want to use AJAX since you probably implemented the API on server side. You can make the iframe to just send a dummy POST at the same time send the real user/pass to AJAX URL.
Or back to use hidden iframe, not to hide it but move it to the invisible area like top: -1000px.
After several hours searching, I found a solution at Trigger autocomplete without submitting a form.
Basically, it uses a hidden iframe in the same page, set the action of your form to the 'src' of the iframe, and add a hidden submit button inside the form, when user clicks your button which triggers AJAX requests, you should programmatically click the hidden button before sending the AJAX request. see example below:
In your form page:
<iframe id="hidden_iframe" name="hidden_iframe" class="hidden" src="/content/blank"></iframe>
<form target="hidden_iframe" method="post" action="/content/blank" class="form-horizontal">
<input type="text" name="name">
<input type="text" name="age">
....
<button id="submit_button" type="submit" class="hidden"></button>
<button id="go_button" type="submit" class="hidden">Go</button>
</form>
Then java script:
$('#go_button').click(function(event){
//submit the form to the hidden iframe
$('#submit_button').click();
//do your business here
$.ajax(function(){
//whatever you want here
}})
);
Hope this helps.

jQTouch AJAX Form Callback

I've got a simple AJAX POST form set up in a jQTouch application. We're talking out-of-the-box simple here:
<form id="contact" class="topPage" method="post" action="/process/mobile-submit.cfm">
<!-- Various form guts go here -->
</form>
And this works just great. My users punch in their info, my server-side script does its job and gobbles up the lead data and spits back an out-of-the-box simple response.
<div>
<div class="toolbar">
Back
</div>
<div class="info">
<strong>Thank You For Your Submission</strong><br />
We have received your inquiry, and blah blah blah jibber jabber.
</div>
</div>
Everyone's happy... except those of us who are trying to track the conversion in Google Analytics. Now, I've got virtual pageviews set up on each panel in this application using the pageAnimationEnd event, which is easy as pie when you know what selectors those are going to be attached to in advance, but when jQTouch creates a new segment from the form return, it has a generic serialized ID like #page-N.
I've tried adding a loose script block into the form return. That works fine for Firefox on my desktop, not so much for Safari on my phone.
Since I've allowed jQTouch to handle the AJAX particulars for me in this instance, is there a straightforward way to attach a success handler to it? Or am I better off trying to bind a pageAnimationEnd handler on $('[id^=page-]') and hope the business doesn't want me to do anything else with ad hoc form returns until we replace this app with one written in jQuery Mobile?
Worked it out.
The return fragment can declare its own ID, naturally, and jQTouch will then treat it as though it were an original part of the document. I had previously assumed jQTouch didn't give a toss about what attributes I gave the fragment; I was wrong.
This means that you could goTo it like any other portion of the document. It also means that you can bind a pageAnimationEnd handler on the return fragment either by ID or by class name and it will behave as expected. Thus:
<div class="formResult">
<div class="toolbar">
Back
</div>
<div class="info">
<strong>Thank You For Your Submission</strong><br />
We have received your inquiry, and blah blah blah jibber jabber.
</div>
And:
$('.formReturn').live('pageAnimationEnd', function(evt, info) {
if (info.direction == 'in') {
// Goal completion code
} else {
$(this).remove();
}
});

Form action submit but NOT redirect (facebook static + magento)

This seems simple enough but there are complications...
I have a facebook FBML static page where I want users to sign up to my magento newsletter.
I think I'm right in saying typically you can put the form code as below into the fbml page and on submit it will add the user to the newsletter;
<form action="http://my-site.com/newsletter/subscriber/new/" method="post" id="newsletter-validate-detail">
<fieldset class="block-content">
<legend>Newsletter</legend>
<label id="newsletter-label" for="newsletter" class="left">Join our mailing list</label>
<div class="input-box left">
<input name="email" type="text" id="newsletter" class="input-text required-entry validate-email" />
</div>
<button id="newsletter-submit" type="submit" class="button btn-submit"><span>Join</span></button>
</fieldset>
</form>
But of course at my site I have an ajax function that returns a thanks for registering, so when this submit is sent from fb, this just lands me at a confirmation message on my domain that is supposed to feed through java and say thanks very much for signing up.
So what I need is some way of posting the action, but keeping the user on facebook, or at least leaving them at some other landing page after the action.
Something that posts but doesn't redirect, or something that posts then redirects to something other than the url in the form action?
Not sure if I need ajax for this or if js is even allowed within the fb environment, could I use any of their proprietary FBML to achieve this?
Many thanks
Could you add onSubmit="handleData(); return false;" to your form so it doesn't submit? and use the handleData() function to proccess the data in whatever way you need? This will keep the user from moving off the current page.

Resources