hey
hey
- <!doctype html>
- <html>
- <head>
- <meta charset=utf-8/>
- <title>Custom Event</title>
- <style>
- body{width:600px;margin: auto;font-family: sans-serif;text-align: center;}
- li {text-align: left;padding-bottom: 1em; }
- </style>
- </head>
- <body>
- <h2>What Are You Interested In?</h2>
- <form action="#">
- <p><input type="text" name="q" id="q"></p>
- </from>
- <ul class="tweets"></ul>
- <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
- <script>
- (function($){
- var obj = $( {} );
- $.each({
- on:'subscribe',
- trigger:'publish',
- off:'unsubscribe'
- }, function( key,api ){
- $[api] = function() {
- obj[key].apply ( obj, argruments );
- }
- });
- })(jQuery);
- (function($){
- var Twitter = {
- init: function() {
- this.template = '<li>{{tweet}}</li>';
- this.query = '@tutspremium';
- this.tweets = [];
- this.timer;
- this.cache();
- this.bindEvents();
- this.subscriptions();
- this.searchInput.val( this.query );
- $.publish('twitter/query');
- return this;
- },
- cache: function() {
- this.container = $('ul.tweets');
- this.searchInput = $('#q');
- },
- bindEvents: function () {
- this.searchInput.on( 'keyup',this.search );
- },
- subscriptions:function() {
- $.subscribe('twitter/query',this.fetchJSON );
- $.subscribe('twitter/query',this.renderResults);
- },
- search: function() {
- var self = Twitter,
- input = this;
- clearTimeout( self.timer);
- self.timer = (input.value.length>=3)&& setTimeout(function(){
- self.query = input.value;
- $.publish('twitter/query');
- },400);/* it calls user time*/
- },
- renderResults: function() {
- var self = Twitter,
- frag = [],
- tweet;
- self.container.html(
- $.map( self.tweets, function( obj, index ) {
- var t =
- obj.text.replace(/(http:[^\s]+)/,'<a href="$1"></a>')
- .replace(/@([^\s]+)/,'<a href="http://twitter.com/$1">@$1</a>');
- return self.template.replace(/{{tweet}}/, t)
- }). join('')/* its updates the url*/
-
- window.Twitter = Twitter.init();
- })(jQuery);
- </script>
- </body>
- </html>
error: