JavaScript - Peer-reviewed Online Javascript Journal?
I come from an academic background, so when I finish something I'm proud of, I naturally want to have it certified and advertised by others. I'm thinking of a site that reviews scripts and classifies those that are accepted as to who may find them worthwhile.
But I don't know of any modern analogue to the traditional refereed technical journals. By "analogue" I mean different in these key respects: Submitted "articles" are interactive web pages rather than printable papers; and "publishing" need not involve hosting the actual page, but more importantly, letting the world know of its existence and importance. I am aware of sites that review for a price, thereby suggesting the ability to be compromised. In some cases, the price is that the author forfeits his copyright. Personally, I'd be especially interested in a journal that accepts scripts published under a variety of open-source public copyrights (my personal favorite is the Creative Commons share-alike license). If you know of such a forum or online journal, I'd love to hear about it. And if not, might you be in the mood to start such a forum/journal? Similar TutorialsHi All- I've read the posting stickies but really don't know where to post this question, have pity I'm a newbe. Please move the post if necessary. I was given this "Mail To:" script from someone off some forum. I believe it is a secure format and managed to insert my info and it does work. I had my code verified by W3C. Yet, I think it has lines which could be deleted, I don't understand the comment out code as written in as ( // ) ? I especially don't understand the "<\/a>" at the end of this line: str += "'>" + anchortext + "<\/a>"; What is str? var? I'm tying to clean it up and understand it. Thanks for your comments. Like I say, it does work as stands. I've placed an[*] where I have inserted my info. <script type="text/javascript" language="JavaScript"> //<![CDATA[ var anchortext = "Email"; * var mailpart1 = "eci"; * var mailpart2 = "ecicare.com"; * var subject = 'ECI Website Inquiry'; * //var body = 'Set body of email'; // could add a set BODY like this (comment out if not needed) var str = "<a href='" + "mail" + "to:"; str += mailpart1 + "@" + mailpart2; str += "?subject="+subject; //str += "&body="+body; // also comment out this line if not needed str += "'>" + anchortext + "<\/a>"; document.write(str); //--> //]]> </script> Later, Robes I'm almost positive this question will make you groan "neewwwbie!".... I have a simple javascript that decides which 'div' to make visible, based on another element within the html. What i want now is to create a page where someone can view all the possible divs in that javascript that might appear and edit them (including href's, ital, bold and image tags.) Much like a CMS system, but the information is within a javascript, not a database. I would assume it's possible. What's a good way to approach this? It sounds like Javascript cannot edit .txt files. Is there a way to have the user access and edit an .xml file and just pull that into the div tag, instead of text? Hi... Im in between a project in which I have to make and Online Radio for various languages Im using Javascript and HTML/CSS and confused on how and where n which way to get a Radio Player on my the web page!! Also whn if I get a Player on page...How would I go about to Make it to Play a Particular Online Radio!! Im using Javascript and HTML(and im not tooo keen on using FLASH as im not aware of it!!!) Pls sumbody help me on this ASAP !! Thanks !! I have to take more javascript programming classes and I'm really not good at it. I desperately need help. I own Visual Basic, but it's a little difficult to use. What is the best book, online resource, and software for programming in javascript?
I am hoping someone can help me with a tweak to my current online quiz code. I know very little javascript but was thinking this might be an easy change. I need a funtion to get all the quiz answers ( I'm using radio buttons with values assigned) Values of each question answered will be added together Results are determined by 3 score ranges and displayed on the appropriate html page I have this code from a different quiz but not able to figure out how to change it to get the results I need. Please be gently with with!!! I am just learning. Code: function finish() { var ext = '.html'; var results = new Array("none","results1","results2","results3"); var nums = new Array(4); for(var i = 0; i < nums.length; i++) nums[i] = 0; for(var i = 1; i <= 9; i++) { var q = document.forms['quiz'].elements['question_'+i]; if(q[0].type=='checkbox') { var n = 0; } for(var j = 0; j < q.length; j++) { if(q[j].checked) { var a = q[j].value.split(','); for(var k = 0; k < a.length; k++) { nums[a[k]]++; } if(q[j].type=='radio') break; else n++; } if(j == q.length-1&&q[j].type=='radio') {nums[0]++;} } if(q[0].type=='checkbox'&&((document.forms['quiz'].elements['question_'+i+'_min']&&n<document.forms['quiz'].elements['question_'+i+'_min'].value)||(document.forms['quiz'].elements['question_'+i+'_max']&&n>document.forms['quiz'].elements['question_'+i+'_max'].value))) nums[0]++; } var j = new Array('0'); for (i in nums) if(nums[i]>nums[j[0]]){j=new Array(''+i);} else if(nums[i]==nums[j[0]])j[j.length] = i; //var o = '';for(var i in results)o+=results[i]+'='+nums[i]+'\n'; //alert(o); if(nums[0]!=0) { alert('You missed or incorrectly answered '+nums[0]+' questions!'); } else if(j[0]==0) { alert('No result could be determined.'); } else { location = results[j[0]]+ext; } } Please let me know if I am way off base or if there is a better way to attach the project. Most Grateful, TechPam hi guys, am trying to create online quiz with javascript,but am having problems,the code compiles but when i run nothing appears.i need help pliz. below is my code.please show where edited. <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/> <title>Driving Theory Test</title> <script language="javaScript" type="text/javascript"> //Questions and answers var questions = new Array(); var answers = new Array(); var questionsAsked; var numberOfQuestionsAsked = 0; var numberofQuestionCorrect = 0; var currentQNumber = -1; //define question 1 questions[0] = new Array(); questions[0][0] = "For which purpose is a horn allowed to be used outside built up areas"; questions[0][1] = "As a warning signal"; questions[0][2] = "As an overtaking signal"; // give correct answer Answers[0] = "A"; //define question 2 questions[1] = new Array(); questions[0][0] = "What can be the effects of even small quantities of alcohol"; questions[0][1] = "Delayed reactions"; questions[0][2] = "Reckless driving"; questions[0][3] = "Impairment of hearing and vision"; // give correct answer Answers[1] = "A"; //define question 3 questions[2] = new Array(); questions[0][0] = "What can cause a dangerous situation"; questions[0][1] = "Cutting corners"; questions[0][2] = "Dipping your headlihgts too late"; // give correct answer Answers[2] = "B"; fuction reset quiz() { var indexCounter; currentQNumber = -1; questionsAsked = New Array(); for (indexCounter = 0; indexCounter < questions.length;indexCounter++) { questionsAsked[indexCounter] = false; } numberOfQuestionsAsked = 0; numberOfQuestionsCorrect = 0; } function answerCorrect(questionNumber, answer) { // declare a variable to hold return value var correct = false; //if ansa provided is same as ansa then correct ansa is true if (answer == answers[questionNumber]) { numberOfQuestionsCorrect++; correct = true; } // return whether the ansa was correct (true or false) return correct; } function getQuestion() { if (questions.length != numberOfQuestionsAsked) { var questionNumber = Math.floor(Math.random() * questions.length) while (questionsAsked[questionNumber] == true) { questionNumber = Math.floor(Math.random() * questions.length); } var questionLength = questions[questionNumber].length; var questionChoice; numberOfQuestionsAsked++; var questionHTML = "<h4>Question " + numberofQuestionAsked + "</h4>"; questionHTML = questionHTML + "<p>" + questions[questionNumber][0]; questionHTML = questionHTML + "</p>; for (questionChoice = 1;questionChoice < questionLength;questionChoice++) { questionHTML = questionHTML + "<input type=radio " questionHTML = questionHTML + " name=radQuestionChoice" if (questionChoice == 1) { questionHTML = questionHTML + " checked"; } questionHTML = questionHTML + ">" + questions[questionNumber][questionChoice]; questionHTML = questionHTML + "<br>" } questionHTML = questionHTML + "<br><input type= 'button'" questionHTML = questionHTML + " value='Answer Question'"; questionHTML = questionHTML + "name=buttonNextQ "; questionHTML = questionHTML + "onclick='return buttonCheckQ_onclick()'>"; currentQNumber = questionNumber; questionsAsked[questionNumber] = true; } else { var questionHTML = "<h3>Quiz Complete</h3>"; questionHTML = questionHTML + "You got " + numberOfQuestionsCorrect; questionHTML = questionHTML + " questions correct out of " questionHTML = questionHTML + " numberOfQuestionsAsked; questionHTML = questionHTML + "<br><br>Your rating is " switch(Math.round(((numberOfQuestionsCorrect / numberOfQuestionsAsked) * 10))) { case 0: case 1: case 2: case 3: questionHTML = questionHTML + "Try next time"; break; case 4: case 5: case 6: case 7: questionHTML = questionHTML + "Average"; break; default: questionHTML = questionHTML + "Excellent" } questionHTML = questionHTML + "<br><br><A " questionHTML = questionHTML + "href= 'Exampage.htm'><Strong>" questionHTML = questionHTML + "Start again</strong></A>" } return questionHTML; } </script> </head> <body> </body> </html> thnks in advance Hi, I am trying to create a small art project where I want to track real-time visitors on my site. I am not very good at coding at all and am really struggling to know how to go about this To give you an idea of what I want to achieve; a basic example would be for every live visitor on my site, a circle would appear on the index page. I am aiming for the end product to be a very basic visualisation of live visitors on the site. So just a group of circles representing how many people are on the site. I am really struggling to get to grips with the coding needed and would hugely appreciate your help. Thank you very much for your time, Hi, I would like to display total online viewers on my website, how can i do this? thanks I want to write a code. in which I select the AC Temperature By Radio Buttons. then I observe the Saving energy by Bar Graph with out submitting the Form. As I change the Input, automatically, Output should change what should be code in HTML or Javascript so that I may observe effect of the change of Temperature on saving energy. thanks. Hello Guys, I have been grabbing good ideas and code from everywhere to build an online order form. I have no skill programming, but i have managed to almost finish it. However i still have two thing I cant done. Hope you can help me. 1. If any product of the "Product #2 drop-down menu" is selected, then "shipping drop-down menu" should only have "Post office option" enabled. 2. If "Shipping drop-down menu" is 7-11 or Family Mart, then "Convenience store text box" should be enabled. You can check the whole code he http://dl.dropbox.com/u/21610873/code.txt Thanks Since it is not clear to me where this post should fit in the forum, I'm just posting it here. Is it possible to create a tracking code that would allow me to: (1) a) Find out the identity of visitors to a certain website (a website unrelated to me and the visitors did not visit my website) b) The identity of those who recently searched for a certain keywords and/or... (2) Find out what websites certain individuals have recently visited (or visiting in real-time)? I have been playing with two options but just dont seem to get the coding right. Can someone please assist. Using ie9 but same problem with all browsers. first snippets. HTML: Code: <!-- Row 3, Col 3 purchase boxes --> <td colspan="1" height="120" align="left"> <input style="margin-left: 60px" type="text" name="bed_359" size="3" maxlength="3" onchange="calculateValue(this.form)" /> R359</td></tr> <!-- Row 10, Col 2 Order Value Box--> <td colspan="1" align="left"><input style="margin-left: 60px" type="text" name="total" size="10" onfocus="this.form.elements[0].focus()" /> </td></tr> javaScript: Code: // Function to calculate order value function calculateValue(orders) { var orderValue = 0; var value = 0; var itemPrice = 0; var itemQuantity = 0; // Run through all the product fields for(var i = 0; i < orders.elements.length; ++i) { // Get the current field formField = orders.elements[i]; // Get the fields name formName = formField.name; // Items price extracted from name itemPrice = parseFloat(formName.substring(formName.lastIndexOf("_") + 1)); // Get the Quantity itemQuantity = parseInt(formField.value); // Update the OrderValue if(itemQuantity >= 0) { value = itemQuantity * itemPrice; orderValue += value; } } // Display the total orders.total.value = orderValue; } Second code: Code: <!-- Row 9, Col 3 purchase boxes --> <td colspan="1" height="120" align="left"> <select style="margin-left: 60px" name="shirt" value="215" onchange="calculateValue(this.form)" /> <option value="0">0</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option></select> R215</td></tr> Java Code: // Function to calculate order value function calculateValue(orders) { var orderValue = 0; var value = 0; var itemPrice = 0; var itemQuantity = 0; // Run through all the product fields for(var i = 0; i < orders.elements.length; ++i) { // Get the current field formField = orders.elements[i]; // Get the fields name formValue = formField; // Items price extracted from name itemPrice = formField; // Get the Quantity itemQuantity = formField.selectedIndex; // Update the OrderValue if(itemQuantity > 0) { orderValue += itemQuantity * itemPrice } } // Display the total orders.total.value = orderValue.toLocaleString();; } Please help its probably something simple. hi, I have to dynamically add images into a div. I am able to do this and perform action on the image locally. If i host it to the server iam not able to see the image it only displays x. But i am able to perform some action on the newly added image. Following is the code i have tested offline and online Code: <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>JavaScript: Moving an Image</title> <script language="javascript" type="text/javascript"> var currImage=null; var maxWidth=100; var maxHeight=100; var fileTypes=["bmp","gif","png","jpg","jpeg"]; function preview(what) { var source=what.value; var imgW,imgH, path; var ext=source.substring(source.lastIndexOf(".")+1,source.length).toLowerCase(); for (var i=0; i<fileTypes.length; i++) if (fileTypes[i]==ext) break; if (i<fileTypes.length) { var ni = document.getElementById('myDiv'); var numi = document.getElementById('theValue'); var num = (document.getElementById('theValue').value -1)+ 2; numi.value = num; var newImg = document.createElement('img'); path = source.replace(/\\/g, '/'); // Fix Windows paths path = 'file://localhost/'+ path; path = path.toLowerCase(); newImg.src=path; alert(path); newImg.id="imgID"+num; ni.appendChild(newImg); var x=parseInt(newImg.width); var y=parseInt(newImg.height); if (x>maxWidth) { y*=maxWidth/x; x=maxWidth; } if (y>maxHeight) { x*=maxHeight/y; y=maxHeight; } newImg.width=x; newImg.height=y; } else { alert("THAT IS NOT A VALID IMAGE\nPlease load an image with an extention of one of the following:\n\n"+fileTypes.join(", ")); } } function removeImage() { var ni = document.getElementById('myDiv'); if (currImage==null) { alert("No image to remove"); } else if (currImage==0) { alert("Click the image to remove / No image to remove"); } else { alert(currImage.id); ni.removeChild(currImage); currImage=0; } } </script> <style> #myDiv { width: 200px; height: 240px; position: relative; margin: 20px auto 0px auto; border: 5px outset #000; overflow: hidden; background-color:pink; } </style> </head> <body > <div id="myDiv" > </div> <p> <input type="hidden" value="0" id="theValue" /> <input type="button" id="delete" value="Remove" onClick="removeImage()"> <input type="file" id="picField" onChange="preview(this)"> </p> </body> </html> Hi, My project simulation takes lot of time so I cant monitor that continuously,. I want to send a SMS whenever some simulation is done/ progress / throws an error to my mobile through SMS when I'm away from the PC.. I dont know how to start with this.. pls tell me how to do this I want to use free online SMS service to do this.. Hello, I am trying to figure out how to write a quiz that has one question per html page, then once the choice has been selected, it will go to another page and tally a total at the end. Can this be done? And if so, can you point me in the right direction to research? Thanks in advance, Tanya Hello! So I came across this Featured Content Slider mod (http://css-tricks.com/creating-a-sli...ontent-slider/) which is based on the Coda Slider (http://www.ndoherty.biz/demos-index/) which uses jQuery. However, you'll notice that the Coda Slider has since received an update (2.0). What I'm trying to do is update the mod for the Coda Slider update, which I'll then use to create a WordPress plugin for my site. Thing is, I don't really know JavaScript (only enough to logic my way through simply stuff). A lot of things seemed to have changed in the Coda update, but I can't seem to get things to work properly in the FCS, specifically being able to click a thumbnail and make the slider switch to that one. I'm pretty sure I've ruled out CSS being an issue, leaving the JavaScipt. If anyone's willing to take a look, I've uploaded what I currently have to http://www.thetanooki.com/coda.zip It's a bit rough at the moment, since I'm pretty much using trial and error to figure things out... and don't mind the seemingly useless PHP code at the top of the .js.php file - that's just an example I'm hoping to use for when I eventually make a WordPress plugin out of it. Anyway, index2.html is the one I'm working on, I'm only using index.html (original) as a guide, and the original FCS as well as old version of Coda can be found at the other links above. Thanks in advance; any light that can be shed on this would be a tremendous help! If I've screwed something else up, let me know - I may have overlooked conflicting class names or something like that since the originals aren't my own code and I'm still familiarizing myself. Hi everyone, first time on these forums. I've installed a WordPress plugin that displays which users are currently online, as a widget on the side-panel of my website, www.mi6gaming.com . There's some problems, however. When using the default code, all the members display correctly and load quickly, but there's no limit to the ammount of users displayed, so it goes on for about 30 members, and then it just starts to overlap and it looks ridiculous. Here is the download link to view any of the files: http://wordpress.org/extend/plugins/...-online/stats/ See screenshot of what i'm talking about: http://i.imgur.com/JYPGQ.png When I change "0" to a certain number, say 5, what that does is it will constantly display 5 members at any given time, and any other members who are currently online will be displayed on top of that. So say I'm a visitor to the website, I will see the 5 most recent people online, and if anyone else logs on during that time, it will display them as being online on top of the other 5 most recently online people. But, this isn't working correctly. It only shows, for some reason, a specific 5 people all the time and does not update whenever somebody else is logged in. So anytime you visit the website, it always shows the same 5 people and the last time they were logged in, even if other people were logged in more recently than them. See screenshot: http://i.imgur.com/CBE53.png So; when I have the code set at 0, it displays everyone correctly and updates on time, but it doesn't cap off and it's too long and overlaps. When I have it set at 5, it stays fixated on 5 people all the time and updates the times THEY were last online, and it shows who is online at the present time, but you have to be on the same page for 45 seconds to be able to see "who's online" right then, whereas when it's at 0, everything is instant and flawless, except for not stopping. Is there any way to add code to prevent it from loading X ammount of users, and to limit it to a certain number? That would likely be the simplest answer. Here is the code: .css Code: .wpwhosonline-row { float: none; width: auto; height: 33px; padding-bottom: 10px; padding-top: 5px; } .wpwhosonline-row > img { float: left; margin-right: 1ex; } .wpwhosonline-active > span { font-weight: bold; color: green; } .wpwhosonline-recent > span { } .wpwhosonline-ancient > span { font-style: italic; color: red; } /* kubrick style follows */ #sidebar ul li.widget_wpwhosonline ul li:before { content: none; } .php Code: <?php /* Plugin Name: Who's Online Plugin URI: http://www.plymouth.edu/ Description: Sidebar widget to log when a user was last online Version: 0.5.1 Author: Adam Backstrom Author URI: http://blogs.bwerp.net/ License: GPL2 */ /* Copyright 2011 Adam Backstrom <adam@sixohthree.com> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ function wpwhosonline_enqueue() { add_action( 'wp_head', 'wpwhosonline_pageoptions_js', 20 ); wp_enqueue_script( 'wpwhosonline', plugins_url('wp-whos-online.js', __FILE__), array('jquery'), 1 ); wp_enqueue_style( 'wpwhosonline_css', plugins_url('wp-whos-online.css', __FILE__), null, 1 ); } add_action('wp_enqueue_scripts', 'wpwhosonline_enqueue'); // our own ajax call add_action( 'wp_ajax_wpwhosonline_ajax_update', 'wpwhosonline_ajax_update' ); // hook into p2 ajax calls, if they're there add_action( 'wp_ajax_prologue_latest_posts', 'wpwhosonline_update' ); add_action( 'wp_ajax_prologue_latest_comments', 'wpwhosonline_update' ); /** * Update a user's "last online" timestamp. */ function wpwhosonline_update() { if( !is_user_logged_in() ) return null; global $user_ID; update_user_meta( $user_ID, 'wpwhosonline_timestamp', time() ); }//end wpwhosonline_update add_action('template_redirect', 'wpwhosonline_update'); /** * Echo json listing all authors who have had their "last online" timestamp updated * since the client's last update. */ function wpwhosonline_ajax_update() { global $wpdb; // update timestamp of user who is checking wpwhosonline_update(); $load_time = strtotime($_GET['load_time'] . ' GMT'); $users = wpwhosonline_recents( "meta_value=$load_time" ); if( count($users) == 0 ) { die( '0' ); } $now = time(); $latest = 0; $return = array(); foreach($users as $user) { $row = array(); $last_online_ts = get_user_meta( $user->ID, 'wpwhosonline_timestamp', true ); if( $last_online_ts > $latest ) $latest = $last_online_ts; $row['user_id'] = $user->ID; $row['html'] = wpwhosonline_user( $last_online_ts, $user ); $row['timestamp'] = $last_online_ts; $return[] = $row; } echo json_encode( array('users' => $return, 'latestupdate' => gmdate('Y-m-d H:i:s', $latest)) ); exit; } function wpwhosonline_pageoptions_js() { global $page_options; ?><script type='text/javascript'> // <![CDATA[ var wpwhosonline = { 'ajaxUrl': "<?php echo esc_js( admin_url('admin-ajax.php') ); ?>", 'wpwhosonlineLoadTime': "<?php echo gmdate( 'Y-m-d H:i:s' ); ?>", 'getwpwhosonlineUpdate': '0', 'isFirstFrontPage': "<?php echo is_home(); ?>" }; // ]]> </script><?php } function wpwhosonline_usersort( $a, $b ) { $ts_a = get_user_meta( $a->ID, 'wpwhosonline_timestamp', true ); $ts_b = get_user_meta( $b->ID, 'wpwhosonline_timestamp', true ); if( $ts_a == $ts_b ) { return 0; } return ($ts_a < $ts_b) ? 1 : -1; } function wpwhosonline_recents( $args = array() ) { $args = wp_parse_args( $args, array( 'meta_key' => 'wpwhosonline_timestamp', 'orderby' => 'wpwhosonline_timestamp', 'order' => 'DESC', 'meta_value' => time() - 604800, // 1 week 'meta_compare' => '>', 'count_total' => false, 'number' => 0 )); $users = get_users( $args ); foreach( $users as $user ) { // grab all these values, or you'll anger usort by modifying // an array mid-execution. get_user_meta( $user->ID, 'wpwhosonline_timestamp', true ); } usort( $users, 'wpwhosonline_usersort' ); return $users; } function wpwhosonline_list_authors() { $users = wpwhosonline_recents(); $html = '<ul class="wpwhosonline-list">'; foreach( $users as $user ) { $last_online_ts = get_user_meta( $user->ID, 'wpwhosonline_timestamp', true ); $item = wpwhosonline_user( $last_online_ts, $user ); $class = wpwhosonline_class( $last_online_ts ); $item = '<li id="wpwhosonline-' . $user->ID . '" class="wpwhosonline-row ' . $class . '" data-wpwhosonline="' . esc_attr( $last_online_ts ) . '">' . $item . '</li>'; $html .= $item; } $html .= '</ul>'; echo $html; } function wpwhosonline_user( $last_online_ts, $user ) { $avatar = get_avatar( $user->user_email, 32 ); $name = $user->display_name; $link = '<a href="' . get_author_posts_url( $user->ID, $user->user_nicename ) . '" title="' . esc_attr( sprintf(__("Posts by %s"), $user->display_name) ) . '">' . $name . '</a>'; // this should always exist; we queried using this meta if( ! $last_online_ts ) { continue; } $now = time(); if( $now - $last_online_ts < 120 ) { $last_online = 'Online now!'; } else { $last_online = human_time_diff( $now, $last_online_ts ) . ' ago'; } $last_online_title = date_i18n( get_option('date_format') . ' ' . get_option('time_format'), $last_online_ts ); if( $last_online ) { $last_online = '<span title="Last online: ' . esc_attr( $last_online_title ) . '">' . $last_online . '</a>'; } return $avatar . $link . '<br>' . $last_online; } function wpwhosonline_class( $lastonline ) { $diff = time() - $lastonline; if( $diff > 7200 ) { return 'wpwhosonline-ancient'; } elseif( $diff > 600 ) { return 'wpwhosonline-recent'; } else { return 'wpwhosonline-active'; } } function widget_wpwhosonline_init() { // Check for the required plugin functions. This will prevent fatal // errors occurring when you deactivate the dynamic-sidebar plugin. if ( !function_exists('wp_register_sidebar_widget') ) return; // This is the function that outputs the Authors code. function widget_wpwhosonline($args) { extract($args); echo $before_widget . $before_title . "Users" . $after_title; ?> <ul> <?php wpwhosonline_list_authors(); ?> </ul> <?php echo $after_widget; } // This registers our widget so it appears with the other available // widgets and can be dragged and dropped into any active sidebars. wp_register_sidebar_widget( 'widget_wpwhosonline', "Who's Online", 'widget_wpwhosonline' ); } // Run our code later in case this loads prior to any required plugins. add_action('plugins_loaded', 'widget_wpwhosonline_init'); .js Code: /* Copyright (C) 2011 Adam Backstrom <adam@sixohthree.com> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ jQuery(function($) { /* * Update author "last online" timestamps */ function getwpwhosonline(){ toggleUpdates(); var queryString = wpwhosonline.ajaxUrl +'?action=wpwhosonline_ajax_update&load_time=' + wpwhosonline.wpwhosonlineLoadTime + '&frontpage=' + wpwhosonline.isFirstFrontPage; ajaxCheckAuthors = $.getJSON(queryString, function(response){ if(typeof response.latestupdate != 'undefined') { wpwhosonline.wpwhosonlineLoadTime = response.latestupdate; for(var i = 0; i < response.users.length; i++) { var current = response.users[i], $o = $('#wpwhosonline-' + current.user_id); console.dir(current.user_id, current.timestamp); if( $o.length == 0 ) { $o = $('<li/>').attr('id', 'wpwhosonline-' + current.user_id). addClass( 'wpwhosonline-row wpwhosonline-active' ). prependTo( '.wpwhosonline-list' ); console.log($o); } $o.html( current.html ). data('wpwhosonline', current.timestamp); } } console.log('Done'); }); toggleUpdates(); updateRecents(); }; // from http://snippets.dzone.com/posts/show/5925 function formatDate(formatDate, formatString) { if(formatDate instanceof Date) { var months = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"); var yyyy = formatDate.getFullYear(); var yy = yyyy.toString().substring(2); var m = formatDate.getMonth(); var mm = m < 10 ? "0" + m : m; var mmm = months[m]; var d = formatDate.getDate(); var dd = d < 10 ? "0" + d : d; var h = formatDate.getHours(); var hh = h < 10 ? "0" + h : h; var n = formatDate.getMinutes(); var nn = n < 10 ? "0" + n : n; var s = formatDate.getSeconds(); var ss = s < 10 ? "0" + s : s; formatString = formatString.replace(/yyyy/i, yyyy); formatString = formatString.replace(/yy/i, yy); formatString = formatString.replace(/mmm/i, mmm); formatString = formatString.replace(/mm/i, mm); formatString = formatString.replace(/m/i, m); formatString = formatString.replace(/dd/i, dd); formatString = formatString.replace(/d/i, d); formatString = formatString.replace(/hh/i, hh); formatString = formatString.replace(/h/i, h); formatString = formatString.replace(/nn/i, nn); formatString = formatString.replace(/n/i, n); formatString = formatString.replace(/ss/i, ss); formatString = formatString.replace(/s/i, s); return formatString; } else { return ""; } } function updateRecents(){ var now = Math.round(new Date().getTime()/1000.0); var active = 120; // 2 minutes var recent = 600; // 10 minutes var ancient = 7200; // 2 hours $('.wpwhosonline-row').each(function(){ var $o = $(this); var since, oclass, remove; var last = $o.data('wpwhosonline'); since = now - last; if(since > ancient) { oclass = "wpwhosonline-ancient"; remove = "wpwhosonline-recent wpwhosonline-active"; } else if(since > recent) { oclass = "wpwhosonline-recent"; remove = "wpwhosonline-ancient wpwhosonline-active"; } else { oclass = "wpwhosonline-active"; remove = "wpwhosonline-ancient wpwhosonline-recent"; // no longer active; remove "Online now!' text if(since > active && $o.text() == 'Online now!' ) { var theDate = new Date(last * 1000); $o.text( formatDate(theDate, 'dd mmm yyyy HH:MM:ss') ); } } $o.addClass( oclass ).removeClass( remove ); }); } function toggleUpdates() { if (0 == wpwhosonline.getwpwhosonlineUpdate) { wpwhosonline.getwpwhosonlineUpdate = setInterval(getwpwhosonline, 30000); } else { clearInterval(wpwhosonline.getwpwhosonlineUpdate); wpwhosonline.getwpwhosonlineUpdate = '0'; } } toggleUpdates(); updateRecents(); }); I need to have an online submission form, which accepts text for print adverts. Here is my problem: Whereas with Twitter, you are limited to 140 characters as the output is digital, with print the overall width of text is vital if it has to fit within a given space. Are there any javascript software libraries available that can calculate the printed length? Preferably as the user types. This assumes that the font, font-size and kerning are known. (I do not want to use the 'Courier' font) We will have to write this in-house unless there is something available on the internets (I'm possibly not the first person to come up against this) Can anyone help? (I've posted this at 'graphicdesignforum' but figure the readership will be different) |