This topic has been closed. No new entries allowed.
Reason: You can now post comments on articles on Dev Opera
You need to be logged in to post in the forums. If you do not have an account, please sign up first.
JSON Configuration for JavaScript
If you're working in a web development team with developers alongside designers, and you want to give the designers an easy way to change the variable parts of the application without the risk of breaking things, an external configuration file is a great idea, and JSON (JavaScript Object Notation) is a perfect format in which to store this data. In this article, Gareth Rushgrove shows you how.( Read the article )
Small nit: "class" is a reserved word in ES, I'm not sure if any UA would actually throw an error on "Object.array[0].class" but I think it shouldn't be used like this in demo/tutorial code.
--
My blog: miscoded
Stupid code from major websites uncovered and criticised
Contribute site fixes! - OTW&TA- all sites must work
My blog: miscoded
Stupid code from major websites uncovered and criticised
Contribute site fixes! - OTW&TA- all sites must work
Opera 9.27 for Windows International (latest available) cannot load JSON script json2.js (taken from http://www.JSON.org/json2.js):
Inline script compilation
Syntax error while loading: line 181 of linked script at file://localhost/C:/TMP/json2.js :
var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17
------------------^
Other browsers (IE, FF) are working with this script library without errors. Minimal HTML page with script causing problem is:
<html>
<head>
<script type="text/javascript">
var cx=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
</script>
</head>
<body>
</body>
</html>
When I make shorter regular expression, all works fine (for example, var cx=/[\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g; is OK).
Bug report is unavailable... Have someone tested this with earlier (or latest 9.5 beta) versions of Opera?
Inline script compilation
Syntax error while loading: line 181 of linked script at file://localhost/C:/TMP/json2.js :
var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17
------------------^
Other browsers (IE, FF) are working with this script library without errors. Minimal HTML page with script causing problem is:
<html>
<head>
<script type="text/javascript">
var cx=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
</script>
</head>
<body>
</body>
</html>
When I make shorter regular expression, all works fine (for example, var cx=/[\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g; is OK).
Bug report is unavailable... Have someone tested this with earlier (or latest 9.5 beta) versions of Opera?
It seems like Opera stumbles on the 'raw' regular expression syntax.
I replaced the troublesome lines in json2.js below:
var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
escapeable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
gap,
with:
var cx = new RegExp('/[\\u0000\\u00ad\\u0600-\\u0604\\u070f\\u17b4\\u17b5\\u200c-\\u200f\\u2028-\\u202f\\u2060-\\u206f\\ufeff\\ufff0-\\uffff]/g');
var escapeable = new RegExp('/[\\\\\\"\\x00-\\x1f\\x7f-\\x9f\\u00ad\\u0600-\\u0604\\u070f\\u17b4\\u17b5\\u200c-\\u200f\\u2028-\\u202f\\u2060-\\u206f\\ufeff\\ufff0-\\uffff]/g');
var gap,
[...]
Seems to work on FF/IE/Opera so far.
Cheers.
I replaced the troublesome lines in json2.js below:
var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
escapeable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
gap,
with:
var cx = new RegExp('/[\\u0000\\u00ad\\u0600-\\u0604\\u070f\\u17b4\\u17b5\\u200c-\\u200f\\u2028-\\u202f\\u2060-\\u206f\\ufeff\\ufff0-\\uffff]/g');
var escapeable = new RegExp('/[\\\\\\"\\x00-\\x1f\\x7f-\\x9f\\u00ad\\u0600-\\u0604\\u070f\\u17b4\\u17b5\\u200c-\\u200f\\u2028-\\u202f\\u2060-\\u206f\\ufeff\\ufff0-\\uffff]/g');
var gap,
[...]
Seems to work on FF/IE/Opera so far.
Cheers.
Actually, that's almost a fix. While it does allow it to load correctly, it doesn't allow it "work" correctly.
The variable escapeable is incorrectly spelt, it should read...
Still, kudos for the fix
The variable escapeable is incorrectly spelt, it should read...
var cx = new RegExp('/[\\u0000\\u00ad\\u0600-\\u0604\\u070f\\u17b4\\u17b5\\u200c-\\u200f\\u2028-\\u202f\\u2060-\\u206f\\ufeff\\ufff0-\\uffff]/g');
var escapable = new RegExp('/[\\\\\\"\\x00-\\x1f\\x7f-\\x9f\\u00ad\\u0600-\\u0604\\u070f\\u17b4\\u17b5\\u200c-\\u200f\\u2028-\\u202f\\u2060-\\u206f\\ufeff\\ufff0-\\uffff]/g');
Still, kudos for the fix