The suffixes use the same Greco-Roman names almost universally. In this case, to add additional languages, there should be much translating needed. We need to add our new words into the localization files so they display nicely. Most Mac applications have a system to aid is language translations. We're not done yet, but it's always a good idea to save as we go. Save your work by Selecting "Save" under the File menu. I've attached a text file with the lines to paste into the Javascript so you don't need to mess with tabs to format it back into a readable format. All of the above code is formated for Web display. It tells Javascript that another entry follows. It's okay though, because we need it there now. That was an uncritical syntax error in the original code. var Numeric = [ Note that there is already a comma after the squiggly-bracket at the end of the Volume entry. Either way, do closely examine how the data is formated and why they will make the appropriate conversions. You can also just type in the data as presented. Here, you may prefer to copy and paste to avoid syntax errors. This is where we will insert our Numeric conversions. Keep scrolling to find the end of Time (sounds like a SciFi novel. The two forms indicate wether we need to multiply or divide to get there and if that item is the From or To value. All the other items in that array is given a value representing the difference from the base value. Each section contains one item that is given the value of '1.0'. These variables contain the information necessary to make the conversions in each of the conversion selections. As you scroll through the listing, you'll notice a few short routines and a long list of variables starting with 'var'. Select the Conversions.js in the files area and note that the Source Code automatically appears in the lower right pane. The only place we will need to add code is in Conversions.js. Since numbers are already handled well in this utility, we can probably assume we don't need to make changes in parser.js. In this case, we want an additional conversion that will convert numbers according to the suffix used. The Conversions scripts are the actual equations used to make the conversions. The additional scripts in this widget are "parser.js" and Conversions.js." The parser scripts are for interpreting our human input into a format the math equations can use and then translating the results into a format that you and I can read. A more complex widget, such as this one, will contain additional scripts for complex operations and, of course, all the cool graphics that make it pretty. Any changes we make in that area, will reflect in these files. They contain the general layout of the widget as defined in the GUI section of Dashcode. These are really all that are necessary for your basic widget. They include an web document (html), a style sheet (css) and a script (js). Notice the files with the same name as our widget, "Unit Converter +". This will open a new devision in the window showing us the files that make up this widget. Under the 'View' menu icon, select the 'Files' option. Just try to understand how the program does what it does. Also take note of the other support files and what they contain. Examine how the various JavaScript (js) files interact. Take your time and examine everything in the Widget. Before we start messing with the code, it's a good idea to try to understand what we're messing with. Never (And I mean NEVER!) work with the original. What we now have before us is an exact duplicate of Apple's original Unit Converter Widget with a new name. Well, let's see if the Unit Converter can answer that. I'm confronted frequently by people that just can't understand why that 10GB Hard drive they just purchased has less than 9.5GB. Now, where it's lacking, is that it doesn't do Numeric conversions. Just accept the exact results and do your own rounding as needed. With any rounding, you'd end up with screwed up results. Yea, it could have rounded this to 252 calories, but that would end up corrupting the data if you chose to then convert those Calories to Joules and then back to BTUs. You're immediately told that it's 251.99576 calories. Ever wonder how many BTUs (British Thermal Units) make up a Calorie? Just pull up the Unit Converter, select the Energy catagory, the BTU and Calories sub-catagories and enter '1' into the BTU area. It makes just about any conversion from and to related units. In the case of the Unit Converter, what it does, it does beautifully. It's a mater of understanding what the Widget does and then add to that. Customizing a Mac OS X Widget might seem a daunting task.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |