[Mapbender-commits] r1681 - in trunk/mapbender/http: extensions
frames javascripts
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Wed Sep 26 04:11:53 EDT 2007
Author: nimix
Date: 2007-09-26 04:11:53 -0400 (Wed, 26 Sep 2007)
New Revision: 1681
Modified:
trunk/mapbender/http/extensions/json.js
trunk/mapbender/http/frames/index.php
trunk/mapbender/http/javascripts/mod_savewmc.php
Log:
put jQuery in main window
Modified: trunk/mapbender/http/extensions/json.js
===================================================================
--- trunk/mapbender/http/extensions/json.js 2007-09-25 14:46:17 UTC (rev 1680)
+++ trunk/mapbender/http/extensions/json.js 2007-09-26 08:11:53 UTC (rev 1681)
@@ -4,12 +4,13 @@
This file adds these methods to JavaScript:
- array.toJSONString()
- boolean.toJSONString()
- date.toJSONString()
- number.toJSONString()
- object.toJSONString()
- string.toJSONString()
+ toJSONString(obj)
+ arrayToJSONString(obj)
+ booleanToJSONString(obj)
+ dateToJSONString(obj)
+ numberToJSONString(obj)
+ objectToJSONString(obj)
+ stringToJSONString(obj)
These methods produce a JSON text from a JavaScript value.
It must not contain any cyclical references. Illegal values
will be excluded.
@@ -18,7 +19,7 @@
add a toJSONString method to any date object to get a different
representation.
- string.parseJSON(filter)
+ parseJSON(string, filter)
This method parses a JSON text to produce an object or
array. It can throw a SyntaxError exception.
@@ -41,153 +42,173 @@
JavaScript Programming Language in the Fourth Edition of the
ECMAScript standard in 2007.
*/
-if (!Object.prototype.toJSONString) {
- Array.prototype.toJSONString = function () {
- var a = ['['], b, i, l = this.length, v;
+function arrayToJSONString(ao){
+ var a = ['['], b, i, l = ao.length, v;
+
+ function p(s) {
+ if (b) {
+ a.push(',');
+ }
+ a.push(s);
+ b = true;
+ }
- function p(s) {
- if (b) {
- a.push(',');
- }
- a.push(s);
- b = true;
- }
+ for (i = 0; i < l; i += 1) {
+ v = ao[i];
+ switch (typeof v) {
+ case 'undefined':
+ case 'function':
+ case 'unknown':
+ break;
+ case 'object':
+ if (v) {
+ p(toJSONString(v));
+ } else {
+ p("null");
+ }
+ break;
+ default:
+ p(toJSONString(v));
+ }
+ }
+ a.push(']');
+ return a.join('');
+}
+function boolToJSONString(bo) {
+ return String(bo);
+};
- for (i = 0; i < l; i += 1) {
- v = this[i];
- switch (typeof v) {
- case 'undefined':
- case 'function':
- case 'unknown':
- break;
- case 'object':
- if (v) {
- if (typeof v.toJSONString === 'function') {
- p(v.toJSONString());
- }
- } else {
- p("null");
- }
- break;
- default:
- p(v.toJSONString());
- }
- }
- a.push(']');
- return a.join('');
- };
+function dateToJSONString(dao) {
+ function f(n) {
+ return n < 10 ? '0' + n : n;
+ }
- Boolean.prototype.toJSONString = function () {
- return String(this);
- };
+ return '"' + dao.getFullYear() + '-' +
+ f(dao.getMonth() + 1) + '-' +
+ f(dao.getDate()) + 'T' +
+ f(dao.getHours()) + ':' +
+ f(dao.getMinutes()) + ':' +
+ f(dao.getSeconds()) + '"';
+};
+
+function numberToJSONString(no) {
+ return isFinite(no) ? String(no) : "null";
+};
- Date.prototype.toJSONString = function () {
-
- function f(n) {
- return n < 10 ? '0' + n : n;
- }
-
- return '"' + this.getFullYear() + '-' +
- f(this.getMonth() + 1) + '-' +
- f(this.getDate()) + 'T' +
- f(this.getHours()) + ':' +
- f(this.getMinutes()) + ':' +
- f(this.getSeconds()) + '"';
- };
-
- Number.prototype.toJSONString = function () {
- return isFinite(this) ? String(this) : "null";
- };
-
- Object.prototype.toJSONString = function () {
+function objectToJSONString(ob) {
- var a = ['{'], b, i, v;
+ var a = ['{'], b, i, v;
- function p(s) {
- if (b) {
- a.push(',');
- }
- a.push(i.toJSONString(), ':', s);
- b = true;
- }
+ function p(s) {
+ if (b) {
+ a.push(',');
+ }
+ a.push(toJSONString(i), ':', s);
+ b = true;
+ }
- for (i in this) {
- if (this.hasOwnProperty(i)) {
- v = this[i];
- switch (typeof v) {
- case 'undefined':
- case 'function':
- case 'unknown':
- break;
- case 'object':
- if (v) {
- if (typeof v.toJSONString === 'function') {
- p(v.toJSONString());
- }
- } else {
- p("null");
- }
- break;
- default:
- p(v.toJSONString());
- }
- }
- }
- a.push('}');
- return a.join('');
- };
+ for (i in ob) {
+ if (ob.hasOwnProperty(i)) {
+ v = ob[i];
+ switch (typeof v) {
+ case 'undefined':
+ case 'function':
+ case 'unknown':
+ break;
+ case 'object':
+ if (v) {
+ p(toJSONString(v));
+ } else {
+ p("null");
+ }
+ break;
+ default:
+ p(toJSONString(v));
+ }
+ }
+ }
+ a.push('}');
+ return a.join('');
+};
+function stringToJSONString(so){
+ var m = {
+ '\b': '\\b',
+ '\t': '\\t',
+ '\n': '\\n',
+ '\f': '\\f',
+ '\r': '\\r',
+ '"' : '\\"',
+ '\\': '\\\\'
+ };
+ if (/["\\\x00-\x1f]/.test(so)) {
+ return '"' + so.replace(/([\x00-\x1f\\"])/g, function(a, b) {
+ var c = m[b];
+ if (c) {
+ return c;
+ }
+ c = b.charCodeAt();
+ return '\\u00' +
+ Math.floor(c / 16).toString(16) +
+ (c % 16).toString(16);
+ }) + '"';
+ }
+ return '"' + so + '"';
+}
- (function (s) {
- var m = {
- '\b': '\\b',
- '\t': '\\t',
- '\n': '\\n',
- '\f': '\\f',
- '\r': '\\r',
- '"' : '\\"',
- '\\': '\\\\'
- };
+function toJSONString(o){
+ switch(typeof o){
+ case 'undefined':
+ case 'function':
+ case 'unknown':
+ break;
+ case 'object':
+ if (o.constructor == Array){
+ return arrayToJSONString(o);
+ }else if(o.constructor == Date){
+ return dateToJSONString(o);
+ }else{
+ return objectToJSONString(o);
+ }
+ case 'number':
+ return numberToJSONString(o);
+ case 'string':
+ return stringToJSONString(o);
+ case 'boolean':
+ return boolToJSONString(o);
+ }
+}
- s.parseJSON = function (filter) {
- try {
- if (/^("(\\.|[^"\\\n\r])*?"|[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t])+?$/.
- test(this)) {
- var j = eval('(' + this + ')');
- if (typeof filter === 'function') {
- function walk(k, v) {
- if (v && typeof v === 'object') {
- for (var i in v) {
- if (v.hasOwnProperty(i)) {
- v[i] = walk(i, v[i]);
- }
- }
- }
- return filter(k, v);
- }
- return walk('', j);
- }
- return j;
- }
- } catch (e) {
- }
- throw new SyntaxError("parseJSON");
- };
-
- s.toJSONString = function () {
- if (/["\\\x00-\x1f]/.test(this)) {
- return '"' + this.replace(/([\x00-\x1f\\"])/g, function(a, b) {
- var c = m[b];
- if (c) {
- return c;
- }
- c = b.charCodeAt();
- return '\\u00' +
- Math.floor(c / 16).toString(16) +
- (c % 16).toString(16);
- }) + '"';
- }
- return '"' + this + '"';
- };
- })(String.prototype);
+function parseJSON(so, filter){
+ var m = {
+ '\b': '\\b',
+ '\t': '\\t',
+ '\n': '\\n',
+ '\f': '\\f',
+ '\r': '\\r',
+ '"' : '\\"',
+ '\\': '\\\\'
+ };
+ try {
+ if (/^("(\\.|[^"\\\n\r])*?"|[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t])+?$/.
+ test(so)) {
+ var j = eval('(' + so + ')');
+ if (typeof filter === 'function') {
+ function walk(k, v) {
+ if (v && typeof v === 'object') {
+ for (var i in v) {
+ if (v.hasOwnProperty(i)) {
+ v[i] = walk(i, v[i]);
+ }
+ }
+ }
+ return filter(k, v);
+ }
+ return walk('', j);
+ }
+ return j;
+ }
+ } catch (e) {
+ }
+ throw new SyntaxError("parseJSON");
}
\ No newline at end of file
Modified: trunk/mapbender/http/frames/index.php
===================================================================
--- trunk/mapbender/http/frames/index.php 2007-09-25 14:46:17 UTC (rev 1680)
+++ trunk/mapbender/http/frames/index.php 2007-09-26 08:11:53 UTC (rev 1681)
@@ -77,7 +77,7 @@
?>
-->
</style>
-
+<script type='text/javascript' src="../extensions/jquery.js"></script>
<script type='text/javascript' src="../extensions/json.js"></script>
<script type='text/javascript' src="../javascripts/point.js"></script>
<script type='text/javascript' src="../javascripts/map_obj.js"></script>
Modified: trunk/mapbender/http/javascripts/mod_savewmc.php
===================================================================
--- trunk/mapbender/http/javascripts/mod_savewmc.php 2007-09-25 14:46:17 UTC (rev 1680)
+++ trunk/mapbender/http/javascripts/mod_savewmc.php 2007-09-26 08:11:53 UTC (rev 1681)
@@ -63,7 +63,7 @@
var ind = getMapObjIndexByName(mod_savewmc_target);
var generalTitle = "session";
window.frames['ajax'].$.ajaxSetup({async:false}); //TODO: find out why async doesn't work sometimes
- window.frames['ajax'].$.post("../php/mod_insertWmcIntoDb.php", {"saveInSession":1, "generalTitle":generalTitle, "mapObject":mb_mapObj[ind].toJSONString()}, function (result, status) {
+ window.frames['ajax'].$.post("../php/mod_insertWmcIntoDb.php", {"saveInSession":1, "generalTitle":generalTitle, "mapObject":toJSONString(mb_mapObj[ind])}, function (result, status) {
});
}
@@ -78,7 +78,7 @@
generalTitle = prompt("Save WMC as...");
}
window.frames['ajax'].$.ajaxSetup({async:false}); //TODO: find out why async doesn't work onunload
- window.frames['ajax'].$.post("../php/mod_insertWmcIntoDb.php", {"saveInSession":0, "generalTitle":generalTitle, "mapObject":mb_mapObj[ind].toJSONString()}, function (result, status) {
+ window.frames['ajax'].$.post("../php/mod_insertWmcIntoDb.php", {"saveInSession":0, "generalTitle":generalTitle, "mapObject":toJSONString(mb_mapObj[ind])}, function (result, status) {
alert(status + ": " + result);
});
}
\ No newline at end of file
More information about the Mapbender_commits
mailing list