Created
March 3, 2013 07:44
-
-
Save thinkphp/5075226 to your computer and use it in GitHub Desktop.
Instagram Search based on CUI2 AMD Style, but with Keydown method to the Element.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require(["cui","dom","event","ajax"], function(cui, dom, event, ajaxobj){ | |
| var sfield = dom.select("#s"), | |
| container = dom.select("#photos"), | |
| timer; | |
| function instaSearch() { | |
| dom.addClass(sfield, "loading") | |
| var q = dom.select("#s").value | |
| var url = "proxy.php?q=" + q; | |
| ajaxobj.ajax("GET", url, function( data ){ | |
| //eval JSON received from proxy.php | |
| data = eval("(" + data + ")"); | |
| //remove the loading | |
| dom.removeClass(sfield, "loading"); | |
| //define an empty variable | |
| var output = ''; | |
| //for each object execute | |
| dom.each(data, function(item, i) { | |
| output += '<div class="p"><a href="'+data[i].src+'" class="fullsize" target="_blank"><img src="full-image.png" alt="fullsize"></a> <a href="'+data[i].url+'" target="_blank"><img src="'+data[i].thumb+'"></a></div>'; | |
| }); | |
| //insert the result to the container | |
| container.html( output ); | |
| }) | |
| } | |
| /** | |
| * keycode glossary | |
| * 32 = SPACE | |
| * 188 = COMMA | |
| * 189 = DASH | |
| * 190 = PERIOD | |
| * 191 = BACKSLASH | |
| * 13 = ENTER | |
| * 219 = LEFT BRACKET | |
| * 220 = FORWARD SLASH | |
| * 221 = RIGHT BRACKET | |
| */ | |
| sfield.Keydown( function( e ){ | |
| if(e.keyCode == '32' || e.keyCode == '188' || e.keyCode == '189' || e.keyCode == '13' || e.keyCode == '190' || e.keyCode == '219' || e.keyCode == '221' || e.keyCode == '191' || e.keyCode == '220') { | |
| e.preventDefault(); | |
| } else { | |
| clearTimeout(timer); | |
| timer = setTimeout(function() { | |
| instaSearch(); | |
| }, 900); | |
| } | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment