[Xerte] Trying to create a function with arguments

Paul Swanson Paul.Swanson at harlandfs.com
Wed Oct 29 15:34:49 GMT 2008


Why didn't I think of that? ;o)
 
Works perfectly, Julian.  Thanks!


________________________________

	From: xerte-bounces at lists.nottingham.ac.uk
[mailto:xerte-bounces at lists.nottingham.ac.uk] On Behalf Of Julian Tenney
	Sent: Wednesday, October 29, 2008 1:29 AM
	To: Xerte discussion list
	Subject: RE: [Xerte] Trying to create a function with arguments
	
	

	I wouldn't include all the aryEntities definitions in the
function, otherwise you are going through that code, rebuilding your
array, every time you call the function. There's no need to do that.
Instead, define the array somewhere near the top of the piece (in a
setup script is ideal, as that code will only run once, or somewhere in
the entry frame of the main framework):

	 

	myLookup = new Array();

	myLookup["&nbsp"] = "\u00A0"; 

	--etc--

	 

	Then there is no need to call a function - just lookup the value
you want:

	 

	myValue = myLookup[entity];

	 

	J

	 

	 

	From: xerte-bounces at lists.nottingham.ac.uk
[mailto:xerte-bounces at lists.nottingham.ac.uk] On Behalf Of Paul Swanson
	Sent: Tuesday, October 28, 2008 10:36 PM
	To: xerte at lists.nottingham.ac.uk
	Subject: [Xerte] Trying to create a function with arguments

	 

	I'm trying to create a function in Xerte that will display HTML
entities. The function takes the normal HTML entity name, and should
return the unicode equivalent, so I need to pass it an argument.

	From the Help, I see that Xerte does not recognize the keyword
'function' so I'm confused on how to pass it an argument. Here is the
function (found it through Google, then added some missing entities that
I think I might use someday):

	// create the entity mapping array     
	// which allows decoding html entities into their unicode
