123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451 |
- Element.implement({
- "makeLnk": function(options){
- return new MWF.xDesktop.LnkMaker(this, options);
- }
- });
- MWF.xDesktop.LnkMaker = new Class({
- Implements: [Options, Events],
- initialize: function(node, options){
- this.setOptions(options);
-
- this.node = node;
- this.desktop = layout.desktop;
- this.tmpApps = [];
-
- this.isReadyDrag = false;
- this.readyDragPosition = null;
-
- this.setEvent();
- },
- setEvent: function(){
- this.node.addEvents({
- "mousedown": function(e){
- if (!e.rightClick){
- this.isReadyDrag = true;
- this.readyDragPosition = {"x": e.page.x, "y": e.page.y};
-
- document.body.addEvent("mousemove", function(e){
- if (this.isReadyDrag){
- if (Math.abs(e.page.x-this.readyDragPosition.y)>6 || Math.abs(e.page.y-this.readyDragPosition.y)>6){
- this.isReadyDrag = false;
- this.readyDragPosition = null;
- this.node.removeEvents("mousemove");
- this.beginMoveToDesktop(e);
- }
- }
- }.bind(this));
- }
- }.bind(this),
- "mouseup": function(e){
- this.isReadyDrag = false;
- this.readyDragPosition = null;
- this.node.removeEvents("mousemove");
- }.bind(this)
- });
- },
-
- createMoveNode: function(){
- var moveNode = new Element("div", {
- "styles": this.desktop.css.lnkMoveNode
- }).inject(this.desktop.desktopNode);
- var size = this.node.getSize();
- moveNode.setStyles({
- "width": ""+size.x+"px",
- "height": ""+size.y+"px"
- });
- this.node.clone().inject(moveNode);
- moveNode.position({"relativeTo": this.node});
-
- return moveNode;
- },
-
- beginMoveToDesktop: function(e){
- var moveNode = this.createMoveNode();
- var desktop = this.desktop;
- //var quick
- var drag = new Drag.Move(moveNode, {
- "snap": 10,
- "stopPropagation": true,
- "droppables": desktop.lnkAreas,
- "onStart": function(){
- this.fireEvent("start");
- this.start();
- this.fireEvent("afterStart");
- }.bind(this),
- "onDrag": function(dragging,e){
- this.fireEvent("drag", dragging);
- this.drag(dragging, e);
- this.fireEvent("afterDrag", dragging);
- }.bind(this),
- "onEnter": function(dragging, inObj){
- this.fireEvent("enter", dragging, inObj);
- this.enter(dragging, inObj);
- this.fireEvent("afterEnter", dragging, inObj);
- }.bind(this),
- "onLeave": function(dragging, paper){
- this.fireEvent("leave", dragging, paper);
- this.leave(dragging);
- this.fireEvent("afterLeave", dragging, paper);
- }.bind(this),
- "onDrop": function(dragging, inObj){
- this.fireEvent("drop", dragging, inObj);
- this.drop(dragging, e);
- this.fireEvent("afterDrop", dragging, inObj);
- }.bind(this),
- "onCancel": function(dragging){
- this.fireEvent("cancel", dragging);
- this.cancel(dragging);
- this.fireEvent("afterCancel", dragging);
- }.bind(this),
- "onComplete": function(dragging, e){
- this.fireEvent("complete", dragging, e);
- // this.complete();
- this.fireEvent("afterComplete", dragging, e);
- }.bind(this)
- });
- drag.start(e);
- },
- start: function(){
- this.tmpApps = [];
- Object.each(this.desktop.apps, function(app, id){
- if (!app.window.isHide){
- this.tmpApps.push(app);
- app.window._fadeOut();
- }
- }.bind(this));
- },
- enter: function(dragging, inObj){
- this.addLnkMark(dragging, inObj);
- },
- drag: function(dragging,e){
- this.moveLnkMark(dragging, e);
- },
- leave: function(dragging){
- this.removeLnkMark(dragging);
- },
- drop: function(dragging){
- this.addLnk(dragging);
- this.endMoveToDesktop(dragging);
- },
- cancel: function(dragging){
- this.endMoveToDesktop(dragging);
- },
-
- addLnkMark: function(node, inObj){
- if (!this.lnkMarkNode){
- this.lnkMarkNode = new Element("div", {
- "styles": this.desktop.css.dsektoplnkMarkNode
- }).inject(inObj);
- }
- },
- moveLnkMark: function(node,e){
- if (this.lnkMarkNode){
- var p = node.getPosition();
- var size = node.getSize();
- var area = this.lnkMarkNode.getParent();
- var lnks = area.getChildren();
- var position = false;
- for (var i=0; i<lnks.length; i++){
- if (lnks[i]!=this.lnkMarkNode && lnks[i]!=node){
- var lnkP = lnks[i].getPosition();
- var lnkSize = lnks[i].getSize();
-
- if (((lnkP.y+lnkSize.y) > (p.y+size.y/2)) && ((lnkP.x+lnkSize.x)>(p.x+size.x/2))){
- // var iconNode = lnks[i].getFirst("div");
- //
- // iconNode.setStyles({
- // "background-color": "#666"
- // });
- }else if ((lnkP.y+lnkSize.y)>(p.y+size.y)){
- this.lnkMarkNode.inject(lnks[i], "before");
- this.lnkMarkNode.setStyle("top", lnkP.y-10);
- position = true;
- break;
- }else{
- // var iconNode = lnks[i].getFirst("div");
- // iconNode.setStyles({
- // "background": "transparent"
- // });
- }
- //if ((lnkP.y< e.event.y) && (lnkP.y+lnkSize.y>e.event.y) && (lnkP.x<e.event.x) && (lnkP.x+lnkSize.x>e.event.x)){
- // debugger;
- // if (lnks[i].node != this.node){
- // alert("in")
- // }
- //}
- }
- }
- if (!position){
- this.lnkMarkNode.inject(area);
- this.lnkMarkNode.setStyle("top", "auto");
- if (this.desktop.lnks.length) this.lnkMarkNode.setStyle("top", this.lnkMarkNode.getPosition().y-10);
- }
- }
- },
- removeLnkMark: function(node){
- if (this.lnkMarkNode){
- this.lnkMarkNode.destroy();
- this.lnkMarkNode = null;
- }
- },
- addLnk: function(node){
- if (this.lnkMarkNode){
- var par = this.options.par;
- var lnk = new MWF.xDesktop.Lnk(par.icon, par.title, par.par);
-
- var next = this.lnkMarkNode.getNext();
- if (next){
- var nextLnk = next.retrieve("lnk");
- var idx = this.desktop.lnks.indexOf(nextLnk);
- this.desktop.lnks.splice(idx, 0, lnk);
- }else{
- this.desktop.lnks.push(lnk);
- }
- lnk.inject(this.lnkMarkNode, "after");
-
- this.removeLnkMark();
- this.desktop.resizeLnk();
- }
- },
-
- endMoveToDesktop: function(dragging){
- this.tmpApps.each(function(app){
- app.window._fadeIn();
- });
- this.tmpApps = [];
- if (dragging) dragging.destroy();
- }
- });
- MWF.xDesktop.LnkMove = new Class({
- Extends: MWF.xDesktop.LnkMaker,
-
- setEvent: function(){
- this.isReadySwing = false;
- this.readySwingTime = "";
- this.node.addEvents({
- "mousedown": function(e){
- if (!e.rightClick){
- this.isReadyDrag = true;
- //this.isReadySwing = true;
- this.readyDragPosition = {"x": e.page.x, "y": e.page.y};
- this.readySwingTime = new Date().getTime();
- // this.swingTimer = window.setTimeout(function(){
- // this.beginNodeSwing(e);
- // }.bind(this), 1000);
-
- this.node.addEvent("mousemove", function(event){
- if (this.isReadyDrag){
- if (Math.abs(event.page.x-this.readyDragPosition.x)>10 || Math.abs(event.page.y-this.readyDragPosition.y)>10){
- this.clearEvent();
- this.beginMoveToDesktop(e);
- }
- }
- }.bind(this));
- }
- }.bind(this),
- "mouseup": function(e){this.clearEvent();}.bind(this)
- });
- },
- clearEvent: function(){
- this.isReadyDrag = false;
- this.readyDragPosition = null;
- this.isReadySwing = false;
- this.readySwingTime = "";
- this.node.removeEvents("mousemove");
- window.clearTimeout(this.swingTimer);
- },
- beginNodeSwing: function(e){
- if (this.isReadySwing){
- this.clearEvent();
- this.morph = new Fx.Morph(this.node, {duration: 100});
- var lnk = this.node.retrieve("lnk");
- lnk.isSwing = true;
- // this.nodeSwing(1);
-
- this.nodeSwing(22);
-
- }
- },
- nodeSwing: function(o){
- // var opacity = (o==1) ? 0.4 : 1;
- var margin = (o==22) ? 18 : 22;
-
- // this.morph.start({"opacity": opacity}).chain(function(){
- // this.nodeSwing(opacity);
- // }.bind(this));
- this.morph.start({"margin-left": margin}).chain(function(){
- this.nodeSwing(margin);
- }.bind(this));
-
- },
- stopSwing: function(){
- this.morph.cancel();
- var lnk = this.node.retrieve("lnk");
- // this.morph.start({"opacity": 1}).chain(function(){
- // lnk.isSwing = false;
- // }.bind(this));
- this.morph.start({"margin-left": 20}).chain(function(){
- lnk.isSwing = false;
- }.bind(this));
- },
- createMoveNode: function(){
- var moveNode = this.node.clone().inject(this.desktop.desktopNode);
- moveNode.position({"relativeTo": this.node});
- moveNode.setStyles(this.desktop.css.desktopLnkNode);
- return moveNode;
- },
- start: function(){
- this.node.setStyle("opacity", 0.5);
- this.node.setStyles(this.desktop.css.desktopLnkNode_current);
- },
- addLnk: function(node){
- if (this.lnkMarkNode){
- var nextLnkNode = this.lnkMarkNode.getNext();
- var prevLnkNode = this.lnkMarkNode.getPrevious();
- var nextLnk = (nextLnkNode) ? nextLnkNode.retrieve("lnk") : null;
- var prevLnk = (prevLnkNode) ? prevLnkNode.retrieve("lnk") : null;
-
- var lnk = this.node.retrieve("lnk");
- if (!nextLnk){
- this.desktop.lnks.erase(lnk);
- this.desktop.lnks.push(lnk);
- }else if (nextLnk==lnk || prevLnk==lnk){
- // this.node.fade("in");
- }else{
- this.desktop.lnks.erase(lnk);
- var index = this.desktop.lnks.indexOf(nextLnk);
- if (index!=-1){
- this.desktop.lnks.splice(index, 0, lnk);
- }else{
- this.desktop.lnks.push(lnk);
- }
- }
- // this.node.setStyle("opacity", 0);
- this.removeLnkMark();
- this.desktop.resizeLnk();
- // this.node.fade("in");
- }
- this.node.fade("in");
- },
- endMoveToDesktop: function(dragging){
- this.node.setStyles(this.desktop.css.desktopLnkNode);
- if (dragging) dragging.destroy();
- }
- });
- MWF.xDesktop.Lnk = new Class({
- initialize: function(icon, title, par){
- this.desktop = layout.desktop;
- this.icon = icon;
- this.title = title;
- this.par = par;
- this.node = new Element("div", {
- "styles": this.desktop.css.desktopLnkNode,
- "title": this.title
- });
- this.node.store("lnk", this);
- this.iconNode = new Element("div", {
- "styles": this.desktop.css.desktopLnkIconNode
- }).inject(this.node);
- var img = new Element("img").inject(this.iconNode);
- var s = this.iconNode.getSize();
- if (!s.x) s.x = this.iconNode.getStyle("width").toFloat();
- if (!s.y) s.y = this.iconNode.getStyle("height").toFloat();
- var w = s.x-10;
- var h = s.y-10;
- img.setStyles({
- "margin": "5px",
- "max-width": ""+w+"px",
- "max-height": ""+h+"px"
- });
- if (this.icon.substr(0,3).toLowerCase()=="url"){
- img.set("src", this.icon.substring(4, this.icon.length-1));
- //this.iconNode.setStyle("background-image", this.icon);
- }else{
- img.set("src", this.icon);
- //this.iconNode.setStyle("background-image", "url("+this.icon+")");
- }
- //this.iconNode.setStyle("background-image", "url("+this.icon+")");
-
- this.titleNode = new Element("div", {
- "styles": this.desktop.css.desktopLnkTitleNode,
- "text": this.title
- }).inject(this.node);
-
- this.node.addEvents({
- "mouseover": function(e){this.node.setStyles(this.desktop.css.desktopLnkNode_current);}.bind(this),
- "mouseout": function(e){this.node.setStyles(this.desktop.css.desktopLnkNode);}.bind(this),
- "click": function(e){this.open(e);}.bind(this)
- });
-
- this.lnkMove = new MWF.xDesktop.LnkMove(this.node);
- this.loadMenu();
- },
- loadMenu: function(){
- this.menu = new MWF.widget.Menu(this.node, {"style": "lnk",
- "container": this.desktop.node
- });
- this.menu.load();
- this.menu.addMenuItem(o2.LP.desktop.deleteLink, "click", function(){
- this.deleteLnk();
- }.bind(this));
- },
- deleteLnk: function(){
- this.desktop.lnks.erase(this);
- this.node.destroy();
- MWF.release(this);
- delete this;
- },
- inject: function(node, where){
- this.node.inject(node, where);
- },
- open: function(e){
- if (!this.isSwing){
- var parList = this.par.split("#");
- var appName = parList[0];
- var statusStr = parList[1] || "";
- if (appName.toLowerCase()==="@url"){
- window.open(statusStr);
- }else{
- var status = JSON.decode(statusStr, false);
- var options = {};
- if (status){
- if (status.appId){
- options = {
- "appId": status.appId,
- "onQueryLoad": function(){
- this.status = status;
- }
- };
- }else{
- options = {
- "onQueryLoad": function(){
- this.status = status;
- }
- };
- }
- }
- this.desktop.openApplication(e, appName, options);
- }
- }else{
- this.stopSwingFun = function(){
- this.lnkMove.stopSwing();
- this.node.removeEvent("click", this.stopSwingFun);
- }.bind(this);
- this.node.addEvent("click", this.stopSwingFun);
-
- }
- }
- });
|