You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I tried to test the code for the http://learn.jquery.com/events/introduction-to-custom-events/ page but I get the error message in the console "Uncaught SyntaxError: Unexpected identifier" at line 124 below ($( "#twitter" ).on( "getResults", function( e, term ) {).
Did I do something wrong or is the code wrong?
<html><head><metacharset="utf-8"><title>Testing jQuery</title><linkrel="stylesheet" href="//code.jquery.com/ui/1.11.0/themes/smoothness/jquery-ui.css"><scriptsrc="//code.jquery.com/jquery-1.10.2.js"></script><scriptsrc="//code.jquery.com/ui/1.11.0/jquery-ui.js"></script><style>
.on { background-color: yellow; }
.off { background-color: black; color: grey; }
</style><script>$(document).ready(function(){$("form").submit(function(event){varterm=$("#search_term").val();$("#twitter").trigger("getResults",[term]);event.preventDefault();});$.fn.twitterResult=function(settings){returnthis.each(function(){varresults=$(this);varactions=$.fn.twitterResult.actions=$.fn.twitterResult.actions||$.fn.twitterResult.createActions();vara=actions.clone().prependTo(results);varterm=settings.term;results.find("span.search_term").text(term);$.each(["refresh","populate","remove","collapse","expand"],function(i,ev){results.on(ev,{term: term},$.fn.twitterResult.events[ev]);});// use the class of each action to figure out// which event it will trigger on the results panela.find("li").click(function(){// pass the li that was clicked to the function// so it can be manipulated if neededresults.trigger($(this).attr("class"),[$(this)]);});});};$.fn.twitterResult.createActions=function(){return$("<ul class='actions' />").append("<li class='refresh'>Refresh</li>"+"<li class='remove'>Remove</li>"+"<li class='collapse'>Collapse</li>");};$.fn.twitterResult.events={refresh: function(e){// indicate that the results are refreshingvarelem=$(this).addClass("refreshing");elem.find("p.tweet").remove();results.append("<p class='loading'>Loading...</p>");// get the twitter data using jsonp$.getJSON("http://search.twitter.com/search.json?q="+escape(e.data.term)+"&rpp=5&callback=?",function(json){elem.trigger("populate",[json]);});},populate: function(e,json){varresults=json.results;varelem=$(this);elem.find("p.loading").remove();$.each(results,function(i,result){vartweet="<p class='tweet'>"+"<a href='http://twitter.com/"+result.from_user+"'>"+result.from_user+"</a>: "+result.text+" <span class='date'>"+result.created_at+"</span>"+"</p>";elem.append(tweet);});// indicate that the results are done refreshingelem.removeClass("refreshing");},remove: function(e,force){if(!force&&!confirm("Remove panel for term "+e.data.term+"?")){return;}$(this).remove();// indicate that we no longer have a panel for the termsearch_terms[e.data.term]=0;},collapse: function(e){$(this).find("li.collapse").removeClass("collapse").addClass("expand").text("Expand");$(this).addClass("collapsed");},expand: function(e){$(this).find("li.expand").removeClass("expand").addClass("collapse").text("Collapse");$(this).removeClass("collapsed");}$("#twitter").on("getResults",function(e,term){// make sure we don't have a box for this term alreadyif(!search_terms[term]){varelem=$(this);vartemplate=elem.find("div.template");// make a copy of the template div// and insert it as the first results boxresults=template.clone().removeClass("template").insertBefore(elem.find("div:first")).twitterResult({"term": term});// load the content using the "refresh"// custom event that we bound to the results containerresults.trigger("refresh");search_terms[term]=1;}}).on("getTrends",function(e){varelem=$(this);$.getJSON("http://search.twitter.com/trends.json?callback=?",function(json){vartrends=json.trends;$.each(trends,function(i,trend){elem.trigger("getResults",[trend.name]);});});});$("#get_trends").click(function(){$("#twitter").trigger("getTrends");});$.each(["refresh","expand","collapse"],function(i,ev){$("#"+ev).click(function(e){$("#twitter div.results").trigger(ev);});});$("#remove").click(function(e){if(confirm("Remove all results?")){$("#twitter div.results").trigger("remove",[true]);}});};});</script></head><body><h1>Twitter Search</h1><inputtype="button" id="get_trends" value="Load Trending Terms" /><form><inputtype="text" class="input_text" id="search_term" /><inputtype="submit" class="input_submit" value="Add Search Term" /></form><divid="twitter"><divclass="template results"><h2>Search Results for
<spanclass="search_term"></span></h2></div></div></html>
The text was updated successfully, but these errors were encountered:
githubshrek
changed the title
Uncaugt SyntaxError: Unexpected identifier
Uncaught SyntaxError: Unexpected identifier
Jul 22, 2014
I tried to test the code for the http://learn.jquery.com/events/introduction-to-custom-events/ page but I get the error message in the console "Uncaught SyntaxError: Unexpected identifier" at line 124 below ($( "#twitter" ).on( "getResults", function( e, term ) {).
Did I do something wrong or is the code wrong?
The text was updated successfully, but these errors were encountered: