mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 00:46:50 +02:00
Merge branch 'MDL-37127-m' of git://github.com/andrewnicols/moodle
This commit is contained in:
commit
5c1d5998ac
11 changed files with 1547 additions and 14 deletions
|
@ -468,6 +468,9 @@ $CFG->admin = 'admin';
|
|||
// Prevent theme caching
|
||||
// $CFG->themerev = -1; // NOT FOR PRODUCTION SERVERS!
|
||||
//
|
||||
// Prevent JS caching
|
||||
// $CFG->jsrev = -1; // NOT FOR PRODUCTION SERVERS!
|
||||
//
|
||||
// Prevent core_string_manager on-disk cache
|
||||
// $CFG->langstringcache = false; // NOT FOR PRODUCTION SERVERS!
|
||||
//
|
||||
|
|
|
@ -198,7 +198,6 @@ class page_requirements_manager {
|
|||
'base' => $CFG->httpswwwroot . '/theme/yui_combo.php'.$sep.'moodle/'.$jsrev.'/',
|
||||
'comboBase' => $CFG->httpswwwroot . '/theme/yui_combo.php'.$sep,
|
||||
'combine' => $this->yui3loader->combine,
|
||||
'filter' => '',
|
||||
'ext' => false,
|
||||
'root' => 'moodle/'.$jsrev.'/', // Add the rev to the root path so that we can control caching.
|
||||
'patterns' => array(
|
||||
|
@ -1062,7 +1061,7 @@ class page_requirements_manager {
|
|||
// Note: in JavaScript just use "YUI().use('overlay', function(Y) { .... });",
|
||||
// this needs to be done before including any other script.
|
||||
$js = "var M = {}; M.yui = {};
|
||||
var moodleConfigFn = function(me) {var p = me.path, b = me.name.replace(/^moodle-/,'').split('-', 3), n = b.pop();if (/(skin|core)/.test(n)) {n = b.pop();me.type = 'css';};me.path = b.join('-')+'/'+n+'/'+n+'.'+me.type;};
|
||||
var moodleConfigFn = function(me) {var p = me.path, b = me.name.replace(/^moodle-/,'').split('-', 3), n = b.pop();if (/(skin|core)/.test(n)) {n = b.pop();me.type = 'css';};me.path = b.join('-')+'/'+n+'/'+n+'-min.'+me.type;};
|
||||
var galleryConfigFn = function(me) {var p = me.path,v=M.yui.galleryversion,f;if(/-(skin|core)/.test(me.name)) {me.type = 'css';p = p.replace(/-(skin|core)/, '').replace(/\.js/, '.css').split('/'), f = p.pop().replace(/(\-(min|debug))/, '');if (/-skin/.test(me.name)) {p.splice(p.length,0,v,'assets','skins','sam', f);} else {p.splice(p.length,0,v,'assets', f);};} else {p = p.split('/'), f = p.pop();p.splice(p.length,0,v, f);};me.path = p.join('/');};
|
||||
var yui2in3ConfigFn = function(me) {if(/-skin|reset|fonts|grids|base/.test(me.name)){me.type='css';me.path=me.path.replace(/\.js/,'.css');me.path=me.path.replace(/\/yui2-skin/,'/assets/skins/sam/yui2-skin');}};\n";
|
||||
$js .= js_writer::set_variable('YUI_config', $this->YUI_config, false) . "\n";
|
||||
|
|
589
lib/yui/build/moodle-core-tooltip/moodle-core-tooltip-coverage.js
vendored
Normal file
589
lib/yui/build/moodle-core-tooltip/moodle-core-tooltip-coverage.js
vendored
Normal file
File diff suppressed because one or more lines are too long
444
lib/yui/build/moodle-core-tooltip/moodle-core-tooltip-debug.js
vendored
Normal file
444
lib/yui/build/moodle-core-tooltip/moodle-core-tooltip-debug.js
vendored
Normal file
|
@ -0,0 +1,444 @@
|
|||
YUI.add('moodle-core-tooltip', function (Y, NAME) {
|
||||
|
||||
/**
|
||||
* Provides the base tooltip class.
|
||||
*
|
||||
* @module moodle-core-tooltip
|
||||
*/
|
||||
|
||||
/**
|
||||
* A base class for a tooltip.
|
||||
*
|
||||
* @param {Object} config Object literal specifying tooltip configuration properties.
|
||||
* @class M.core.tooltip
|
||||
* @constructor
|
||||
* @extends M.core.dialogue
|
||||
*/
|
||||
function TOOLTIP(config) {
|
||||
if (!config) {
|
||||
config = {};
|
||||
}
|
||||
|
||||
// Override the default options provided by the parent class.
|
||||
if (typeof config.draggable === 'undefined') {
|
||||
config.draggable = true;
|
||||
}
|
||||
|
||||
if (typeof config.constrain === 'undefined') {
|
||||
config.constrain = true;
|
||||
}
|
||||
|
||||
if (typeof config.lightbox === 'undefined') {
|
||||
config.lightbox = false;
|
||||
}
|
||||
|
||||
TOOLTIP.superclass.constructor.apply(this, [config]);
|
||||
}
|
||||
|
||||
var SELECTORS = {
|
||||
CLOSEBUTTON: '.closebutton'
|
||||
},
|
||||
|
||||
CSS = {
|
||||
PANELTEXT: 'tooltiptext'
|
||||
},
|
||||
RESOURCES = {
|
||||
WAITICON: {
|
||||
pix: 'i/loading_small',
|
||||
component: 'moodle'
|
||||
}
|
||||
},
|
||||
ATTRS = {};
|
||||
|
||||
/**
|
||||
* Static property provides a string to identify the JavaScript class.
|
||||
*
|
||||
* @property NAME
|
||||
* @type String
|
||||
* @static
|
||||
*/
|
||||
TOOLTIP.NAME = 'moodle-core-tooltip';
|
||||
|
||||
/**
|
||||
* Static property used to define the CSS prefix applied to tooltip dialogues.
|
||||
*
|
||||
* @property CSS_PREFIX
|
||||
* @type String
|
||||
* @static
|
||||
*/
|
||||
TOOLTIP.CSS_PREFIX = 'moodle-dialogue';
|
||||
|
||||
/**
|
||||
* Static property used to define the default attribute configuration for the Tooltip.
|
||||
*
|
||||
* @property ATTRS
|
||||
* @type String
|
||||
* @static
|
||||
*/
|
||||
TOOLTIP.ATTRS = ATTRS;
|
||||
|
||||
/**
|
||||
* The initial value of the header region before the content finishes loading.
|
||||
*
|
||||
* @attribute initialheadertext
|
||||
* @type String
|
||||
* @default ''
|
||||
* @writeOnce
|
||||
*/
|
||||
ATTRS.initialheadertext = {
|
||||
value: ''
|
||||
};
|
||||
|
||||
/**
|
||||
* The initial value of the body region before the content finishes loading.
|
||||
*
|
||||
* The supplid string will be wrapped in a div with the CSS.PANELTEXT class and a standard Moodle spinner
|
||||
* appended.
|
||||
*
|
||||
* @attribute initialbodytext
|
||||
* @type String
|
||||
* @default ''
|
||||
* @writeOnce
|
||||
*/
|
||||
ATTRS.initialbodytext = {
|
||||
value: '',
|
||||
setter: function(content) {
|
||||
var parentnode,
|
||||
spinner;
|
||||
parentnode = Y.Node.create('<div />')
|
||||
.addClass(CSS.PANELTEXT);
|
||||
|
||||
spinner = Y.Node.create('<img />')
|
||||
.setAttribute('src', M.util.image_url(RESOURCES.WAITICON.pix, RESOURCES.WAITICON.component))
|
||||
.addClass('spinner');
|
||||
|
||||
if (content) {
|
||||
// If we have been provided with content, add it to the parent and make
|
||||
// the spinner appear correctly inline
|
||||
parentnode.set('text', content);
|
||||
spinner.addClass('iconsmall');
|
||||
} else {
|
||||
// If there is no loading message, just make the parent node a lightbox
|
||||
parentnode.addClass('content-lightbox');
|
||||
}
|
||||
|
||||
parentnode.append(spinner);
|
||||
return parentnode;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* The initial value of the footer region before the content finishes loading.
|
||||
*
|
||||
* If a value is supplied, it will be wrapped in a <div> first.
|
||||
*
|
||||
* @attribute initialfootertext
|
||||
* @type String
|
||||
* @default ''
|
||||
* @writeOnce
|
||||
*/
|
||||
ATTRS.initialfootertext = {
|
||||
value: null,
|
||||
setter: function(content) {
|
||||
if (content) {
|
||||
return Y.Node.create('<div />')
|
||||
.set('text', content);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* The function which handles setting the content of the title region.
|
||||
* The specified function will be called with a context of the tooltip instance.
|
||||
*
|
||||
* The default function will simply set the value of the title to object.heading as returned by the AJAX call.
|
||||
*
|
||||
* @attribute headerhandler
|
||||
* @type Function|String|null
|
||||
* @default set_header_content
|
||||
*/
|
||||
ATTRS.headerhandler = {
|
||||
value: 'set_header_content'
|
||||
};
|
||||
|
||||
/**
|
||||
* The function which handles setting the content of the body region.
|
||||
* The specified function will be called with a context of the tooltip instance.
|
||||
*
|
||||
* The default function will simply set the value of the body area to a div containing object.text as returned
|
||||
* by the AJAX call.
|
||||
*
|
||||
* @attribute bodyhandler
|
||||
* @type Function|String|null
|
||||
* @default set_body_content
|
||||
*/
|
||||
ATTRS.bodyhandler = {
|
||||
value: 'set_body_content'
|
||||
};
|
||||
|
||||
/**
|
||||
* The function which handles setting the content of the footer region.
|
||||
* The specified function will be called with a context of the tooltip instance.
|
||||
*
|
||||
* By default, the footer is not set.
|
||||
*
|
||||
* @attribute footerhandler
|
||||
* @type Function|String|null
|
||||
* @default null
|
||||
*/
|
||||
ATTRS.footerhandler = {
|
||||
value: null
|
||||
};
|
||||
|
||||
/**
|
||||
* Set the Y.Cache object to use.
|
||||
*
|
||||
* By default a new Y.Cache object will be created for each instance of the tooltip.
|
||||
*
|
||||
* In certain situations, where multiple tooltips may share the same cache, it may be preferable to
|
||||
* seed this cache from the calling method.
|
||||
*
|
||||
* @attribute textcache
|
||||
* @type Y.Cache|null
|
||||
* @default null
|
||||
*/
|
||||
ATTRS.textcache = {
|
||||
value: null
|
||||
};
|
||||
|
||||
/**
|
||||
* Set the default size of the Y.Cache object.
|
||||
*
|
||||
* This is only used if no textcache is specified.
|
||||
*
|
||||
* @attribute textcachesize
|
||||
* @type Number
|
||||
* @default 10
|
||||
*/
|
||||
ATTRS.textcachesize = {
|
||||
value: 10
|
||||
};
|
||||
|
||||
Y.extend(TOOLTIP, M.core.dialogue, {
|
||||
// The bounding box.
|
||||
bb: null,
|
||||
|
||||
// Any event listeners we may need to cancel later.
|
||||
listenevents: [],
|
||||
|
||||
// Cache of objects we've already retrieved.
|
||||
textcache: null,
|
||||
|
||||
// The align position. This differs for RTL languages so we calculate once and store.
|
||||
alignpoints: [
|
||||
Y.WidgetPositionAlign.TL,
|
||||
Y.WidgetPositionAlign.RC
|
||||
],
|
||||
|
||||
initializer: function() {
|
||||
// Set the initial values for the handlers.
|
||||
// These cannot be set in the attributes section as context isn't present at that time.
|
||||
if (!this.get('headerhandler')) {
|
||||
this.set('headerhandler', this.set_header_content);
|
||||
}
|
||||
if (!this.get('bodyhandler')) {
|
||||
this.set('bodyhandler', this.set_body_content);
|
||||
}
|
||||
if (!this.get('footerhandler')) {
|
||||
this.set('footerhandler', function() {});
|
||||
}
|
||||
|
||||
// Set up the dialogue with initial content.
|
||||
this.setAttrs({
|
||||
headerContent: this.get('initialheadertext'),
|
||||
bodyContent: this.get('initialbodytext'),
|
||||
footerContent: this.get('initialfootertext'),
|
||||
zIndex: 150
|
||||
});
|
||||
|
||||
// Hide and then render the dialogue.
|
||||
this.hide();
|
||||
this.render();
|
||||
|
||||
// Hook into a few useful areas.
|
||||
this.bb = this.get('boundingBox');
|
||||
|
||||
// Change the alignment if this is an RTL language.
|
||||
if (right_to_left()) {
|
||||
this.alignpoints = [
|
||||
Y.WidgetPositionAlign.TR,
|
||||
Y.WidgetPositionAlign.LC
|
||||
];
|
||||
}
|
||||
|
||||
// Set up the text cache if it's not set up already.
|
||||
if (!this.get('textcache')) {
|
||||
this.set('textcache', new Y.Cache({
|
||||
// Set a reasonable maximum cache size to prevent memory growth.
|
||||
max: this.get('textcachesize')
|
||||
}));
|
||||
}
|
||||
|
||||
// Disable the textcache when in developerdebug.
|
||||
if (M.cfg.developerdebug) {
|
||||
this.get('textcache').set('max', 0);
|
||||
}
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Display the tooltip for the clicked link.
|
||||
*
|
||||
* The anchor for the clicked link is used, additionally appending ajax=1 to the parameters.
|
||||
*
|
||||
* @method display_panel
|
||||
* @param {EventFacade} e The event from the clicked link. This is used to determine the clicked URL.
|
||||
*/
|
||||
display_panel: function(e) {
|
||||
var clickedlink, thisevent, ajaxurl, config, cacheentry;
|
||||
|
||||
// Prevent the default click action and prevent the event triggering anything else.
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
|
||||
// Cancel any existing listeners and close the panel if it's already open.
|
||||
this.cancel_events();
|
||||
|
||||
// Grab the clickedlink - this contains the URL we fetch and we align the panel to it.
|
||||
clickedlink = e.target.ancestor('a', true);
|
||||
|
||||
// Align with the link that was clicked.
|
||||
this.align(clickedlink, this.alignpoints);
|
||||
|
||||
// Reset the initial text to a spinner while we retrieve the text.
|
||||
this.setAttrs({
|
||||
headerContent: this.get('initialheadertext'),
|
||||
bodyContent: this.get('initialbodytext'),
|
||||
footerContent: this.get('initialfootertext')
|
||||
});
|
||||
|
||||
// Now that initial setup has begun, show the panel.
|
||||
this.show();
|
||||
|
||||
// Add some listen events to close on.
|
||||
thisevent = this.bb.delegate('click', this.close_panel, SELECTORS.CLOSEBUTTON, this);
|
||||
this.listenevents.push(thisevent);
|
||||
|
||||
thisevent = Y.one('body').on('key', this.close_panel, 'esc', this);
|
||||
this.listenevents.push(thisevent);
|
||||
|
||||
// Listen for mousedownoutside events - clickoutside is broken on IE.
|
||||
thisevent = this.bb.on('mousedownoutside', this.close_panel, this);
|
||||
this.listenevents.push(thisevent);
|
||||
|
||||
ajaxurl = clickedlink.get('href');
|
||||
|
||||
cacheentry = this.get('textcache').retrieve(ajaxurl);
|
||||
if (cacheentry) {
|
||||
// The data from this help call was already cached so use that and avoid an AJAX call.
|
||||
this._set_panel_contents(cacheentry.response);
|
||||
} else {
|
||||
// Retrieve the actual help text we should use.
|
||||
config = {
|
||||
method: 'get',
|
||||
context: this,
|
||||
sync: false,
|
||||
data: {
|
||||
// We use a slightly different AJAX URL to the one on the anchor to allow non-JS fallback.
|
||||
ajax: 1
|
||||
},
|
||||
on: {
|
||||
complete: function(tid, response) {
|
||||
this._set_panel_contents(response.responseText, ajaxurl);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Y.io(clickedlink.get('href'), config);
|
||||
}
|
||||
},
|
||||
|
||||
_set_panel_contents: function(response, ajaxurl) {
|
||||
var responseobject;
|
||||
|
||||
// Attempt to parse the response into an object.
|
||||
try {
|
||||
responseobject = Y.JSON.parse(response);
|
||||
if (responseobject.error) {
|
||||
this.close_panel();
|
||||
return new M.core.ajaxException(responseobject);
|
||||
}
|
||||
} catch (error) {
|
||||
this.close_panel();
|
||||
return new M.core.exception({
|
||||
name: error.name,
|
||||
message: "Unable to retrieve the requested content. The following error was returned: " + error.message
|
||||
});
|
||||
}
|
||||
|
||||
// Set the contents using various handlers.
|
||||
// We must use Y.bind to ensure that the correct context is used when the default handlers are overridden.
|
||||
Y.bind(this.get('headerhandler'), this, responseobject)();
|
||||
Y.bind(this.get('bodyhandler'), this, responseobject)();
|
||||
Y.bind(this.get('footerhandler'), this, responseobject)();
|
||||
|
||||
if (ajaxurl) {
|
||||
// Ensure that this data is added to the cache.
|
||||
this.get('textcache').add(ajaxurl, response);
|
||||
}
|
||||
|
||||
this.get('buttons').header[0].focus();
|
||||
},
|
||||
|
||||
set_header_content: function(responseobject) {
|
||||
this.set('headerContent', responseobject.heading);
|
||||
},
|
||||
|
||||
set_body_content: function(responseobject) {
|
||||
var bodycontent = Y.Node.create('<div />')
|
||||
.set('innerHTML', responseobject.text)
|
||||
.setAttribute('role', 'alert')
|
||||
.addClass(CSS.PANELTEXT);
|
||||
this.set('bodyContent', bodycontent);
|
||||
},
|
||||
|
||||
close_panel: function(e) {
|
||||
// Hide the panel first.
|
||||
this.hide();
|
||||
|
||||
// Cancel the listeners that we added in display_panel.
|
||||
this.cancel_events();
|
||||
|
||||
// Prevent any default click that the close button may have.
|
||||
if (e) {
|
||||
e.preventDefault();
|
||||
}
|
||||
},
|
||||
|
||||
cancel_events: function() {
|
||||
// Detach all listen events to prevent duplicate triggers.
|
||||
var thisevent;
|
||||
while (this.listenevents.length) {
|
||||
thisevent = this.listenevents.shift();
|
||||
thisevent.detach();
|
||||
}
|
||||
}
|
||||
});
|
||||
M.core = M.core || {};
|
||||
M.core.tooltip = M.core.tooltip = TOOLTIP;
|
||||
|
||||
|
||||
}, '@VERSION@', {
|
||||
"requires": [
|
||||
"base",
|
||||
"node",
|
||||
"io-base",
|
||||
"moodle-core-notification",
|
||||
"json-parse",
|
||||
"widget-position",
|
||||
"widget-position-align",
|
||||
"event-outside",
|
||||
"cache"
|
||||
]
|
||||
});
|
1
lib/yui/build/moodle-core-tooltip/moodle-core-tooltip-min.js
vendored
Normal file
1
lib/yui/build/moodle-core-tooltip/moodle-core-tooltip-min.js
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
YUI.add("moodle-core-tooltip",function(e,t){function n(e){e||(e={}),typeof e.draggable=="undefined"&&(e.draggable=!0),typeof e.constrain=="undefined"&&(e.constrain=!0),typeof e.lightbox=="undefined"&&(e.lightbox=!1),n.superclass.constructor.apply(this,[e])}var r={CLOSEBUTTON:".closebutton"},i={PANELTEXT:"tooltiptext"},s={WAITICON:{pix:"i/loading_small",component:"moodle"}},o={};n.NAME="moodle-core-tooltip",n.CSS_PREFIX="moodle-dialogue",n.ATTRS=o,o.initialheadertext={value:""},o.initialbodytext={value:"",setter:function(t){var n,r;return n=e.Node.create("<div />").addClass(i.PANELTEXT),r=e.Node.create("<img />").setAttribute("src",M.util.image_url(s.WAITICON.pix,s.WAITICON.component)).addClass("spinner"),t?(n.set("text",t),r.addClass("iconsmall")):n.addClass("content-lightbox"),n.append(r),n}},o.initialfootertext={value:null,setter:function(t){if(t)return e.Node.create("<div />").set("text",t)}},o.headerhandler={value:"set_header_content"},o.bodyhandler={value:"set_body_content"},o.footerhandler={value:null},o.textcache={value:null},o.textcachesize={value:10},e.extend(n,M.core.dialogue,{bb:null,listenevents:[],textcache:null,alignpoints:[e.WidgetPositionAlign.TL,e.WidgetPositionAlign.RC],initializer:function(){return this.get("headerhandler")||this.set("headerhandler",this.set_header_content),this.get("bodyhandler")||this.set("bodyhandler",this.set_body_content),this.get("footerhandler")||this.set("footerhandler",function(){}),this.setAttrs({headerContent:this.get("initialheadertext"),bodyContent:this.get("initialbodytext"),footerContent:this.get("initialfootertext"),zIndex:150}),this.hide(),this.render(),this.bb=this.get("boundingBox"),right_to_left()&&(this.alignpoints=[e.WidgetPositionAlign.TR,e.WidgetPositionAlign.LC]),this.get("textcache")||this.set("textcache",new e.Cache({max:this.get("textcachesize")})),M.cfg.developerdebug&&this.get("textcache").set("max",0),this},display_panel:function(t){var n,i,s,o,u;t.preventDefault(),t.stopPropagation(),this.cancel_events(),n=t.target.ancestor("a",!0),this.align(n,this.alignpoints),this.setAttrs({headerContent:this.get("initialheadertext"),bodyContent:this.get("initialbodytext"),footerContent:this.get("initialfootertext")}),this.show(),i=this.bb.delegate("click",this.close_panel,r.CLOSEBUTTON,this),this.listenevents.push(i),i=e.one("body").on("key",this.close_panel,"esc",this),this.listenevents.push(i),i=this.bb.on("mousedownoutside",this.close_panel,this),this.listenevents.push(i),s=n.get("href"),u=this.get("textcache").retrieve(s),u?this._set_panel_contents(u.response):(o={method:"get",context:this,sync:!1,data:{ajax:1},on:{complete:function(e,t){this._set_panel_contents(t.responseText,s)}}},e.io(n.get("href"),o))},_set_panel_contents:function(t,n){var r;try{r=e.JSON.parse(t);if(r.error)return this.close_panel(),new M.core.ajaxException(r)}catch(i){return this.close_panel(),new M.core.exception({name:i.name,message:"Unable to retrieve the requested content. The following error was returned: "+i.message})}e.bind(this.get("headerhandler"),this,r)(),e.bind(this.get("bodyhandler"),this,r)(),e.bind(this.get("footerhandler"),this,r)(),n&&this.get("textcache").add(n,t),this.get("buttons").header[0].focus()},set_header_content:function(e){this.set("headerContent",e.heading)},set_body_content:function(t){var n=e.Node.create("<div />").set("innerHTML",t.text).setAttribute("role","alert").addClass(i.PANELTEXT);this.set("bodyContent",n)},close_panel:function(e){this.hide(),this.cancel_events(),e&&e.preventDefault()},cancel_events:function(){var e;while(this.listenevents.length)e=this.listenevents.shift(),e.detach()}}),M.core=M.core||{},M.core.tooltip=M.core.tooltip=n},"@VERSION@",{requires:["base","node","io-base","moodle-core-notification","json-parse","widget-position","widget-position-align","event-outside","cache"]});
|
444
lib/yui/build/moodle-core-tooltip/moodle-core-tooltip.js
vendored
Normal file
444
lib/yui/build/moodle-core-tooltip/moodle-core-tooltip.js
vendored
Normal file
|
@ -0,0 +1,444 @@
|
|||
YUI.add('moodle-core-tooltip', function (Y, NAME) {
|
||||
|
||||
/**
|
||||
* Provides the base tooltip class.
|
||||
*
|
||||
* @module moodle-core-tooltip
|
||||
*/
|
||||
|
||||
/**
|
||||
* A base class for a tooltip.
|
||||
*
|
||||
* @param {Object} config Object literal specifying tooltip configuration properties.
|
||||
* @class M.core.tooltip
|
||||
* @constructor
|
||||
* @extends M.core.dialogue
|
||||
*/
|
||||
function TOOLTIP(config) {
|
||||
if (!config) {
|
||||
config = {};
|
||||
}
|
||||
|
||||
// Override the default options provided by the parent class.
|
||||
if (typeof config.draggable === 'undefined') {
|
||||
config.draggable = true;
|
||||
}
|
||||
|
||||
if (typeof config.constrain === 'undefined') {
|
||||
config.constrain = true;
|
||||
}
|
||||
|
||||
if (typeof config.lightbox === 'undefined') {
|
||||
config.lightbox = false;
|
||||
}
|
||||
|
||||
TOOLTIP.superclass.constructor.apply(this, [config]);
|
||||
}
|
||||
|
||||
var SELECTORS = {
|
||||
CLOSEBUTTON: '.closebutton'
|
||||
},
|
||||
|
||||
CSS = {
|
||||
PANELTEXT: 'tooltiptext'
|
||||
},
|
||||
RESOURCES = {
|
||||
WAITICON: {
|
||||
pix: 'i/loading_small',
|
||||
component: 'moodle'
|
||||
}
|
||||
},
|
||||
ATTRS = {};
|
||||
|
||||
/**
|
||||
* Static property provides a string to identify the JavaScript class.
|
||||
*
|
||||
* @property NAME
|
||||
* @type String
|
||||
* @static
|
||||
*/
|
||||
TOOLTIP.NAME = 'moodle-core-tooltip';
|
||||
|
||||
/**
|
||||
* Static property used to define the CSS prefix applied to tooltip dialogues.
|
||||
*
|
||||
* @property CSS_PREFIX
|
||||
* @type String
|
||||
* @static
|
||||
*/
|
||||
TOOLTIP.CSS_PREFIX = 'moodle-dialogue';
|
||||
|
||||
/**
|
||||
* Static property used to define the default attribute configuration for the Tooltip.
|
||||
*
|
||||
* @property ATTRS
|
||||
* @type String
|
||||
* @static
|
||||
*/
|
||||
TOOLTIP.ATTRS = ATTRS;
|
||||
|
||||
/**
|
||||
* The initial value of the header region before the content finishes loading.
|
||||
*
|
||||
* @attribute initialheadertext
|
||||
* @type String
|
||||
* @default ''
|
||||
* @writeOnce
|
||||
*/
|
||||
ATTRS.initialheadertext = {
|
||||
value: ''
|
||||
};
|
||||
|
||||
/**
|
||||
* The initial value of the body region before the content finishes loading.
|
||||
*
|
||||
* The supplid string will be wrapped in a div with the CSS.PANELTEXT class and a standard Moodle spinner
|
||||
* appended.
|
||||
*
|
||||
* @attribute initialbodytext
|
||||
* @type String
|
||||
* @default ''
|
||||
* @writeOnce
|
||||
*/
|
||||
ATTRS.initialbodytext = {
|
||||
value: '',
|
||||
setter: function(content) {
|
||||
var parentnode,
|
||||
spinner;
|
||||
parentnode = Y.Node.create('<div />')
|
||||
.addClass(CSS.PANELTEXT);
|
||||
|
||||
spinner = Y.Node.create('<img />')
|
||||
.setAttribute('src', M.util.image_url(RESOURCES.WAITICON.pix, RESOURCES.WAITICON.component))
|
||||
.addClass('spinner');
|
||||
|
||||
if (content) {
|
||||
// If we have been provided with content, add it to the parent and make
|
||||
// the spinner appear correctly inline
|
||||
parentnode.set('text', content);
|
||||
spinner.addClass('iconsmall');
|
||||
} else {
|
||||
// If there is no loading message, just make the parent node a lightbox
|
||||
parentnode.addClass('content-lightbox');
|
||||
}
|
||||
|
||||
parentnode.append(spinner);
|
||||
return parentnode;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* The initial value of the footer region before the content finishes loading.
|
||||
*
|
||||
* If a value is supplied, it will be wrapped in a <div> first.
|
||||
*
|
||||
* @attribute initialfootertext
|
||||
* @type String
|
||||
* @default ''
|
||||
* @writeOnce
|
||||
*/
|
||||
ATTRS.initialfootertext = {
|
||||
value: null,
|
||||
setter: function(content) {
|
||||
if (content) {
|
||||
return Y.Node.create('<div />')
|
||||
.set('text', content);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* The function which handles setting the content of the title region.
|
||||
* The specified function will be called with a context of the tooltip instance.
|
||||
*
|
||||
* The default function will simply set the value of the title to object.heading as returned by the AJAX call.
|
||||
*
|
||||
* @attribute headerhandler
|
||||
* @type Function|String|null
|
||||
* @default set_header_content
|
||||
*/
|
||||
ATTRS.headerhandler = {
|
||||
value: 'set_header_content'
|
||||
};
|
||||
|
||||
/**
|
||||
* The function which handles setting the content of the body region.
|
||||
* The specified function will be called with a context of the tooltip instance.
|
||||
*
|
||||
* The default function will simply set the value of the body area to a div containing object.text as returned
|
||||
* by the AJAX call.
|
||||
*
|
||||
* @attribute bodyhandler
|
||||
* @type Function|String|null
|
||||
* @default set_body_content
|
||||
*/
|
||||
ATTRS.bodyhandler = {
|
||||
value: 'set_body_content'
|
||||
};
|
||||
|
||||
/**
|
||||
* The function which handles setting the content of the footer region.
|
||||
* The specified function will be called with a context of the tooltip instance.
|
||||
*
|
||||
* By default, the footer is not set.
|
||||
*
|
||||
* @attribute footerhandler
|
||||
* @type Function|String|null
|
||||
* @default null
|
||||
*/
|
||||
ATTRS.footerhandler = {
|
||||
value: null
|
||||
};
|
||||
|
||||
/**
|
||||
* Set the Y.Cache object to use.
|
||||
*
|
||||
* By default a new Y.Cache object will be created for each instance of the tooltip.
|
||||
*
|
||||
* In certain situations, where multiple tooltips may share the same cache, it may be preferable to
|
||||
* seed this cache from the calling method.
|
||||
*
|
||||
* @attribute textcache
|
||||
* @type Y.Cache|null
|
||||
* @default null
|
||||
*/
|
||||
ATTRS.textcache = {
|
||||
value: null
|
||||
};
|
||||
|
||||
/**
|
||||
* Set the default size of the Y.Cache object.
|
||||
*
|
||||
* This is only used if no textcache is specified.
|
||||
*
|
||||
* @attribute textcachesize
|
||||
* @type Number
|
||||
* @default 10
|
||||
*/
|
||||
ATTRS.textcachesize = {
|
||||
value: 10
|
||||
};
|
||||
|
||||
Y.extend(TOOLTIP, M.core.dialogue, {
|
||||
// The bounding box.
|
||||
bb: null,
|
||||
|
||||
// Any event listeners we may need to cancel later.
|
||||
listenevents: [],
|
||||
|
||||
// Cache of objects we've already retrieved.
|
||||
textcache: null,
|
||||
|
||||
// The align position. This differs for RTL languages so we calculate once and store.
|
||||
alignpoints: [
|
||||
Y.WidgetPositionAlign.TL,
|
||||
Y.WidgetPositionAlign.RC
|
||||
],
|
||||
|
||||
initializer: function() {
|
||||
// Set the initial values for the handlers.
|
||||
// These cannot be set in the attributes section as context isn't present at that time.
|
||||
if (!this.get('headerhandler')) {
|
||||
this.set('headerhandler', this.set_header_content);
|
||||
}
|
||||
if (!this.get('bodyhandler')) {
|
||||
this.set('bodyhandler', this.set_body_content);
|
||||
}
|
||||
if (!this.get('footerhandler')) {
|
||||
this.set('footerhandler', function() {});
|
||||
}
|
||||
|
||||
// Set up the dialogue with initial content.
|
||||
this.setAttrs({
|
||||
headerContent: this.get('initialheadertext'),
|
||||
bodyContent: this.get('initialbodytext'),
|
||||
footerContent: this.get('initialfootertext'),
|
||||
zIndex: 150
|
||||
});
|
||||
|
||||
// Hide and then render the dialogue.
|
||||
this.hide();
|
||||
this.render();
|
||||
|
||||
// Hook into a few useful areas.
|
||||
this.bb = this.get('boundingBox');
|
||||
|
||||
// Change the alignment if this is an RTL language.
|
||||
if (right_to_left()) {
|
||||
this.alignpoints = [
|
||||
Y.WidgetPositionAlign.TR,
|
||||
Y.WidgetPositionAlign.LC
|
||||
];
|
||||
}
|
||||
|
||||
// Set up the text cache if it's not set up already.
|
||||
if (!this.get('textcache')) {
|
||||
this.set('textcache', new Y.Cache({
|
||||
// Set a reasonable maximum cache size to prevent memory growth.
|
||||
max: this.get('textcachesize')
|
||||
}));
|
||||
}
|
||||
|
||||
// Disable the textcache when in developerdebug.
|
||||
if (M.cfg.developerdebug) {
|
||||
this.get('textcache').set('max', 0);
|
||||
}
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Display the tooltip for the clicked link.
|
||||
*
|
||||
* The anchor for the clicked link is used, additionally appending ajax=1 to the parameters.
|
||||
*
|
||||
* @method display_panel
|
||||
* @param {EventFacade} e The event from the clicked link. This is used to determine the clicked URL.
|
||||
*/
|
||||
display_panel: function(e) {
|
||||
var clickedlink, thisevent, ajaxurl, config, cacheentry;
|
||||
|
||||
// Prevent the default click action and prevent the event triggering anything else.
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
|
||||
// Cancel any existing listeners and close the panel if it's already open.
|
||||
this.cancel_events();
|
||||
|
||||
// Grab the clickedlink - this contains the URL we fetch and we align the panel to it.
|
||||
clickedlink = e.target.ancestor('a', true);
|
||||
|
||||
// Align with the link that was clicked.
|
||||
this.align(clickedlink, this.alignpoints);
|
||||
|
||||
// Reset the initial text to a spinner while we retrieve the text.
|
||||
this.setAttrs({
|
||||
headerContent: this.get('initialheadertext'),
|
||||
bodyContent: this.get('initialbodytext'),
|
||||
footerContent: this.get('initialfootertext')
|
||||
});
|
||||
|
||||
// Now that initial setup has begun, show the panel.
|
||||
this.show();
|
||||
|
||||
// Add some listen events to close on.
|
||||
thisevent = this.bb.delegate('click', this.close_panel, SELECTORS.CLOSEBUTTON, this);
|
||||
this.listenevents.push(thisevent);
|
||||
|
||||
thisevent = Y.one('body').on('key', this.close_panel, 'esc', this);
|
||||
this.listenevents.push(thisevent);
|
||||
|
||||
// Listen for mousedownoutside events - clickoutside is broken on IE.
|
||||
thisevent = this.bb.on('mousedownoutside', this.close_panel, this);
|
||||
this.listenevents.push(thisevent);
|
||||
|
||||
ajaxurl = clickedlink.get('href');
|
||||
|
||||
cacheentry = this.get('textcache').retrieve(ajaxurl);
|
||||
if (cacheentry) {
|
||||
// The data from this help call was already cached so use that and avoid an AJAX call.
|
||||
this._set_panel_contents(cacheentry.response);
|
||||
} else {
|
||||
// Retrieve the actual help text we should use.
|
||||
config = {
|
||||
method: 'get',
|
||||
context: this,
|
||||
sync: false,
|
||||
data: {
|
||||
// We use a slightly different AJAX URL to the one on the anchor to allow non-JS fallback.
|
||||
ajax: 1
|
||||
},
|
||||
on: {
|
||||
complete: function(tid, response) {
|
||||
this._set_panel_contents(response.responseText, ajaxurl);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Y.io(clickedlink.get('href'), config);
|
||||
}
|
||||
},
|
||||
|
||||
_set_panel_contents: function(response, ajaxurl) {
|
||||
var responseobject;
|
||||
|
||||
// Attempt to parse the response into an object.
|
||||
try {
|
||||
responseobject = Y.JSON.parse(response);
|
||||
if (responseobject.error) {
|
||||
this.close_panel();
|
||||
return new M.core.ajaxException(responseobject);
|
||||
}
|
||||
} catch (error) {
|
||||
this.close_panel();
|
||||
return new M.core.exception({
|
||||
name: error.name,
|
||||
message: "Unable to retrieve the requested content. The following error was returned: " + error.message
|
||||
});
|
||||
}
|
||||
|
||||
// Set the contents using various handlers.
|
||||
// We must use Y.bind to ensure that the correct context is used when the default handlers are overridden.
|
||||
Y.bind(this.get('headerhandler'), this, responseobject)();
|
||||
Y.bind(this.get('bodyhandler'), this, responseobject)();
|
||||
Y.bind(this.get('footerhandler'), this, responseobject)();
|
||||
|
||||
if (ajaxurl) {
|
||||
// Ensure that this data is added to the cache.
|
||||
this.get('textcache').add(ajaxurl, response);
|
||||
}
|
||||
|
||||
this.get('buttons').header[0].focus();
|
||||
},
|
||||
|
||||
set_header_content: function(responseobject) {
|
||||
this.set('headerContent', responseobject.heading);
|
||||
},
|
||||
|
||||
set_body_content: function(responseobject) {
|
||||
var bodycontent = Y.Node.create('<div />')
|
||||
.set('innerHTML', responseobject.text)
|
||||
.setAttribute('role', 'alert')
|
||||
.addClass(CSS.PANELTEXT);
|
||||
this.set('bodyContent', bodycontent);
|
||||
},
|
||||
|
||||
close_panel: function(e) {
|
||||
// Hide the panel first.
|
||||
this.hide();
|
||||
|
||||
// Cancel the listeners that we added in display_panel.
|
||||
this.cancel_events();
|
||||
|
||||
// Prevent any default click that the close button may have.
|
||||
if (e) {
|
||||
e.preventDefault();
|
||||
}
|
||||
},
|
||||
|
||||
cancel_events: function() {
|
||||
// Detach all listen events to prevent duplicate triggers.
|
||||
var thisevent;
|
||||
while (this.listenevents.length) {
|
||||
thisevent = this.listenevents.shift();
|
||||
thisevent.detach();
|
||||
}
|
||||
}
|
||||
});
|
||||
M.core = M.core || {};
|
||||
M.core.tooltip = M.core.tooltip = TOOLTIP;
|
||||
|
||||
|
||||
}, '@VERSION@', {
|
||||
"requires": [
|
||||
"base",
|
||||
"node",
|
||||
"io-base",
|
||||
"moodle-core-notification",
|
||||
"json-parse",
|
||||
"widget-position",
|
||||
"widget-position-align",
|
||||
"event-outside",
|
||||
"cache"
|
||||
]
|
||||
});
|
10
lib/yui/src/tooltip/build.json
Normal file
10
lib/yui/src/tooltip/build.json
Normal file
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"name": "moodle-core-tooltip",
|
||||
"builds": {
|
||||
"moodle-core-tooltip": {
|
||||
"jsfiles": [
|
||||
"tooltip.js"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,4 +1,3 @@
|
|||
YUI.add('moodle-core-tooltip', function(Y) {
|
||||
/**
|
||||
* Provides the base tooltip class.
|
||||
*
|
||||
|
@ -426,9 +425,3 @@ YUI.add('moodle-core-tooltip', function(Y) {
|
|||
});
|
||||
M.core = M.core || {};
|
||||
M.core.tooltip = M.core.tooltip = TOOLTIP;
|
||||
},
|
||||
'@VERSION@', {
|
||||
requires: ['base', 'io-base', 'moodle-core-notification', 'json-parse',
|
||||
'widget-position', 'widget-position-align', 'event-outside', 'cache']
|
||||
}
|
||||
);
|
15
lib/yui/src/tooltip/meta/tooltip.json
Normal file
15
lib/yui/src/tooltip/meta/tooltip.json
Normal file
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
"moodle-core-tooltip": {
|
||||
"requires": [
|
||||
"base",
|
||||
"node",
|
||||
"io-base",
|
||||
"moodle-core-notification",
|
||||
"json-parse",
|
||||
"widget-position",
|
||||
"widget-position-align",
|
||||
"event-outside",
|
||||
"cache"
|
||||
]
|
||||
}
|
||||
}
|
|
@ -73,6 +73,7 @@ foreach ($parts as $part) {
|
|||
if (empty($part)) {
|
||||
continue;
|
||||
}
|
||||
$filecontent = '';
|
||||
$part = min_clean_param($part, 'SAFEPATH');
|
||||
$bits = explode('/', $part);
|
||||
if (count($bits) < 2) {
|
||||
|
@ -95,13 +96,27 @@ foreach ($parts as $part) {
|
|||
}
|
||||
$frankenstyle = array_shift($bits);
|
||||
$filename = array_pop($bits);
|
||||
$modulename = $bits[0];
|
||||
$dir = get_component_directory($frankenstyle);
|
||||
if ($mimetype == 'text/css') {
|
||||
$bits[] = 'assets';
|
||||
$bits[] = 'skins';
|
||||
$bits[] = 'sam';
|
||||
}
|
||||
$contentfile = $dir.'/yui/'.join('/', $bits).'/'.$filename;
|
||||
|
||||
// For shifted YUI modules, we need the YUI module name in frankenstyle format.
|
||||
$frankenstylemodulename = join('-', array($version, $frankenstyle, $modulename));
|
||||
|
||||
// By default, try and use the /yui/build directory.
|
||||
$frankenstylefilename = preg_replace('/' . $modulename . '/', $frankenstylemodulename, $filename);
|
||||
$contentfile = $dir . '/yui/build/' . $frankenstylemodulename . '/' . $frankenstylefilename;
|
||||
|
||||
// If the shifted versions don't exist, fall back to the non-shifted file.
|
||||
if (!file_exists($contentfile) or !is_file($contentfile)) {
|
||||
// We have to revert to the non-minified and non-debug versions.
|
||||
$filename = preg_replace('/-(min|debug)\./', '.', $filename);
|
||||
$contentfile = $dir . '/yui/' . join('/', $bits) . '/' . $filename;
|
||||
}
|
||||
} else if ($version === '2in3') {
|
||||
$contentfile = "$CFG->libdir/yuilib/$part";
|
||||
|
||||
|
@ -120,7 +135,10 @@ foreach ($parts as $part) {
|
|||
$content .= "\n// Combo resource $part ($location) not found!\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
if (empty($filecontent)) {
|
||||
$filecontent = file_get_contents($contentfile);
|
||||
}
|
||||
$fmodified = filemtime($contentfile);
|
||||
if ($fmodified > $lastmodified) {
|
||||
$lastmodified = $fmodified;
|
||||
|
@ -131,8 +149,16 @@ foreach ($parts as $part) {
|
|||
|
||||
if ($mimetype === 'text/css') {
|
||||
if ($version == 'moodle') {
|
||||
$filecontent = preg_replace('/([a-z0-9_-]+)\.(png|gif)/', $relroot.'/theme/yui_image.php'.$sep.$version.'/'.$frankenstyle.'/'.array_shift($bits).'/$1.$2', $filecontent);
|
||||
// Search for all images in the file and replace with an appropriate link to the yui_image.php script
|
||||
$imagebits = array(
|
||||
$sep . $version,
|
||||
$frankenstyle,
|
||||
$modulename,
|
||||
array_shift($bits),
|
||||
'$1.$2'
|
||||
);
|
||||
|
||||
$filecontent = preg_replace('/([a-z0-9_-]+)\.(png|gif)/', $relroot . '/theme/yui_image.php' . implode('/', $imagebits), $filecontent);
|
||||
} else if ($version == '2in3') {
|
||||
// First we need to remove relative paths to images. These are used by YUI modules to make use of global assets.
|
||||
// I've added this as a separate regex so it can be easily removed once
|
||||
|
|
|
@ -41,7 +41,6 @@ if ($slashargument = min_get_slash_argument()) {
|
|||
$etag = sha1($path);
|
||||
$parts = explode('/', $path);
|
||||
$version = array_shift($parts);
|
||||
|
||||
if ($version == 'moodle' && count($parts) >= 3) {
|
||||
if (!defined('ABORT_AFTER_CONFIG_CANCEL')) {
|
||||
define('ABORT_AFTER_CONFIG_CANCEL', true);
|
||||
|
@ -54,7 +53,17 @@ if ($version == 'moodle' && count($parts) >= 3) {
|
|||
$image = array_pop($parts);
|
||||
$subdir = join('/', $parts);
|
||||
$dir = get_component_directory($frankenstyle);
|
||||
$imagepath = $dir.'/yui/'.$module.'/assets/skins/sam/'.$image;
|
||||
|
||||
// For shifted YUI modules, we need the YUI module name in frankenstyle format.
|
||||
$frankenstylemodulename = join('-', array($version, $frankenstyle, $module));
|
||||
|
||||
// By default, try and use the /yui/build directory.
|
||||
$imagepath = $dir . '/yui/build/' . $frankenstylemodulename . '/assets/skins/sam/' . $image;
|
||||
|
||||
// If the shifted versions don't exist, fall back to the non-shifted file.
|
||||
if (!file_exists($imagepath) or !is_file($imagepath)) {
|
||||
$imagepath = $dir . '/yui/' . $module . '/assets/skins/sam/' . $image;
|
||||
}
|
||||
} else if ($version == 'gallery' && count($parts)==3) {
|
||||
list($module, $version, $image) = $parts;
|
||||
$imagepath = "$CFG->dirroot/lib/yui/gallery/$module/$version/assets/skins/sam/$image";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue