[Mapbender-commits] r5970 - trunk/mapbender/lib
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Fri Apr 16 11:32:53 EDT 2010
Author: christoph
Date: 2010-04-16 11:32:53 -0400 (Fri, 16 Apr 2010)
New Revision: 5970
Modified:
trunk/mapbender/lib/basic.js
Log:
easyform and file_exists
Modified: trunk/mapbender/lib/basic.js
===================================================================
--- trunk/mapbender/lib/basic.js 2010-04-16 15:32:17 UTC (rev 5969)
+++ trunk/mapbender/lib/basic.js 2010-04-16 15:32:53 UTC (rev 5970)
@@ -200,6 +200,30 @@
return "?";
};
+Mapbender.phpjs = {
+ "file_exists": function (url) {
+ // http://kevin.vanzonneveld.net
+ // + original by: Enrique Gonzalez
+ // + input by: Jani Hartikainen
+ // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
+ // % note 1: This function uses XmlHttpRequest and cannot retrieve resource from different domain.
+ // % note 1: Synchronous so may lock up browser, mainly here for study purposes.
+ // * example 1: file_exists('http://kevin.vanzonneveld.net/pj_test_supportfile_1.htm');
+ // * returns 1: '123'
+
+ var req = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
+ if (!req) {throw new Error('XMLHttpRequest not supported');}
+
+ // HEAD Results are usually shorter (faster) than GET
+ req.open('HEAD', url, false);
+ req.send(null);
+ if (req.status == 200){
+ return true;
+ }
+
+ return false;
+ }
+};
Mapbender.sprintf = function () {
// http://kevin.vanzonneveld.net
@@ -350,3 +374,43 @@
return format.replace(regex, doFormat);
};
+/**
+ * form filling and serializing
+ */
+$.fn.easyform = function (obj) {
+ if (typeof obj !== "string" && typeof obj !== "object") {
+ return this;
+ }
+ var data = typeof obj === "object" && obj.data ? obj.data : {};
+ var command = typeof obj === "string" ? obj : "";
+
+ switch (command) {
+ case "serialize":
+ var f = $(this).serializeArray();
+ var r = {};
+ for (var i in f) {
+ r[f[i].name] = f[i].value;
+ }
+ return r;
+ case "fill":
+ data = arguments.length > 1 &&
+ typeof arguments[1] === "object" ? arguments[1] : {};
+ break;
+ case "reset":
+ this.each(function () {
+ this.reset();
+ });
+ break;
+
+ }
+
+ return this.each(function () {
+ if (data) {
+ for (var i in data) {
+ $(this[i]).val(data[i]);
+ }
+ return;
+ }
+
+ });
+};
More information about the Mapbender_commits
mailing list