[Mapbender-commits] r2538 - trunk/mapbender/lib
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Mon Jun 23 11:57:43 EDT 2008
Author: christoph
Date: 2008-06-23 11:57:43 -0400 (Mon, 23 Jun 2008)
New Revision: 2538
Added:
trunk/mapbender/lib/alignButton.js
trunk/mapbender/lib/basic.js
trunk/mapbender/lib/button.js
trunk/mapbender/lib/buttonNew.js
trunk/mapbender/lib/draggableButton.js
trunk/mapbender/lib/resizableButton.js
trunk/mapbender/lib/saveButton.js
trunk/mapbender/lib/selectableButton.js
Log:
Added: trunk/mapbender/lib/alignButton.js
===================================================================
--- trunk/mapbender/lib/alignButton.js (rev 0)
+++ trunk/mapbender/lib/alignButton.js 2008-06-23 15:57:43 UTC (rev 2538)
@@ -0,0 +1,99 @@
+var Align = {
+ top : {
+ buttonParameters : {
+ on:"../img/button_blink_red/up_on.png",
+ over:"../img/button_blink_red/up_on.png",
+ off:"../img/button_blink_red/up_off.png",
+ type:"singular"
+ },
+ align : function () {
+ if ($(".ui-selected").size() < 2) {
+ return false;
+ }
+ var minY;
+ $(".ui-selected").each(function() {
+ var currentMinY = parseInt(this.style.top);
+ if ((!minY && minY !== 0 ) || currentMinY < minY) {
+ minY = currentMinY;
+ }
+ });
+ $(".ui-selected").each(function() {
+ this.style.top = minY + "px";
+ });
+ }
+ },
+ left : {
+ buttonParameters : {
+ on:"../img/button_blink_red/back_on.png",
+ over:"../img/button_blink_red/back_on.png",
+ off:"../img/button_blink_red/back_off.png",
+ type:"singular"
+ },
+ align : function () {
+ if ($(".ui-selected").size() < 2) {
+ return false;
+ }
+ var minX;
+ $(".ui-selected").each(function() {
+ var currentMinX = parseInt(this.style.left);
+ if ((!minX && minX !== 0 ) || currentMinX < minX) {
+ minX = currentMinX;
+ }
+ });
+
+ $(".ui-selected").each(function() {
+ this.style.left = minX + "px";
+ });
+ }
+ },
+ bottom : {
+ buttonParameters : {
+ on:"../img/button_blink_red/down_on.png",
+ over:"../img/button_blink_red/down_on.png",
+ off:"../img/button_blink_red/down_off.png",
+ type:"singular"
+ },
+ align : function () {
+ if ($(".ui-selected").size() < 2) {
+ return false;
+ }
+ var maxY;
+ $(".ui-selected").each(function() {
+ var currentMaxY = parseInt(this.style.top) + parseInt(this.style.height);
+ if ((!maxY && maxY !== 0) || currentMaxY > maxY) {
+ maxY = currentMaxY;
+ }
+ });
+
+ $(".ui-selected").each(function() {
+ var newY = maxY - parseInt(this.style.height);
+ this.style.top = newY + "px";
+ });
+ }
+ },
+ right : {
+ buttonParameters : {
+ on:"../img/button_blink_red/forward_on.png",
+ over:"../img/button_blink_red/forward_on.png",
+ off:"../img/button_blink_red/forward_off.png",
+ type:"singular"
+ },
+ align : function () {
+ if ($(".ui-selected").size() < 2) {
+ return false;
+ }
+ var maxX;
+ $(".ui-selected").each(function() {
+ var currentMaxX = parseInt(this.style.left) + parseInt(this.style.width);
+ if ((!maxX && maxX !== 0) || currentMaxX > maxX) {
+ maxX = currentMaxX;
+ }
+ });
+
+ $(".ui-selected").each(function() {
+ var newX = maxX - parseInt(this.style.width);
+ this.style.left = newX + "px";
+ });
+ }
+ }
+}
\ No newline at end of file
Added: trunk/mapbender/lib/basic.js
===================================================================
--- trunk/mapbender/lib/basic.js (rev 0)
+++ trunk/mapbender/lib/basic.js 2008-06-23 15:57:43 UTC (rev 2538)
@@ -0,0 +1,117 @@
+var ie = document.all?1:0;
+var n6 = document.getElementById&&!document.all?1:0;
+var n4 = document.layers?1:0;
+
+var clickX;
+var clickY;
+
+var mb_log = null;
+
+
+// transparent GIF
+var mb_trans = new Image();
+mb_trans.src = "../img/transparent.gif";
+
+/*
+ * get the conjunction character of an URL
+ * @param {String} onlineresource
+ * @return the character & or ?
+ * @type String
+ */
+function mb_getConjunctionCharacter(onlineresource){
+ var conChar;
+ if(onlineresource.indexOf("?") > -1){
+ if(onlineresource.charAt(onlineresource.length-1) == "?"){
+ conChar = "";
+ }else if(onlineresource.charAt(onlineresource.length-1) == "&"){
+ conChar = "";
+ }else{
+ conChar = "&";
+ }
+ }
+ if(onlineresource.indexOf("?") == -1){
+ conChar = "?";
+ }
+ return conChar;
+}
+
+function mb_showHighlight(frameName,x,y){
+ var pos = makeRealWorld2mapPos(frameName,x, y);
+ mb_arrangeElement(frameName,"highlight",pos[0]-7, pos[1]-7);
+ window.frames[frameName].document.getElementById("highlight").style.visibility = 'visible';
+}
+function mb_hideHighlight(frameName){
+ mb_arrangeElement(frameName,"highlight",-20, -20);
+ mb_arrangeElement(frameName,"highlight",-20, -20);
+ window.frames[frameName].document.getElementById("highlight").style.visibility = 'hidden';
+}
+
+function cloneObject(obj) {
+ if (typeof obj !== 'object' || obj === null) {
+ return obj;
+ }
+ var c = obj instanceof Array ? [] : {};
+ for (var i in obj) {
+ var prop = obj[i];
+ if (typeof prop == 'object') {
+ if (prop instanceof Array) {
+ c[i] = [];
+ for (var j = 0; j < prop.length; j++) {
+ if (typeof prop[j] != 'object') {
+ c[i].push(prop[j]);
+ } else {
+ c[i].push(cloneObject(prop[j]));
+ }
+ }
+ } else {
+ c[i] = cloneObject(prop);
+ }
+ } else {
+ c[i] = prop;
+ }
+ }
+ return c;
+}
+
+function mb_timestamp(){
+ var d = new Date();
+ var ts = Math.round(Date.parse(d)/1000);
+ return ts;
+}
+
+function mb_getMousePos(e,fName){
+if(fName){
+ if(ie){
+ clickX = window.frames[fName].event.clientX;
+ clickY = window.frames[fName].event.clientY;
+ }
+ else{
+ clickX = e.pageX;
+ clickY = e.pageY;
+ }
+ }
+ else{
+ if(ie){
+ clickX = event.clientX;
+ clickY = event.clientY;
+ }
+ else{
+ clickX = e.pageX;
+ clickY = e.pageY;
+ }
+ }
+ var pos = [clickX,clickY];
+ return pos;
+}
+
+function mb_arrangeElement(frameName, elName, left, top) {
+ if(frameName !== ""){
+ window.frames[frameName].document.getElementById(elName).style.top = top;
+ window.frames[frameName].document.getElementById(elName).style.left = left;
+ }
+ else{
+ document.getElementById(elName).style.top = top;
+ document.getElementById(elName).style.left = left;
+ }
+}
+
Added: trunk/mapbender/lib/button.js
===================================================================
--- trunk/mapbender/lib/button.js (rev 0)
+++ trunk/mapbender/lib/button.js 2008-06-23 15:57:43 UTC (rev 2538)
@@ -0,0 +1,148 @@
+/*
+ ***************************************************************************************
+ * button handling
+ ***************************************************************************************
+ */
+
+var mb_button = [];
+
+function mb_regButton_frame(wii, frameName, param){
+ var ind = mb_button.length;
+ mb_button[ind] = new mb_conButton(wii, ind);
+ if (frameName === null) {
+ if (param === null) {
+ eval(wii+"("+ind+")");
+ }
+ else {
+ eval(wii+"("+ind+", "+param+")");
+ }
+ }
+ else if (param === null) {
+ eval("window.frames['" + frameName + "']."+wii+"("+ind+")");
+ }
+ else {
+ eval("window.frames['" + frameName + "']."+wii+"("+ind+", "+param+")");
+ }
+ mb_button[ind].prev = mb_button[ind].src;
+ mb_button[ind].src = mb_button[ind].img_off;
+ mb_button[ind].onmouseover = function () {
+ mb_button_over(ind);
+ };
+ mb_button[ind].onmouseout = function(){
+ mb_button_out(ind);
+ };
+ mb_button[ind].onclick = function(){
+ mb_button_click(ind);
+ };
+ if (frameName === null) {
+ mb_button[ind].frameName = "";
+ }
+ else {
+ mb_button[ind].frameName = frameName;
+ }
+}
+
+function mb_regButton(wii){
+ mb_regButton_frame(wii, null, null);
+}
+
+function mb_conButton(wii, ind){
+ this.wii = wii;
+ return true;
+}
+function mb_button_over(ind){
+ if(mb_button[ind].status === 0){
+ mb_button[ind].prev = mb_button[ind].src;
+ mb_button[ind].src = mb_button[ind].img_over;
+ }
+}
+function mb_button_out(ind){
+ mb_button[ind].src = mb_button[ind].prev;
+}
+function mb_button_click(ind){
+ var mbStatus = mb_button[ind].status;
+ if(mbStatus === 0){
+ mb_disableButton(mb_button[ind].elName);
+ mb_button[ind].prev = mb_button[ind].img_on;
+ mb_button[ind].src = mb_button[ind].img_on;
+ mb_button[ind].status = 1;
+ if (mb_button[ind].frameName !== "") {
+ window.frames[mb_button[ind].frameName].document.getElementById(mb_button[ind].elName).go();
+ }
+ else {
+ document.getElementById(mb_button[ind].elName).go();
+ }
+ }
+ else{
+ mb_button[ind].prev = mb_button[ind].img_off;
+ mb_button[ind].src = mb_button[ind].img_off;
+ mb_button[ind].status = 0;
+ if (mb_button[ind].frameName !== "") {
+ window.frames[mb_button[ind].frameName].document.getElementById(mb_button[ind].elName).stop();
+ }
+ else {
+ document.getElementById(mb_button[ind].elName).stop();
+ }
+ }
+}
+function mb_disableButton(elName){
+ for(var i=0; i<mb_button.length; i++){
+ if(mb_button[i].elName != elName && mb_button[i].status == 1){
+ mb_button[i].status = 0;
+ if (mb_button[i].frameName !== "") {
+ window.frames[mb_button[i].frameName].document.getElementById(mb_button[i].elName).src = mb_button[i].img_off;
+ window.frames[mb_button[i].frameName].document.getElementById(mb_button[i].elName).stop();
+ }
+ else {
+ document.getElementById(mb_button[i].elName).src = mb_button[i].img_off;
+ document.getElementById(mb_button[i].elName).stop();
+ }
+ return true;
+
+ }
+ }
+}
+function mb_disableThisButton(elName){
+ for(var i=0; i<mb_button.length; i++){
+ if(mb_button[i].elName == elName && mb_button[i].status == 1){
+ //alert(mb_button[i].elName);
+ mb_button[i].status = 0;
+ if (mb_button[i].frameName !== "") {
+ window.frames[mb_button[i].frameName].document.getElementById(mb_button[i].elName).src = mb_button[i].img_off;
+ window.frames[mb_button[i].frameName].document.getElementById(mb_button[i].elName).stop();
+ }
+ else {
+ document.getElementById(mb_button[i].elName).src = mb_button[i].img_off;
+ document.getElementById(mb_button[i].elName).stop();
+ }
+ return true;
+
+ }
+ }
+}
+function updateButtonTooltips(obj) {
+ // this one only changes those in the main frame
+ var imageArray = document.getElementsByTagName("img");
+ for (var i = 0; i < imageArray.length; i++) {
+ for(var j=0; j<obj.length; j++){
+ if (imageArray[i].id == obj[j].id) {
+ document.getElementById(imageArray[i].id).title = obj[j].title;
+ }
+ }
+ }
+}
+
+function mb_localizeButtons(){
+ mb_ajax_json("../php/mod_button_tooltips.php", function(obj, status){
+ updateButtonTooltips(obj);
+ });
+}
+
+eventLocalize.register(function () {
+ mb_localizeButtons();
+});
+
+eventInit.register(function () {
+ mb_localizeButtons();
+});
+
Added: trunk/mapbender/lib/buttonNew.js
===================================================================
--- trunk/mapbender/lib/buttonNew.js (rev 0)
+++ trunk/mapbender/lib/buttonNew.js 2008-06-23 15:57:43 UTC (rev 2538)
@@ -0,0 +1,129 @@
+
+/**
+ * A group of buttons.
+ */
+function ButtonGroup (nodeId) {
+ var buttonArray = [];
+ var node = "#" + nodeId;
+
+ this.add = function (button) {
+ if (!button.constructor == "Button") {
+ console.log("not a button, but a %s", button.constructor);
+ return false;
+ }
+ if (button.type == "toggle") {
+ for (var i = 0; i < buttonArray.length; i++) {
+ var currentButton = buttonArray[i];
+ currentButton.registerPush(button.triggerStop);
+ button.registerPush(currentButton.triggerStop);
+ }
+ }
+ else if (button.type == "singular") {
+ button.registerPush(button.triggerStop);
+ }
+ buttonArray.push(button);
+ $(node).append(button.getNode());
+ }
+}
+
+
+function Button (options) {
+ //
+ // API
+ //
+ this.registerStart = function (func) {
+ start.register(func);
+ };
+
+ this.registerStop = function (func) {
+ stop.register(func);
+ };
+
+ this.registerPush = function (func) {
+ push.register(func);
+ };
+
+ this.registerRelease = function (func) {
+ release.register(func);
+ };
+
+ this.triggerStart = function () {
+ start.trigger();
+ };
+
+ this.triggerStop = function () {
+ stop.trigger();
+ };
+
+ this.triggerPush = function () {
+ push.trigger();
+ };
+
+ this.triggerRelease = function () {
+ release.trigger();
+ };
+
+ this.getNode = function () {
+ return $node;
+ };
+
+ //
+ // constructor
+ //
+ /**
+ * Is triggered if the button is pushed, may
+ * also be triggered by other actions.
+ * Changes the button image source.
+ */
+ var start = new MapbenderEvent();
+ /**
+ * Is triggered if the button is released, may
+ * also be triggered by other actions.
+ * Changes the button image source.
+ */
+ var stop = new MapbenderEvent();
+ /**
+ * Is only called after the button has been
+ * manually pushed by the user.
+ * Triggers "start".
+ */
+ var push = new MapbenderEvent();
+
+ /**
+ * Is only called after the button has been
+ * manually released by the user.
+ * Triggers "stop".
+ */
+ var release = new MapbenderEvent();
+
+ start.register(function() {
+ isOn = true;
+ $node.attr("src", srcOn);
+ });
+
+ stop.register(function() {
+ $node.attr("src", srcOff);
+ isOn = false;
+ });
+
+ push.register(function() {
+ start.trigger();
+ });
+
+ release.register(function() {
+ stop.trigger();
+ });
+
+ var srcOn = (options.on) ? options.on : null;
+ var srcOff = (options.off) ? options.off : null;
+ var srcOver = (options.over) ? options.over : null;
+ this.type = (options.type) ? options.type : "default";
+
+ var $node = $("<img style='padding:5px' src='" + srcOff + "'/>");
+ var isOn = false;
+
+ $node.click(function() {
+ (!isOn) ? push.trigger() : release.trigger();
+ });
+}
+
Added: trunk/mapbender/lib/draggableButton.js
===================================================================
--- trunk/mapbender/lib/draggableButton.js (rev 0)
+++ trunk/mapbender/lib/draggableButton.js 2008-06-23 15:57:43 UTC (rev 2538)
@@ -0,0 +1,98 @@
+var Draggable = {
+ buttonParameters : {
+ on:"../img/button_blink_red/pan_on.png",
+ over:"../img/button_blink_red/pan_over.png",
+ off:"../img/button_blink_red/pan_off.png",
+ type:"toggle"
+ },
+ grid : [7,7],
+ makeDraggable : function() {
+
+ var $selection = $(".ui-selected");
+ if ($selection.size() > 0) {
+
+ // if elements have been selected, we want to drag
+ // them together, not individually. So we move these
+ // elements into a new div tag, and make that tag
+ // draggable
+
+ Draggable.moveSelectionToDiv();
+
+ $(".div-draggable").draggable({
+ grid:Draggable.grid
+ });
+ }
+ else {
+ $(".collection").children().draggable({
+ grid:Draggable.grid
+ });
+ }
+ },
+ removeDraggable : function () {
+ if ($(".ui-selected").size() > 0) {
+ Draggable.moveSelectionFromDiv();
+ }
+ $(".collection").children().draggable("destroy");
+ },
+ moveSelectionFromDiv : function () {
+ var divX, divY;
+ var $draggableDiv = $(".div-draggable");
+ $draggableDiv.each(function() {
+ divX = parseInt(this.style.left);
+ divY = parseInt(this.style.top);
+ });
+ $draggableDiv.children().each(function() {
+ var newX = parseInt(this.style.left) + divX;
+ var newY = parseInt(this.style.top) + divY;
+ this.style.left = newX + "px";
+ this.style.top = newY + "px";
+ $(this).removeClass("ui-selectee");
+ $(this).removeClass("ui-selected");
+ $(this).addClass("div-border");
+ $clone = $(this).clone();
+ $(".collection").append($clone);
+ });
+ $draggableDiv.remove();
+ },
+ moveSelectionToDiv : function () {
+ // first, put all selected elements inside a
+ // single div tag; then, make that div tag
+ // draggable
+
+ // the coordinates of the new div tag need
+ // to be computed first
+ var minX, minY;
+ $(".ui-selected").each(function() {
+ var currentLeft = parseInt(this.style.left);
+ if ((!minX && minX !== 0) || currentLeft < minX) {
+ minX = currentLeft;
+ }
+ var currentTop = parseInt(this.style.top);
+ if ((!minY && minY !== 0) || currentTop < minY) {
+ minY = currentTop;
+ }
+ });
+
+ var $div = $("<div class='div-draggable'></div>");
+ $div.css("position", "absolute");
+ $div.css("top", minY);
+ $div.css("left", minX);
+
+ // to move the selected nodes, we clone them and attach
+ // them to the new div. the old tags are removed
+ $(".ui-selected").each(function() {
+ var newX = parseInt(this.style.left) - minX;
+ var newY = parseInt(this.style.top) - minY;
+
+ $clone = $(this).clone();
+ $clone.css("position", "absolute");
+ $clone.css("top", newY + "px");
+ $clone.css("left", newX + "px");
+
+ $div.append($clone);
+ $(this).remove();
+ });
+
+ $div.appendTo($(".collection"));
+ }
+}
Added: trunk/mapbender/lib/resizableButton.js
===================================================================
--- trunk/mapbender/lib/resizableButton.js (rev 0)
+++ trunk/mapbender/lib/resizableButton.js 2008-06-23 15:57:43 UTC (rev 2538)
@@ -0,0 +1,18 @@
+var Resizable = {
+ buttonParameters : {
+ on:"../img/button_blink_red/select_rectangle_on.png",
+ over:"../img/button_blink_red/select_rectangle_over.png",
+ off:"../img/button_blink_red/select_rectangle_off.png",
+ type:"toggle"
+ },
+ makeResizable : function () {
+ var selector = ".collection > div";
+ $all = $(selector);
+ $all.resizable();
+ },
+ removeResizable : function () {
+ var selector = ".collection > div";
+ $all = $(selector);
+ $all.resizable("destroy");
+ }
+};
Added: trunk/mapbender/lib/saveButton.js
===================================================================
--- trunk/mapbender/lib/saveButton.js (rev 0)
+++ trunk/mapbender/lib/saveButton.js 2008-06-23 15:57:43 UTC (rev 2538)
@@ -0,0 +1,34 @@
+var Save = {
+ buttonParameters : {
+ on:"../img/button_blink_red/wmc_save_on.png",
+ over:"../img/button_blink_red/wmc_save_over.png",
+ off:"../img/button_blink_red/wmc_save_off.png",
+ type:"toggle"
+ },
+ updateDatabase : function (callback) {
+ var data = [];
+ $(".collection").children().each(function() {
+ data.push({
+ id:this.id,
+ top:parseInt(this.style.top),
+ left:parseInt(this.style.left),
+ width:parseInt(this.style.width),
+ height:parseInt(this.style.height)
+ });
+ });
+ var queryObj = {
+ command:"update",
+ parameters:{
+ applicationId:editApplicationId,
+ data:data
+ }
+ };
+ $.post("mod_editApplication_server.php", {
+ queryObj:$.toJSON(queryObj)
+ }, function (json, status) {
+ var replyObj = eval('(' + json + ')');
+ alert(replyObj.success);
+ callback();
+ });
+ }
+};
Added: trunk/mapbender/lib/selectableButton.js
===================================================================
--- trunk/mapbender/lib/selectableButton.js (rev 0)
+++ trunk/mapbender/lib/selectableButton.js 2008-06-23 15:57:43 UTC (rev 2538)
@@ -0,0 +1,32 @@
+var Selectable = {
+ buttonParameters : {
+ on:"../img/button_blink_red/selArea_on.png",
+ over:"../img/button_blink_red/selArea_over.png",
+ off:"../img/button_blink_red/selArea_off.png",
+ type:"toggle"
+ },
+ makeSelectable : function () {
+ // if a selection has been made, remove it
+ if ($(".ui-selected").size() > 0) {
+ Selectable.removeSelection();
+ }
+
+ $all = $(".collection");
+ $all.selectable({
+ selecting:function() {
+ $(".ui-selecting").removeClass("div-border");
+ },
+ unselecting:function() {
+ $(".ui-selectee").addClass("div-border");
+ $(".ui-selecting").removeClass("div-border");
+ }
+ });
+ },
+ removeSelection : function () {
+ $(".ui-selected").addClass("div-border");
+ $(".collection").selectable("destroy");
+ $(".ui-selected").removeClass("ui-selected");
+ $(".ui-selectee").removeClass("ui-selectee");
+ $(".ui-selectable").removeClass("ui-selectable");
+ }
+}
\ No newline at end of file
More information about the Mapbender_commits
mailing list