JavaScript - Google Closure Compiler
This is pretty cool; here's an online service Google has provided to scrunch your Javascript code down as small as possible.
http://closure-compiler.appspot.com/home Here's the intro page... http://code.google.com/closure/compiler/ I like it! Similar TutorialsI am a student. I have eliminated all errors except this one. Quote: Reservations.java:108: 'else' without 'if' else ^ 1 error Tool completed with exit code 1 I have both if and else there. I have gone through the code looking for another problem, but there are none. I am in a time crunch with this chapter ending tomorrow night. If you could point me in the right direction it would be fantastic. Because I am in a bind, and do not know where else to look. here is the area that the compiler is referring to. PHP Code: public void actionPerformed(ActionEvent e) { if (hidden.getState()); { JOptionPane.showMessageDialog(null,"You must select Nonsmoking or Smoking.","Error",JOptionPane.ERROR_MESSAGE); } else { int available = room.bookRoom(Smoking.getState()); if (available > 0) //room is available { roomDisplay[available].setBackground(lightRed);//diplay room as occupied roomDisplay[available].setText( roomDisplay[available].getText() + "\n" + nameField.getText() + " " + phoneField.getText() + "\nparty of " + numberOfGuests.getSelectedItem() );//display info in room clearFields(); } else //rooms is not available { if (Smoking.getState()) JOptionPane.showMessageDialog(null,"Smoking is Full","Error",JOptionPane.INFORMATION_MESSAGE); else JOptionPane.shoeMessageDialog(null,"Nonsmoking is Full","Error",JOptionPane.INFORMATION_MESSAGE); hidden.setState(true); }//end of else block that checks the available room number }//end of else block that checks the state of the hidden option button }//end of the actionperformed() method Here is the full code PHP Code: import javax.swing.JOptionPane; import java.awt.*; import java.awt.event.*; public class Reservations extends Frame implements ActionListener { color lightRed = new color(255, 90, 90); color lightGreen = new color(140, 215, 40); Rooms room = new Rooms(5, 3); Panel roomPanel = new Panel(); TextArea roomDisplay[] = new TextArea[9]; Panel buttonPanel = new Panel(); Button bookButton = new button("Book Room"); Panel inputPanel = new Panel(); Label custNameLabel = new Label("Name"); TextField nameField = new TextField(15); Label custPhoneLabel = new Label("Phone Number"); TextField phoneField = new TextField(15); Label numLabel = new Label("Number in Party"); Choice numberOfGuests = new Choice(); CheckboxGroup optios = new CheckboxGroup(); Checkbox nonSmoking = new Checkbox("Nonsmoking",false,options); Checkbox Smoking = new Checkbox("Smoking",false,options); Checkbox hidden = new CheckBox("",true,options); public Reservations() { //set Layouts for frame and three panels this.setLayout(new BorderLayout()); roomPanel.setLayout(new GridLayout(2,4,10,10)); buttonPanel.setLayout(new FlowLayout()); inputPanel.setLayout(new FlowLayout()); //add components to room panel for (inti=1; i<9; i++) { roomDisplay[i] = new TextArea(null,3,5,3); if(i<6) roomDisplay[i].setText("Room " + i + "NonSmoking"); else roomDisplay[i].setText("Room " + i + "Smoking"); roomDisplay[i].SetEditable(false); roomDisplay[i].setBackground(lightGreen); roomDisplay.add(roomDisplay[i]); } //add components to button panel buttonPanel.add(bookButton); //add components to input panel inputPanel.add(custNameLabel); inputPanel.add(NameField); inputPanel.add(custPhoneLabel); inputPanel.add(PhoneField); inputPanel.add(numLabel); inputPanel.add(numberOfGuests); for(int i = 8; i<=20; i++) numberOfGuests.add(String.valueOf(i)); inputPanel.add(nonSmoking); inputPanel.add(Smoking); //adds panel to Frame add(buttonPanel, BorderLayout.South); add(inputPanel, BorderLayout.Center); add(roomPanel, BorderLayout.North); bookButton.addActionListener(this); //override the windowClosing() method will allow the user to click the close button addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } } ); }//end of constructor method public static void main(String[] args) { Reservations f = new Reservations(); f.setBounds(200,200,600,300); f.setTitle("Reserve a Party Room"); f.setVisible(true); }//end of main public void actionPerformed(ActionEvent e) { if (hidden.getState()); { JOptionPane.showMessageDialog(null,"You must select Nonsmoking or Smoking.","Error",JOptionPane.ERROR_MESSAGE); } else { int available = room.bookRoom(Smoking.getState()); if (available > 0) //room is available { roomDisplay[available].setBackground(lightRed);//diplay room as occupied roomDisplay[available].setText( roomDisplay[available].getText() + "\n" + nameField.getText() + " " + phoneField.getText() + "\nparty of " + numberOfGuests.getSelectedItem() );//display info in room clearFields(); } else //rooms is not available { if (Smoking.getState()) JOptionPane.showMessageDialog(null,"Smoking is Full","Error",JOptionPane.INFORMATION_MESSAGE); else JOptionPane.shoeMessageDialog(null,"Nonsmoking is Full","Error",JOptionPane.INFORMATION_MESSAGE); hidden.setState(true); }//end of else block that checks the available room number }//end of else block that checks the state of the hidden option button }//end of the actionperformed() method //reset the text fields and choice components void cleadFields() { nameField.setText(""); phoneField.setText(""); numberOfGuests.setText(0); nameField.requestFocus(); hidden.setState(true); }//end of clearFields() method }//end of reservation class is this function a closure in javascript? Code: function f1(){ var n=999; function f2(){ alert(n); // 999 } } is the function f2() a closure? if not? why? what's and use of a closure.could you depict it in your own words. thank you Code: function foo(x) { var tmp = 3; function bar(y) { alert(x + y + (++tmp)); } bar(10); } foo(2) is the function a closure? if not? why? thank you When using anonymous wrappers (I guess they are called like that), what does "()" part do at the end of the stack? An example: Code: ( function() {} ) () //Here! What does it do and how can we use it? js code is as follows: Code: uniqueNo=(function(){ var no=0; return function(){ return no++; } })() document.writeln(uniqueNo()); // 1st time call document.writeln(uniqueNo()); // 2nd time call document.writeln(uniqueNo()); // 3rd time call the result is 1 2 3 why after the 2nd call, the declaration 'var no=0' is useless -- seems 'no' is updated and stored each time it is called? many thanks Hi, i'm looking to send a loop variable (i) to a function inside the loop, but I can't seem to get it to use the value I want, it keeps making it a reference of i and therefore the function is always called using the last value of i rather than the one it was set with. So if i have 5 Tabs then Tab 1, when clicked, should call DefaultTabClick(0) and so on rather than always using 4 for any of the tabs. Code: for (var i = 0; i < AccountSettings.Tabs.length; i++) { $tabs.append(CreateTabLink(AccountSettings.Tabs[i].Title, DefaultTabClick(i)));}); } function DefaultTabClick(i) { var i = i || AccountSettings.Tabs.length - 1; return function () { if (currentTab === i) {RenameTab(this);} else { SaveTabSettings(currentTab); //Save Current ClearDashboard(); //Clear Current LoadDashboardWithLayout(i); //Load Selected } } } Hi all, I've got some simple code that I use to drag the corners of a DIV to resize it on the fly. One thing that bothers me is that there is a "global" variable just hanging outside and I would rather "encapsulate" it all into a block of code so that the variable persists, but is not visible outside of the code that uses it. So, here's the code: Code: /*** * support for mouse drag resize of mChat window * "global" save of mouse start position **/ var start = 0; /*** * do-nothing function to attach unused events to **/ function nullFunc () { return false; }; /*** * begin drag **/ function drag () { start = 0; document.onmouseup = up; document.onmousedown = nullFunc; document.onmousemove = move; return false; }; /*** * end drag **/ function up () { start = 0; document.onmouseup = nullFunc; document.onmousedown = nullFunc; document.onmousemove = nullFunc; return false; }; /*** * mouse move capture **/ function move (e) { var o = mouseXY(e); /* mouseXY not shown here */ if (start) { mChatSize(o.y - start); /* mChatSize not shown here */ } start = o.y; return false; }; You see the code captures the mouse Y coordinate and then subtracts "start" from it to generate a DELTA (which is what the mChatSize function needs). So, moving the mouse up generates "-1, -1, -1" maybe -2 if dragged fast and +1 +1 +1... if moved down.... you see? Now what I want to do is put all this code in a "box" so that "start" is global to the box, but invisible outside. I tried to do it and made no headway... I'm sure it's simple and I'm just missing it. Any help will be appreciated. Thanks! -- Roger I have a page with a GoogleMap with a GoogleBar and I would like the GoogleBar to appear with something written in it already and to have that search executed. In other words, I would like to "write something to the GoogleBar and press Enter" automatically as soon as the map loads. How can I do this? btw: By GoogleBar, I mean the search bar that appears on the map after using the enableGoogleBar() function. Hi, I'm not sure where I have translated this incorrectly. I have one google map embedded on my page which works fine. But I wanted to add a second one. I thought the easiest way to do this would be to have a second page which is called later on with all the details on it for the second map. However although I think (this I presume is where I went wrong) I have replicated the instructions correctly the place holder for the second map just remains blank. This is the code for my called page with the instructions for the second map: PHP Code: <?php echo $_POST['Map'] . '<br />'; ?> <div id="placemap_canvas"></div> <meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> <style type="text/css"> html {height:250px} body {height:250px} #placemap_canvas {width:100%; height:150px;} </style> <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true" /> </script> <script type="text/javascript"> var latlng = new google.maps.LatLng ( <?php include("dbconnect.php"); $result = mysql_query("SELECT * FROM regions WHERE RegionPId='{$_POST['Map']}'"); while($row = mysql_fetch_array($result)){ echo $row['maplink']; } mysql_close($con); ?> ); var myOptions = { zoom: 4, center: latlng, mapTypeId: google.maps.MapTypeId.ROADMAP }; var map = new google.maps.Map(document.getElementById("placemap_canvas"), myOptions); } </script> And this is the script of the main page, just in case I would be better off keeping them both in one place. Code: <head> <script type="text/javascript"> function loadSubPlace(File,ID,Msg,Eile,EID,Esg){ loadXMLDoc1(File,ID,Msg); var mimer = setTimeout(function(){loadXMLDoc1(Eile,EID,Esg)},5000); } </script> <meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> <style type="text/css"> html {height:250px} body {height:250px} #map_canvas {width:30%; height:250px;} </style> <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true" /> </script> <script type="text/javascript"> function initialize() { var latlng = new google.maps.LatLng ( <?php include("dbconnect.php"); $result = mysql_query("SELECT * FROM countries WHERE Country='{$_SESSION['Country']}'"); while($row = mysql_fetch_array($result)){ echo $row['Map']; } mysql_close($con); ?>); var myOptions = { zoom: 4, center: latlng, mapTypeId: google.maps.MapTypeId.ROADMAP }; var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); } </script> </head> <body onload="initialize()"> <div class="countryright" id="map_canvas"> include("dbconnect.php"); $snowball=explode(';',$_POST['syringa']); $turnsol=$snowball[1]; $violet =$snowball[2]; $wakerobin=$snowball[3]; global $turnsol; global $violet; global $wakerobin; echo '<center><b><big>' . $wakerobin. '</big></b></center><br /><br />'; $result=mysql_query("SELECT * FROM regions WHERE country='{$turnsol}' AND region='{$violet}' AND place='{$wakerobin}' AND sub !='' ORDER BY sub ASC"); while($row = mysql_fetch_array($result)){ $wheat="{$row['RegionPId']};{$turnsol};{$violet};{$wakerobin};{$row['sub']}"; $tigerlilly=$row['RegionPId']; echo '<input type="button" class="button3" name="place" id="place" value="' . $row['sub'] . '" onclick="loadSubPlace(\'getPlace.php\',\'txtHintPlaceSub\',\'hepatica=' . urlencode($wheat) . '\',\'getPlaceMap.php\',\'placemapcanvas\',\'Map=' . urlencode($tigerlilly) . '\');" />'; } echo '<input type="button" class="button3" name="addplace" id="addplace" value="Add Place" onclick="loadXMLDoc1(\'getAddPlaceSub.php\',\'txtHintPlaceSub\', encodeURI(\'addsubplace=' . $_POST['syringa'] . '\'));" />'; echo '<br /><br /><div id="txtHintPlaceSub"></div><br /><br />'; mysql_close($con); ?> I've cut out the script that doesn't relate to this so I hope I haven't missed anything important. Can the Google API replace scraping? You can get blocked by Google if you scrape, but can you get the same info from the Google API at no risk?
Hi guys, I'm trying to run this sample file that i got from the google docs. I want to write a stock ticker from google finances xml feed and this is a sample they had. Code: <?xml version="1.0" encoding="utf-8"?> <Module> <ModulePrefs title="hellofinance"> <Require feature="finance"/> </ModulePrefs> <Content type="html"> <![CDATA[ Hello world! Here is your portfolio:<br/> GOOG: <span id=_IG_SYM1_l></span> (<span id=_IG_SYM1_c></span>)<br/> AAPL: <span id=_IG_SYM2_l></span> (<span id=_IG_SYM2_c></span>)<br/> INTC: <span id=_IG_SYM3_l></span> (<span id=_IG_SYM3_c></span>)<br/> <script> var quote = new google.finance.Quote(); quote.enableDomUpdates( { 'GOOG' : '_IG_SYM1', 'AAPL' : '_IG_SYM2', 'INTC' : '_IG_SYM3' } ); quote.getQuotes(["GOOG", "AAPL", "INTC"]); </script> ]]> </Content> </Module> my problem is i don't know how to execute it so i can see how it works. I tried sticking this code within a php file and it returns an error on the first line for unexpected t-string. So i tried changing the extension to xml and it just displays the code but does not execute. I'm stumped. Any help is appreciated. Thanks P.S. - Yes i do have the zend gdata framework installed and running on my server and is working correctly according to their test. Hello everyone! I've searched a lot of places for a script like this and found nothing. Here's my situation. My site uses a main iframe that changes as you click links. However, Google links to all my pages, I only want it to access a few (because some pages are only meant to be viewed via iframe). I'm looking for a JavaScript that will detect if the page is being viewed in an iframe, if it is, it should take no action, but if it's no, it should redirect to a different page. Is this possible??? Hi, I have a table with FROM and TO columns and a column with MAP/DIRECTIONS link. When a user clicks on the link, it should display Map and Directions on the iframe on the same page. How can I achieve this using Google map and directions API? Thanks Is there a javascript that when I mouse over a object like the the magnifying glass that can be seen after a google search that will display a preview image and then make that image clickable to pull up that webpage/file? TYIA James Hello, I think I am posting this in the right spot! I'm trying to add google translate to my mobile website... Because, I want an easy way for koreans to read it. It's a mobile site by dudamobile so my editing ability is limited.. the issue I am having is it works but it is throwing off my scrolling ability and page size and the toolbar and banner was spanning my webite to a very large area which threw off the look of the site. I was able to remove the banner (which I didnt need) by inputing this code into the CSS body {top: 0px !important; position: static !important; } .goog-te-banner-frame {display:none !important} but the drop down bar still has a spand the size a full sized website for some reason I pasted in the following code provided by google translate for the site: <div id="google_translate_element"></div><script> function googleTranslateElementInit() { new google.translate.TranslateElement({ pageLanguage: 'en', includedLanguages: 'zh-CN,zh-TW,en,de,ja,ko,th', layout: google.translate.TranslateElement.InlineLayout.SIMPLE }, 'google_translate_element'); } </script><script src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script> Is there any code that can be added to restrict the size of this bar? again the translate option works outside of this. Thanks Dave Hi I have just started looking at the Google maps, and have atutorial that will get the co-ordinates. What I want this to do, is then populate two fields on a form one called longitude and one called latitude Code: function usePointFromPostcode(postcode, callbackFunction) { localSearch.setSearchCompleteCallback(null, function() { if (localSearch.results[0]) { var resultLat = localSearch.results[0].lat; var resultLng = localSearch.results[0].lng; var point = new GLatLng(resultLat,resultLng); callbackFunction(point); }else{ alert("Postcode not found!"); } }); localSearch.execute(postcode + ", UK"); } Any ideas/tips would be be much appreciated i take an google suggestions code. view source... i hope that is the best "ajax google suggestions" code created... and try to understand it. someone can help to understand that javascript ? write remarks... formated code file attached + : Link1 I started using Google API Visualizations to create a bar chart which was very easy because of the code examples google gives but then I realised instead of setting the values I want within the html I wanted a form which would let you input the values you want for the bar chart. I made it look like this: Using this code: Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"/> <title> Google Visualization API Sample </title> <SCRIPT LANGUAGE="JavaScript"> function UpdateChart (form) { var TeamA = form.TeamA.value; var TeamB = form.TeamB.value; var TeamC = form.TeamC.value; var TeamD = form.TeamD.value; } </SCRIPT> <script type="text/javascript" src="http://www.google.com/jsapi"></script> <script type="text/javascript"> google.load('visualization', '1', {packages: ['barchart']}); </script> <script type="text/javascript"> function drawVisualization() { // Create and populate the data table. var data = new google.visualization.DataTable(); data.addColumn('string', 'Year'); data.addColumn('number', 'Score'); data.addRows(4); data.setValue(0, 0, 'Team A'); data.setValue(0, 1, 500); data.setValue(1, 0, 'Team B'); data.setValue(1, 1, 300); data.setValue(2, 0, 'Team C'); data.setValue(2, 1, 70); data.setValue(3, 0, 'Team D'); data.setValue(3, 1, 150); // Create and draw the visualization. new google.visualization.BarChart(document.getElementById('visualization')). draw(data, {title: 'Scores', legend: 'none'}); } google.setOnLoadCallback(drawVisualization); </script> </head> <body style="font-family: Arial;border: 0 none;"> <div id="visualization" style="width: 300px; height: 300px;"></div> <form name="input" method="get"> Team A: <input type="text" name="TeamA" value="0" size="1"> <br>Team B: <input type="text" name="TeamB" value="0" size="1"> <br>Team C: <input type="text" name="TeamC" value="0" size="1"> <br>Team D: <input type="text" name="TeamD" value="0" size="1"> <br> <INPUT TYPE="button" NAME="btnUpdate" Value="Update" onClick="UpdateChart(this.form)"> </form> </body> </html> However, instead of the values I've bolded I want the values from the form to be used. I've never really used Javascript before so I'm not sure what to do. Any help would be appreciated. Hi there, I know too little of JavaScript to get the Google Maps API working. I hope someone can help me out! My goal is to display an address. In the example on google, you can input it through a form: http://code.google.com/apis/maps/doc...ng-simple.html I would like the map to show the location+marker when I open the page, not after clicking a submit button. However, I only want an address in my html. I want the API to convert it in a LatLng format. Hopefully, someone can take the time to look at it. It's all in the source code of the page mentioned above, I believe. Thanks! Hi guys, I really need a custom google map, something like http://www.zeemaps.com/ offers, Where you can: Add placemarkers to a map by clicking an add button A sidebar with all locations listed Info windows when you click on markers giving you information And a couple of other features! I would really appreciate some help, spent 3 days on this now and i have: Code: <!DOCTYPE html "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"/> <title>Google Maps JavaScript API Example</title> <script src="http://maps.google.com/maps? file=api&v=2.x&key=ABQIAAAAWRAYgBXwUGsMlXv1A5Q4bBRI_5kORY0Qfu7GdhaM1xc6on2HoBT-8FUS12kkCbVXsWHjVsqeAyFq5Q&sensor=false" type="text/javascript"></script> <script type="text/javascript"> function initialize() { if (GBrowserIsCompatible()) { var map = new GMap2(document.getElementById("map_canvas")); map.setCenter(new GLatLng(54.77534585936447, -2.5927734375), 6); map.setUIToDefault(); } var publisher_id = 'ca-pub-4595198420871047'; var adsManagerOptions = { maxAdsOnMap : 4, style: G_ADSMANAGER_STYLE_ADUNIT, // The channel field is optional - replace this field with a channel number // for Google AdSense tracking //channel: 'your_channel_id' }; adsManager = new GAdsManager(map, publisher_id, adsManagerOptions); adsManager.enable(); } </script> </head> <body onload="initialize()" onunload="GUnload()"> <div id="map_canvas" style="width: 100%; height: 100%"></div> </body> </html> |