MDL-38674 JavaScript: Migrate moodle-filter_glossary-autolink to use Shifter

This commit is contained in:
Andrew Robert Nicols
2013-03-24 17:26:23 +00:00
parent 373a8e052c
commit 096065e6c0
8 changed files with 664 additions and 134 deletions
-134
View File
@@ -1,134 +0,0 @@
YUI.add('moodle-filter_glossary-autolinker', function(Y) {
var AUTOLINKERNAME = 'Glossary filter autolinker',
URL = 'url',
POPUPNAME = 'name',
POPUPOPTIONS = 'options',
TITLE = 'title',
WIDTH = 'width',
HEIGHT = 'height',
MENUBAR = 'menubar',
LOCATION = 'location',
SCROLLBARS = 'scrollbars',
RESIZEABLE = 'resizable',
TOOLBAR = 'toolbar',
STATUS = 'status',
DIRECTORIES = 'directories',
FULLSCREEN = 'fullscreen',
DEPENDENT = 'dependent';
var AUTOLINKER = function() {
AUTOLINKER.superclass.constructor.apply(this, arguments);
};
Y.extend(AUTOLINKER, Y.Base, {
overlay : null,
initializer : function(config) {
var popupname = this.get(POPUPNAME),
popupoptions = this.get(POPUPOPTIONS),
self = this;
Y.delegate('click', function(e){
e.preventDefault();
//display a progress indicator
var title = '';
var content = Y.Node.create('<div id="glossaryfilteroverlayprogress"><img src="'+M.cfg.loadingicon+'" class="spinner" /></div>');
var o = new Y.Overlay({
headerContent : title,
bodyContent : content
});
self.overlay = o;
o.render(Y.one(document.body));
//Switch over to the ajax url and fetch the glossary item
var fullurl = this.getAttribute('href').replace('showentry.php','showentry_ajax.php');
var cfg = {
method: 'get',
context : self,
on: {
success: function(id, o, node) {
this.display_callback(o.responseText);
},
failure: function(id, o, node) {
var debuginfo = o.statusText;
if (M.cfg.developerdebug) {
o.statusText += ' (' + fullurl + ')';
}
this.display_callback('bodyContent',debuginfo);
}
}
};
Y.io(fullurl, cfg);
}, Y.one(document.body), 'a.glossary.autolink.concept');
},
display_callback : function(content) {
try {
var data = Y.JSON.parse(content);
if (data.success){
this.overlay.hide(); //hide progress indicator
for (key in data.entries) {
definition = data.entries[key].definition + data.entries[key].attachments
var alertpanel = new M.core.alert({title:data.entries[key].concept, message:definition, lightbox:false});
Y.Node.one('#id_yuialertconfirm-' + alertpanel.COUNT).focus();
}
return true;
} else if (data.error) {
new M.core.ajaxException(data);
}
}catch(e) {
new M.core.exception(e);
}
return false;
}
}, {
NAME : AUTOLINKERNAME,
ATTRS : {
url : {
validator : Y.Lang.isString,
value : M.cfg.wwwroot+'/mod/glossary/showentry.php'
},
name : {
validator : Y.Lang.isString,
value : 'glossaryconcept'
},
options : {
getter : function(val) {
return {
width : this.get(WIDTH),
height : this.get(HEIGHT),
menubar : this.get(MENUBAR),
location : this.get(LOCATION),
scrollbars : this.get(SCROLLBARS),
resizable : this.get(RESIZEABLE),
toolbar : this.get(TOOLBAR),
status : this.get(STATUS),
directories : this.get(DIRECTORIES),
fullscreen : this.get(FULLSCREEN),
dependent : this.get(DEPENDENT)
}
},
readOnly : true
},
width : {value : 600},
height : {value : 450},
menubar : {value : false},
location : {value : false},
scrollbars : {value : true},
resizable : {value : true},
toolbar : {value : true},
status : {value : true},
directories : {value : false},
fullscreen : {value : false},
dependent : {value : true}
}
});
M.filter_glossary = M.filter_glossary || {};
M.filter_glossary.init_filter_autolinking = function(config) {
return new AUTOLINKER(config);
}
}, '@VERSION@', {requires:['base','node','io-base','json-parse','event-delegate','overlay','moodle-core-notification']});
File diff suppressed because one or more lines are too long
@@ -0,0 +1,144 @@
YUI.add('moodle-filter_glossary-autolinker', function (Y, NAME) {
var AUTOLINKERNAME = 'Glossary filter autolinker',
WIDTH = 'width',
HEIGHT = 'height',
MENUBAR = 'menubar',
LOCATION = 'location',
SCROLLBARS = 'scrollbars',
RESIZEABLE = 'resizable',
TOOLBAR = 'toolbar',
STATUS = 'status',
DIRECTORIES = 'directories',
FULLSCREEN = 'fullscreen',
DEPENDENT = 'dependent',
AUTOLINKER;
AUTOLINKER = function() {
AUTOLINKER.superclass.constructor.apply(this, arguments);
};
Y.extend(AUTOLINKER, Y.Base, {
overlay : null,
initializer : function() {
var self = this;
Y.delegate('click', function(e){
e.preventDefault();
//display a progress indicator
var title = '',
content = Y.Node.create('<div id="glossaryfilteroverlayprogress"><img src="'+M.cfg.loadingicon+'" class="spinner" /></div>'),
o = new Y.Overlay({
headerContent : title,
bodyContent : content
}),
fullurl,
cfg;
self.overlay = o;
o.render(Y.one(document.body));
//Switch over to the ajax url and fetch the glossary item
fullurl = this.getAttribute('href').replace('showentry.php','showentry_ajax.php');
cfg = {
method: 'get',
context : self,
on: {
success: function(id, o) {
this.display_callback(o.responseText);
},
failure: function(id, o) {
var debuginfo = o.statusText;
if (M.cfg.developerdebug) {
o.statusText += ' (' + fullurl + ')';
}
this.display_callback('bodyContent',debuginfo);
}
}
};
Y.io(fullurl, cfg);
}, Y.one(document.body), 'a.glossary.autolink.concept');
},
display_callback : function(content) {
var data,
key,
alertpanel;
try {
data = Y.JSON.parse(content);
if (data.success){
this.overlay.hide(); //hide progress indicator
for (key in data.entries) {
definition = data.entries[key].definition + data.entries[key].attachments;
alertpanel = new M.core.alert({title:data.entries[key].concept, message:definition, lightbox:false});
Y.Node.one('#id_yuialertconfirm-' + alertpanel.COUNT).focus();
}
return true;
} else if (data.error) {
new M.core.ajaxException(data);
}
} catch(e) {
new M.core.exception(e);
}
return false;
}
}, {
NAME : AUTOLINKERNAME,
ATTRS : {
url : {
validator : Y.Lang.isString,
value : M.cfg.wwwroot+'/mod/glossary/showentry.php'
},
name : {
validator : Y.Lang.isString,
value : 'glossaryconcept'
},
options : {
getter : function() {
return {
width : this.get(WIDTH),
height : this.get(HEIGHT),
menubar : this.get(MENUBAR),
location : this.get(LOCATION),
scrollbars : this.get(SCROLLBARS),
resizable : this.get(RESIZEABLE),
toolbar : this.get(TOOLBAR),
status : this.get(STATUS),
directories : this.get(DIRECTORIES),
fullscreen : this.get(FULLSCREEN),
dependent : this.get(DEPENDENT)
};
},
readOnly : true
},
width : {value : 600},
height : {value : 450},
menubar : {value : false},
location : {value : false},
scrollbars : {value : true},
resizable : {value : true},
toolbar : {value : true},
status : {value : true},
directories : {value : false},
fullscreen : {value : false},
dependent : {value : true}
}
});
M.filter_glossary = M.filter_glossary || {};
M.filter_glossary.init_filter_autolinking = function(config) {
return new AUTOLINKER(config);
};
}, '@VERSION@', {
"requires": [
"base",
"node",
"io-base",
"json-parse",
"event-delegate",
"overlay",
"moodle-core-notification"
]
});
@@ -0,0 +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;try{n=e.JSON.parse(t);if(n.success){this.overlay.hide();for(r in n.entries)definition=n.entries[r].definition+n.entries[r].attachments,i=new M.core.alert({title:n.entries[r].concept,message:definition,lightbox:!1}),e.Node.one("#id_yuialertconfirm-"+i.COUNT).focus();return!0}n.error&&new M.core.ajaxException(n)}catch(s){new M.core.exception(s)}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-notification"]});
@@ -0,0 +1,144 @@
YUI.add('moodle-filter_glossary-autolinker', function (Y, NAME) {
var AUTOLINKERNAME = 'Glossary filter autolinker',
WIDTH = 'width',
HEIGHT = 'height',
MENUBAR = 'menubar',
LOCATION = 'location',
SCROLLBARS = 'scrollbars',
RESIZEABLE = 'resizable',
TOOLBAR = 'toolbar',
STATUS = 'status',
DIRECTORIES = 'directories',
FULLSCREEN = 'fullscreen',
DEPENDENT = 'dependent',
AUTOLINKER;
AUTOLINKER = function() {
AUTOLINKER.superclass.constructor.apply(this, arguments);
};
Y.extend(AUTOLINKER, Y.Base, {
overlay : null,
initializer : function() {
var self = this;
Y.delegate('click', function(e){
e.preventDefault();
//display a progress indicator
var title = '',
content = Y.Node.create('<div id="glossaryfilteroverlayprogress"><img src="'+M.cfg.loadingicon+'" class="spinner" /></div>'),
o = new Y.Overlay({
headerContent : title,
bodyContent : content
}),
fullurl,
cfg;
self.overlay = o;
o.render(Y.one(document.body));
//Switch over to the ajax url and fetch the glossary item
fullurl = this.getAttribute('href').replace('showentry.php','showentry_ajax.php');
cfg = {
method: 'get',
context : self,
on: {
success: function(id, o) {
this.display_callback(o.responseText);
},
failure: function(id, o) {
var debuginfo = o.statusText;
if (M.cfg.developerdebug) {
o.statusText += ' (' + fullurl + ')';
}
this.display_callback('bodyContent',debuginfo);
}
}
};
Y.io(fullurl, cfg);
}, Y.one(document.body), 'a.glossary.autolink.concept');
},
display_callback : function(content) {
var data,
key,
alertpanel;
try {
data = Y.JSON.parse(content);
if (data.success){
this.overlay.hide(); //hide progress indicator
for (key in data.entries) {
definition = data.entries[key].definition + data.entries[key].attachments;
alertpanel = new M.core.alert({title:data.entries[key].concept, message:definition, lightbox:false});
Y.Node.one('#id_yuialertconfirm-' + alertpanel.COUNT).focus();
}
return true;
} else if (data.error) {
new M.core.ajaxException(data);
}
} catch(e) {
new M.core.exception(e);
}
return false;
}
}, {
NAME : AUTOLINKERNAME,
ATTRS : {
url : {
validator : Y.Lang.isString,
value : M.cfg.wwwroot+'/mod/glossary/showentry.php'
},
name : {
validator : Y.Lang.isString,
value : 'glossaryconcept'
},
options : {
getter : function() {
return {
width : this.get(WIDTH),
height : this.get(HEIGHT),
menubar : this.get(MENUBAR),
location : this.get(LOCATION),
scrollbars : this.get(SCROLLBARS),
resizable : this.get(RESIZEABLE),
toolbar : this.get(TOOLBAR),
status : this.get(STATUS),
directories : this.get(DIRECTORIES),
fullscreen : this.get(FULLSCREEN),
dependent : this.get(DEPENDENT)
};
},
readOnly : true
},
width : {value : 600},
height : {value : 450},
menubar : {value : false},
location : {value : false},
scrollbars : {value : true},
resizable : {value : true},
toolbar : {value : true},
status : {value : true},
directories : {value : false},
fullscreen : {value : false},
dependent : {value : true}
}
});
M.filter_glossary = M.filter_glossary || {};
M.filter_glossary.init_filter_autolinking = function(config) {
return new AUTOLINKER(config);
};
}, '@VERSION@', {
"requires": [
"base",
"node",
"io-base",
"json-parse",
"event-delegate",
"overlay",
"moodle-core-notification"
]
});
@@ -0,0 +1,10 @@
{
"name": "moodle-filter_glossary-autolinker",
"builds": {
"moodle-filter_glossary-autolinker": {
"jsfiles": [
"autolinker.js"
]
}
}
}
+129
View File
@@ -0,0 +1,129 @@
var AUTOLINKERNAME = 'Glossary filter autolinker',
WIDTH = 'width',
HEIGHT = 'height',
MENUBAR = 'menubar',
LOCATION = 'location',
SCROLLBARS = 'scrollbars',
RESIZEABLE = 'resizable',
TOOLBAR = 'toolbar',
STATUS = 'status',
DIRECTORIES = 'directories',
FULLSCREEN = 'fullscreen',
DEPENDENT = 'dependent',
AUTOLINKER;
AUTOLINKER = function() {
AUTOLINKER.superclass.constructor.apply(this, arguments);
};
Y.extend(AUTOLINKER, Y.Base, {
overlay : null,
initializer : function() {
var self = this;
Y.delegate('click', function(e){
e.preventDefault();
//display a progress indicator
var title = '',
content = Y.Node.create('<div id="glossaryfilteroverlayprogress"><img src="'+M.cfg.loadingicon+'" class="spinner" /></div>'),
o = new Y.Overlay({
headerContent : title,
bodyContent : content
}),
fullurl,
cfg;
self.overlay = o;
o.render(Y.one(document.body));
//Switch over to the ajax url and fetch the glossary item
fullurl = this.getAttribute('href').replace('showentry.php','showentry_ajax.php');
cfg = {
method: 'get',
context : self,
on: {
success: function(id, o) {
this.display_callback(o.responseText);
},
failure: function(id, o) {
var debuginfo = o.statusText;
if (M.cfg.developerdebug) {
o.statusText += ' (' + fullurl + ')';
}
this.display_callback('bodyContent',debuginfo);
}
}
};
Y.io(fullurl, cfg);
}, Y.one(document.body), 'a.glossary.autolink.concept');
},
display_callback : function(content) {
var data,
key,
alertpanel;
try {
data = Y.JSON.parse(content);
if (data.success){
this.overlay.hide(); //hide progress indicator
for (key in data.entries) {
definition = data.entries[key].definition + data.entries[key].attachments;
alertpanel = new M.core.alert({title:data.entries[key].concept, message:definition, lightbox:false});
Y.Node.one('#id_yuialertconfirm-' + alertpanel.COUNT).focus();
}
return true;
} else if (data.error) {
new M.core.ajaxException(data);
}
} catch(e) {
new M.core.exception(e);
}
return false;
}
}, {
NAME : AUTOLINKERNAME,
ATTRS : {
url : {
validator : Y.Lang.isString,
value : M.cfg.wwwroot+'/mod/glossary/showentry.php'
},
name : {
validator : Y.Lang.isString,
value : 'glossaryconcept'
},
options : {
getter : function() {
return {
width : this.get(WIDTH),
height : this.get(HEIGHT),
menubar : this.get(MENUBAR),
location : this.get(LOCATION),
scrollbars : this.get(SCROLLBARS),
resizable : this.get(RESIZEABLE),
toolbar : this.get(TOOLBAR),
status : this.get(STATUS),
directories : this.get(DIRECTORIES),
fullscreen : this.get(FULLSCREEN),
dependent : this.get(DEPENDENT)
};
},
readOnly : true
},
width : {value : 600},
height : {value : 450},
menubar : {value : false},
location : {value : false},
scrollbars : {value : true},
resizable : {value : true},
toolbar : {value : true},
status : {value : true},
directories : {value : false},
fullscreen : {value : false},
dependent : {value : true}
}
});
M.filter_glossary = M.filter_glossary || {};
M.filter_glossary.init_filter_autolinking = function(config) {
return new AUTOLINKER(config);
};
@@ -0,0 +1,13 @@
{
"moodle-filter_glossary-autolinker": {
"requires": [
"base",
"node",
"io-base",
"json-parse",
"event-delegate",
"overlay",
"moodle-core-notification"
]
}
}