equivalents     

	function GetEntityArray(entity) { 
	    aryEntities = Array(); 
	    aryEntities[" "]   = "\u00A0"; // non-breaking space 
	    aryEntities["¡"]  = "\u00A1"; // inverted exclamation
mark 
	    aryEntities["¢"]   = "\u00A2"; // cent sign 
	    aryEntities["£"]  = "\u00A3"; // pound sign 
	    aryEntities["¤"] = "\u00A4"; // currency sign 
	    aryEntities["¥"]    = "\u00A5"; // yen sign 
	    aryEntities["€"]   = "\u20AC"; // Euro sign 
	    aryEntities["¦"] = "\u00A6"; // broken vertical bar
(|) 
	    aryEntities["§"]   = "\u00A7"; // section sign 
	    aryEntities["¨"]    = "\u00A8"; // diaeresis 
	    aryEntities["©"]   = "\u00A9"; // copyright sign 
	    aryEntities["®"]    = "\u00AE"; // registered sign 
	    aryEntities["™"]  = "\u2122"; // trademark sign 
	    aryEntities["°"]    = "\u00B0"; // degree sign 
	    aryEntities["±"] = "\u00B1"; // plus-minus sign 
	    aryEntities["¹"]   = "\u00B9"; // superscript one 
	    aryEntities["²"]   = "\u00B2"; // superscript two 
	    aryEntities["³"]   = "\u00B3"; // superscript three 
	    aryEntities["´"]  = "\u00B4"; // acute accent 
	    aryEntities["µ"]  = "\u00B5"; // micro sign 
	    aryEntities["¼"] = "\u00BC"; // vulgar fraction one
quarter 
	    aryEntities["½"] = "\u00BD"; // vulgar fraction one
half 
	    aryEntities["¾"] = "\u00BE"; // vulgar fraction three
quarters 
	    aryEntities["¿"] = "\u00BF"; // inverted question
mark 
	    aryEntities["À"] = "\u00C0"; // Latin capital letter
A with grave 
	    aryEntities["Á"] = "\u00C1"; // Latin capital letter
A with acute 
	    aryEntities["Â"]  = "\u00C2"; // Latin capital letter
A with circumflex 
	    aryEntities["Ã"] = "\u00C3"; // Latin capital letter
A with tilde 
	    aryEntities["Ä"]   = "\u00C4"; // Latin capital letter
A with diaeresis 
	    aryEntities["Å"]  = "\u00C5"; // Latin capital letter
A with ring above 
	    aryEntities["Æ"]  = "\u00C6"; // Latin capital letter
AE 
	    aryEntities["Ç"] = "\u00C7"; // Latin capital letter
C with cedilla 
	    aryEntities["È"] = "\u00C8"; // Latin capital letter
E with grave 
	    aryEntities["É"] = "\u00C9"; // Latin capital letter
E with acute 
	    aryEntities["Ê"]  = "\u00CA"; // Latin capital letter
E with circumflex 
	    aryEntities["Ë"]   = "\u00CB"; // Latin capital letter
E with diaeresis 
	    aryEntities["Ì"] = "\u00CC"; // Latin capital letter
I with grave 
	    aryEntities["Í"] = "\u00CD"; // Latin capital letter
I with acute 
	    aryEntities["Î"]  = "\u00CE"; // Latin capital letter
I with circumflex 
	    aryEntities["Ï"]   = "\u00CF"; // Latin capital letter
I with diaeresis 
	    aryEntities["Ð"]    = "\u00D0"; // Latin capital letter
ETH 
	    aryEntities["Ñ"] = "\u00D1"; // Latin capital letter
N with tilde 
	    aryEntities["Ò"] = "\u00D2"; // Latin capital letter
O with grave 
	    aryEntities["Ó"] = "\u00D3"; // Latin capital letter
O with acute 
	    aryEntities["Ô"]  = "\u00D4"; // Latin capital letter
O with circumflex 
	    aryEntities["Õ"] = "\u00D5"; // Latin capital letter
O with tilde 
	    aryEntities["Ö"]   = "\u00D6"; // Latin capital letter
O with diaeresis 
	    aryEntities["Ø"] = "\u00D8"; // Latin capital letter
O with stroke 
	    aryEntities["Ù"] = "\u00D9"; // Latin capital letter
U with grave 
	    aryEntities["Ú"] = "\u00DA"; // Latin capital letter
U with acute 
	    aryEntities["Û"]  = "\u00DB"; // Latin capital letter
U with circumflex 
	    aryEntities["Ü"]   = "\u00DC"; // Latin capital letter
U with diaeresis 
	    aryEntities["Ý"] = "\u00DD"; // Latin capital letter
Y with acute 
	    aryEntities["Þ"]  = "\u00DE"; // Latin capital letter
THORN 
	    aryEntities["ß"]  = "\u00DF"; // Latin small letter
sharp s = ess-zed 
	    aryEntities["à"] = "\u00E0"; // Latin small letter a
with grave 
	    aryEntities["á"] = "\u00E1"; // Latin small letter a
with acute 
	    aryEntities["â"]  = "\u00E2"; // Latin small letter a
with circumflex 
	    aryEntities["ã"] = "\u00E3"; // Latin small letter a
with tilde 
	    aryEntities["ä"]   = "\u00E4"; // Latin small letter a
with diaeresis 
	    aryEntities["å"]  = "\u00E5"; // Latin small letter a
with ring above 
	    aryEntities["æ"]  = "\u00E6"; // Latin small letter ae

	    aryEntities["ç"] = "\u00E7"; // Latin small letter c
with cedilla 
	    aryEntities["è"] = "\u00E8"; // Latin small letter e
with grave 
	    aryEntities["é"] = "\u00E9"; // Latin small letter e
with acute 
	    aryEntities["ê"]  = "\u00EA"; // Latin small letter e
with circumflex 
	    aryEntities["ë"]   = "\u00EB"; // Latin small letter e
with diaeresis 
	    aryEntities["ì"] = "\u00EC"; // Latin small letter i
with grave 
	    aryEntities["í"] = "\u00ED"; // Latin small letter i
with acute 
	    aryEntities["î"]  = "\u00EE"; // Latin small letter i
with circumflex 
	    aryEntities["ï"]   = "\u00EF"; // Latin small letter i
with diaeresis 
	    aryEntities["ð"]    = "\u00F0"; // Latin small letter
eth 
	    aryEntities["ñ"] = "\u00F1"; // Latin small letter n
with tilde 
	    aryEntities["ò"] = "\u00F2"; // Latin small letter o
with grave 
	    aryEntities["ó"] = "\u00F3"; // Latin small letter o
with acute 
	    aryEntities["ô"]  = "\u00F4"; // Latin small letter o
with circumflex 
	    aryEntities["õ"] = "\u00F5"; // Latin small letter o
with tilde 
	    aryEntities["ö"]   = "\u00F6"; // Latin small letter o
with diaeresis 
	    aryEntities["ø"] = "\u00F8"; // Latin small letter o
with stroke 
	    aryEntities["ù"] = "\u00F9"; // Latin small letter u
with grave 
	    aryEntities["ú"] = "\u00FA"; // Latin small letter u
with acute 
	    aryEntities["û"]  = "\u00FB"; // Latin small letter u
with circumflex 
	    aryEntities["ü"]   = "\u00FC"; // Latin small letter u
with diaeresis 
	    aryEntities["ý"] = "\u00FD"; // Latin small letter y
with acute 
	    aryEntities["þ"]  = "\u00FE"; // Latin small letter
thorn 
	    aryEntities["ÿ"]   = "\u00FF"; // Latin small letter y
with diaeresis 
	    aryEntities["–"]  = "\u2013"; // N-dash 
	    aryEntities["—"]  = "\u2014"; // M-dash 
	    aryEntities["""]   = "\u0022"; // Quotation mark 
	    aryEntities["&"]    = "\u0026"; // Ampersand 
	    aryEntities["<"]     = "\u003C"; // Less-than sign 
	    aryEntities[">"]     = "\u003E"; // Greater-than sign 
	    aryEntities["√"]  = "\u221A"; // Square root symbol 
	    aryEntities["∞"]  = "\u221E"; // Infinity symbol 
	    aryEntities["◊"]    = "\u25CA"; // Lozenge shape 
	    aryEntities["♠"] = "\u2660"; // Spade suit 
	    aryEntities["♣"]  = "\u2663"; // Club suit / shamrock 
	    aryEntities["♥"] = "\u2665"; // Heart suit /
valentine 
	    aryEntities["♦"]  = "\u2666"; // Diamond suit 
	    
	    return aryEntities[entity];     
	} 

	When I try to use the function to set a variable, I get
'undefined.' Any pointers? Incidentally, I think this would be a really
useful addition to the core Xerte.

	_____________________________ 

	 Paul Swanson 
	 Instructional Designer 
	 Harland Financial Solutions 
	 800.274.7280 Ext. 2462 
	 Paul.Swanson at harlandfs.com 
	_____________________________ 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.nottingham.ac.uk/pipermail/xerte/attachments/20081029/5b4b5313/attachment.html


More information about the Xerte mailing list