MDL-33765 filter_glossary: Stacking JS windows with offset

This commit is contained in:
Martin Mastny 2015-06-02 13:45:49 +08:00 committed by Mark Nelson
parent 57a1f4fc65
commit a42f94a38d
4 changed files with 85 additions and 4 deletions

View File

@ -19,6 +19,7 @@ AUTOLINKER = function() {
};
Y.extend(AUTOLINKER, Y.Base, {
overlay : null,
alertpanels: {},
initializer : function() {
var self = this;
Y.delegate('click', function(e){
@ -64,7 +65,10 @@ Y.extend(AUTOLINKER, Y.Base, {
var data,
key,
alertpanel,
definition;
alertpanelid,
definition,
position;
var self = this;
try {
data = Y.JSON.parse(content);
if (data.success){
@ -76,6 +80,20 @@ Y.extend(AUTOLINKER, Y.Base, {
message:definition, modal:false, yesLabel: M.util.get_string('ok', 'moodle')});
Y.fire(M.core.event.FILTER_CONTENT_UPDATED, {nodes: (new Y.NodeList(alertpanel.get('boundingBox')))});
Y.Node.one('#id_yuialertconfirm-' + alertpanel.get('COUNT')).focus();
// Register alertpanel for stacking.
alertpanelid = '#moodle-dialogue-' + alertpanel.get('COUNT');
alertpanel.on('complete', function(){
delete self.alertpanels[alertpanelid];
});
// We already have some windows opened, so set the right position...
if (!Y.Object.isEmpty(this.alertpanels)){
position = this._getLatestWindowPosition();
Y.Node.one(alertpanelid).setXY([position[0] + 10, position[1] + 10]);
}
this.alertpanels[alertpanelid] = Y.Node.one(alertpanelid).getXY();
}
return true;
@ -86,6 +104,15 @@ Y.extend(AUTOLINKER, Y.Base, {
new M.core.exception(e);
}
return false;
},
_getLatestWindowPosition : function() {
var lastPosition = [0, 0];
Y.Object.each(this.alertpanels, function(position) {
if (position[0] > lastPosition[0]){
lastPosition = position;
}
});
return lastPosition;
}
}, {
NAME : AUTOLINKERNAME,

View File

@ -1 +1 @@
YUI.add("moodle-filter_glossary-autolinker",function(e,t){var n="Glossary filter autolinker",r="width",i="height",s="menubar",o="location",u="scrollbars",a="resizable",f="toolbar",l="status",c="directories",h="fullscreen",p="dependent",d;d=function(){d.superclass.constructor.apply(this,arguments)},e.extend(d,e.Base,{overlay:null,initializer:function(){var t=this;e.delegate("click",function(n){n.preventDefault();var r="",i=e.Node.create('<div id="glossaryfilteroverlayprogress"><img src="'+M.cfg.loadingicon+'" class="spinner" />'+"</div>"),s=new e.Overlay({headerContent:r,bodyContent:i}),o,u;t.overlay=s,s.render(e.one(document.body)),o=this.getAttribute("href").replace("showentry.php","showentry_ajax.php"),u={method:"get",context:t,on:{success:function(e,t){this.display_callback(t.responseText)},failure:function(e,t){var n=t.statusText;M.cfg.developerdebug&&(t.statusText+=" ("+o+")"),this.display_callback("bodyContent",n)}}},e.io(o,u)},e.one(document.body),"a.glossary.autolink.concept")},display_callback:function(t){var n,r,i,s;try{n=e.JSON.parse(t);if(n.success){this.overlay.hide();for(r in n.entries)s=n.entries[r].definition+n.entries[r].attachments,i=new M.core.alert({title:n.entries[r].concept,draggable:!0,message:s,modal:!1,yesLabel:M.util.get_string("ok","moodle")}),e.fire(M.core.event.FILTER_CONTENT_UPDATED,{nodes:new e.NodeList(i.get("boundingBox"))}),e.Node.one("#id_yuialertconfirm-"+i.get("COUNT")).focus();return!0}n.error&&new M.core.ajaxException(n)}catch(o){new M.core.exception(o)}return!1}},{NAME:n,ATTRS:{url:{validator:e.Lang.isString,value:M.cfg.wwwroot+"/mod/glossary/showentry.php"},name:{validator:e.Lang.isString,value:"glossaryconcept"},options:{getter:function(){return{width:this.get(r),height:this.get(i),menubar:this.get(s),location:this.get(o),scrollbars:this.get(u),resizable:this.get(a),toolbar:this.get(f),status:this.get(l),directories:this.get(c),fullscreen:this.get(h),dependent:this.get(p)}},readOnly:!0},width:{value:600},height:{value:450},menubar:{value:!1},location:{value:!1},scrollbars:{value:!0},resizable:{value:!0},toolbar:{value:!0},status:{value:!0},directories:{value:!1},fullscreen:{value:!1},dependent:{value:!0}}}),M.filter_glossary=M.filter_glossary||{},M.filter_glossary.init_filter_autolinking=function(e){return new d(e)}},"@VERSION@",{requires:["base","node","io-base","json-parse","event-delegate","overlay","moodle-core-event","moodle-core-notification-alert","moodle-core-notification-exception","moodle-core-notification-ajaxexception"]});
YUI.add("moodle-filter_glossary-autolinker",function(e,t){var n="Glossary filter autolinker",r="width",i="height",s="menubar",o="location",u="scrollbars",a="resizable",f="toolbar",l="status",c="directories",h="fullscreen",p="dependent",d;d=function(){d.superclass.constructor.apply(this,arguments)},e.extend(d,e.Base,{overlay:null,alertpanels:{},initializer:function(){var t=this;e.delegate("click",function(n){n.preventDefault();var r="",i=e.Node.create('<div id="glossaryfilteroverlayprogress"><img src="'+M.cfg.loadingicon+'" class="spinner" />'+"</div>"),s=new e.Overlay({headerContent:r,bodyContent:i}),o,u;t.overlay=s,s.render(e.one(document.body)),o=this.getAttribute("href").replace("showentry.php","showentry_ajax.php"),u={method:"get",context:t,on:{success:function(e,t){this.display_callback(t.responseText)},failure:function(e,t){var n=t.statusText;M.cfg.developerdebug&&(t.statusText+=" ("+o+")"),this.display_callback("bodyContent",n)}}},e.io(o,u)},e.one(document.body),"a.glossary.autolink.concept")},display_callback:function(t){var n,r,i,s,o,u,a=this;try{n=e.JSON.parse(t);if(n.success){this.overlay.hide();for(r in n.entries)o=n.entries[r].definition+n.entries[r].attachments,i=new M.core.alert({title:n.entries[r].concept,draggable:!0,message:o,modal:!1,yesLabel:M.util.get_string("ok","moodle")}),e.fire(M.core.event.FILTER_CONTENT_UPDATED,{nodes:new e.NodeList(i.get("boundingBox"))}),e.Node.one("#id_yuialertconfirm-"+i.get("COUNT")).focus(),s="#moodle-dialogue-"+i.get("COUNT"),i.on("complete",function(){delete a.alertpanels[s]}),e.Object.isEmpty(this.alertpanels)||(u=this._getLatestWindowPosition(),e.Node.one(s).setXY([u[0]+10,u[1]+10])),this.alertpanels[s]=e.Node.one(s).getXY();return!0}n.error&&new M.core.ajaxException(n)}catch(f){new M.core.exception(f)}return!1},_getLatestWindowPosition:function(){var t=[0,0];return e.Object.each(this.alertpanels,function(e){e[0]>t[0]&&(t=e)}),t}},{NAME:n,ATTRS:{url:{validator:e.Lang.isString,value:M.cfg.wwwroot+"/mod/glossary/showentry.php"},name:{validator:e.Lang.isString,value:"glossaryconcept"},options:{getter:function(){return{width:this.get(r),height:this.get(i),menubar:this.get(s),location:this.get(o),scrollbars:this.get(u),resizable:this.get(a),toolbar:this.get(f),status:this.get(l),directories:this.get(c),fullscreen:this.get(h),dependent:this.get(p)}},readOnly:!0},width:{value:600},height:{value:450},menubar:{value:!1},location:{value:!1},scrollbars:{value:!0},resizable:{value:!0},toolbar:{value:!0},status:{value:!0},directories:{value:!1},fullscreen:{value:!1},dependent:{value:!0}}}),M.filter_glossary=M.filter_glossary||{},M.filter_glossary.init_filter_autolinking=function(e){return new d(e)}},"@VERSION@",{requires:["base","node","io-base","json-parse","event-delegate","overlay","moodle-core-event","moodle-core-notification-alert","moodle-core-notification-exception","moodle-core-notification-ajaxexception"]});

View File

@ -19,6 +19,7 @@ AUTOLINKER = function() {
};
Y.extend(AUTOLINKER, Y.Base, {
overlay : null,
alertpanels: {},
initializer : function() {
var self = this;
Y.delegate('click', function(e){
@ -64,7 +65,10 @@ Y.extend(AUTOLINKER, Y.Base, {
var data,
key,
alertpanel,
definition;
alertpanelid,
definition,
position;
var self = this;
try {
data = Y.JSON.parse(content);
if (data.success){
@ -76,6 +80,20 @@ Y.extend(AUTOLINKER, Y.Base, {
message:definition, modal:false, yesLabel: M.util.get_string('ok', 'moodle')});
Y.fire(M.core.event.FILTER_CONTENT_UPDATED, {nodes: (new Y.NodeList(alertpanel.get('boundingBox')))});
Y.Node.one('#id_yuialertconfirm-' + alertpanel.get('COUNT')).focus();
// Register alertpanel for stacking.
alertpanelid = '#moodle-dialogue-' + alertpanel.get('COUNT');
alertpanel.on('complete', function(){
delete self.alertpanels[alertpanelid];
});
// We already have some windows opened, so set the right position...
if (!Y.Object.isEmpty(this.alertpanels)){
position = this._getLatestWindowPosition();
Y.Node.one(alertpanelid).setXY([position[0] + 10, position[1] + 10]);
}
this.alertpanels[alertpanelid] = Y.Node.one(alertpanelid).getXY();
}
return true;
@ -86,6 +104,15 @@ Y.extend(AUTOLINKER, Y.Base, {
new M.core.exception(e);
}
return false;
},
_getLatestWindowPosition : function() {
var lastPosition = [0, 0];
Y.Object.each(this.alertpanels, function(position) {
if (position[0] > lastPosition[0]){
lastPosition = position;
}
});
return lastPosition;
}
}, {
NAME : AUTOLINKERNAME,

View File

@ -17,6 +17,7 @@ AUTOLINKER = function() {
};
Y.extend(AUTOLINKER, Y.Base, {
overlay : null,
alertpanels: {},
initializer : function() {
var self = this;
Y.delegate('click', function(e){
@ -62,7 +63,10 @@ Y.extend(AUTOLINKER, Y.Base, {
var data,
key,
alertpanel,
definition;
alertpanelid,
definition,
position;
var self = this;
try {
data = Y.JSON.parse(content);
if (data.success){
@ -74,6 +78,20 @@ Y.extend(AUTOLINKER, Y.Base, {
message:definition, modal:false, yesLabel: M.util.get_string('ok', 'moodle')});
Y.fire(M.core.event.FILTER_CONTENT_UPDATED, {nodes: (new Y.NodeList(alertpanel.get('boundingBox')))});
Y.Node.one('#id_yuialertconfirm-' + alertpanel.get('COUNT')).focus();
// Register alertpanel for stacking.
alertpanelid = '#moodle-dialogue-' + alertpanel.get('COUNT');
alertpanel.on('complete', function(){
delete self.alertpanels[alertpanelid];
});
// We already have some windows opened, so set the right position...
if (!Y.Object.isEmpty(this.alertpanels)){
position = this._getLatestWindowPosition();
Y.Node.one(alertpanelid).setXY([position[0] + 10, position[1] + 10]);
}
this.alertpanels[alertpanelid] = Y.Node.one(alertpanelid).getXY();
}
return true;
@ -84,6 +102,15 @@ Y.extend(AUTOLINKER, Y.Base, {
new M.core.exception(e);
}
return false;
},
_getLatestWindowPosition : function() {
var lastPosition = [0, 0];
Y.Object.each(this.alertpanels, function(position) {
if (position[0] > lastPosition[0]){
lastPosition = position;
}
});
return lastPosition;
}
}, {
NAME : AUTOLINKERNAME,