Execute
Save
Share
Share link
share
share
share
Team
Public Teams
Comments
0
Created By:
Guest
Title:
Title
Description
Edit
Copy Link
Login
Email *
Password *
Login
OR
Create Account
Screen Name *
Email *
Password *
Retype Password *
Team Access Code
Register
Public CodeBins
HELP
--Select Theme--
Ambiance
Blackboard
Cobalt
Eclipse
Elegant
Erlang-Dark
Lesser-Dark
Monokai
Neat
Night
Rubyblue
Vibrant-Ink
Xq-Dark
New CodeBin
CodeBins Versions
06/26/2017- V.3
06/26/2017- V.2
06/26/2017- V.1
Compare Versions
Recent CodeBins
View All CodeBins
/* * NOTE: This file generates fake tweet data, and is not intended to be part of your implementation. * You can safely leave this file untouched, and confine your changes to index.html. */ // set up data structures window.streams = {}; streams.home = []; streams.users = {}; streams.users.shawndrost = []; streams.users.sharksforcheap = []; streams.users.mracus = []; streams.users.douglascalhoun = []; window.users = Object.keys(streams.users); // utility function for adding tweets to our data structures var addTweet = function(newTweet) { var username = newTweet.user; streams.users[username].push(newTweet); streams.home.push(newTweet); }; // utility function var randomElement = function(array) { var randomIndex = Math.floor(Math.random() * array.length); return array[randomIndex]; }; // random tweet generator var opening = ['just', '', '', '', '', 'ask me how i', 'completely', 'nearly', 'productively', 'efficiently', 'last night i', 'the president', 'that wizard', 'a ninja', 'a seedy old man']; var verbs = ['downloaded', 'interfaced', 'deployed', 'developed', 'built', 'invented', 'experienced', 'navigated', 'aided', 'enjoyed', 'engineered', 'installed', 'debugged', 'delegated', 'automated', 'formulated', 'systematized', 'overhauled', 'computed']; var objects = ['my', 'your', 'the', 'a', 'my', 'an entire', 'this', 'that', 'the', 'the big', 'a new form of']; var nouns = ['cat', 'koolaid', 'system', 'city', 'worm', 'cloud', 'potato', 'money', 'way of life', 'belief system', 'security system', 'bad decision', 'future', 'life', 'pony', 'mind']; var tags = ['#techlife', '#burningman', '#sf', 'but only i know how', 'for real', '#sxsw', '#ballin', '#omg', '#yolo', '#magic', '', '', '', '']; var randomMessage = function() { return [randomElement(opening), randomElement(verbs), randomElement(objects), randomElement(nouns), randomElement(tags)].join(' '); }; // generate random tweets on a random schedule var generateRandomTweet = function() { var tweet = {}; tweet.user = randomElement(users); tweet.message = randomMessage(); tweet.created_at = new Date(); addTweet(tweet); }; for (var i = 0; i < 100; i++) { generateRandomTweet(); } var scheduleNextTweet = function() { generateRandomTweet(); setTimeout(scheduleNextTweet, Math.random() * 1500); }; scheduleNextTweet(); // utility function for letting students add "write a tweet" functionality // (note: not used by the rest of this file.) var writeTweet = function(message) { if (!visitor) { throw new Error('set the global visitor property!'); } var tweet = {}; tweet.user = visitor; tweet.message = message; addTweet(tweet); };
Bottom of Page
In Head
On Load
On Ready
Setting
Validate
Copy
Format
body { background-color: #87CEFA; } h1{ font-family: cursive; text-align: center; background-color: white; font-size: 60px; } #tweetList{ height: 700px; width: 1150px; border-style: solid; border-width: 10px; font-size: 20px; background-color: white; /*overflow:hidden; */ } #eachTweet{ color: blue; } button { background-color: #00008B; border: none; color: white; padding: 15px 20px; text-align: center; text-decoration: none; display: inline-block; font-size: 20px; font-family: cursive; } img{ width: 6%; height: 6%; } button.user { color: blue; background:none; border:none; }
Setting
Validate
Copy
Format
<!DOCTYPE html> <html> <head> <script src="jquery.js"></script> <script src="data_generator.js"></script> <link rel="stylesheet" href="stylesheet.css"> </head> <body> <h1><img src="http://vignette4.wikia.nocookie.net/pokemon/images/c/c5/144Articuno_OS_anime_2.png/revision/latest?cb=20150609035010">Twittler</h1> <div id='tweetList'></div> <button class='generator'>Generate a new Tweet</button> <script> $(document).ready(function(){ var tweetList = $('#tweetList'); tweetList.html(''); var count = 0; var index = streams.home.length - 1; //index of 9 (10 -1) var initialTweet = 10; while(initialTweet >= 0){ //initialize the first 10 tweets var tweet = streams.home[index]; //the tweet object at that array index var $tweet = $("<div id='eachTweet'><button class='user'></button><span id='info'></span></div>"); //jquery object to store the text $tweet.find('.user').text(count + '@' + tweet.user + ':') $tweet.find('#info').text(tweet.message + ' ' + tweet.created_at); //gives the tweet variable this text $tweet.appendTo(tweetList); //places the text just after the body initialTweet --; count++; index--; } $(".generator").on("click", function(){ var indx = streams.home.length - 1; var aTweet = streams.home[indx]; var $aTweet = $("<div id='eachTweet'><button class='user'></button><span id='info'></span></div>"); $aTweet.find('.user').text(count + '@' + aTweet.user + ':') $aTweet.find('#info').text(aTweet.message + ' ' + aTweet.created_at); //gives the tweet variable this text $aTweet.appendTo(tweetList); count++; $("#tweetList div").first().remove(); }); $('.user').on("click", function(){ console.log(10) }); }); </script> </body> </html>
No Doc Type
HTML5
HTML 4.01 Transitional
HTML 4.01 Strict
HTML 4.01 Frameset
XHTML 1.1
XHTML 1.0 Transitional
XHTML 1.0 Strict
XHTML 1.0 Frameset
Copy
Format
Download
×
Code Description
×
Difference of Versions
HTML
CSS
JS
×
JS Error
×
CSS Error
Errors
Warnings
×
JavaScript Setting
JS Libraries:
Chrome Frame 1.0.3
Dojo 1.8.0
Dojo 1.7.3
Dojo 1.7.2
Ext Core 3.1.0
jQuery 1.8.0
jQuery 1.7.2
jQuery 1.6.0
jQuery 1.5.0
jQuery 1.4.4
jQuery 1.4.0
jQuery-min 1.7.2
jQueryUI-min 1.8.21
MooTools more-1.4.0.1-full
MooTools core-1.4.5-full
MooTools core-1.4.1-full
Prototype 1.7.1.0
script.aculo.us 1.9.0
SWFObject 2.2
Twitter Bootstrap 2.0.4
WebFont Loader 1.0.28
yui 3.5.1
User Libraries:
Upload File
JavaScript URL(s):
×
CSS Setting
CSS Libraries:
jQueryUI 1.8.21
Twitter Bootstrap 2.0.4
User Libraries:
Upload File
CSS URL(s):