mirror of
https://github.com/moodle/moodle.git
synced 2025-04-22 08:55:15 +02:00
Merge branch 'MDL-52204-master' of git://github.com/danpoltawski/moodle
This commit is contained in:
commit
0575c5ad8c
2
lib/amd/build/form-autocomplete.min.js
vendored
2
lib/amd/build/form-autocomplete.min.js
vendored
File diff suppressed because one or more lines are too long
2
lib/amd/build/templates.min.js
vendored
2
lib/amd/build/templates.min.js
vendored
@ -1 +1 @@
|
||||
define(["core/mustache","jquery","core/ajax","core/str","core/notification","core/url","core/config","core/localstorage","core/event"],function(a,b,c,d,e,f,g,h,i){var j={},k=[],l=[],m=1,n="",o=function(b,c){var d,e=b.split(","),g="",h="",i="";e.length>0&&(g=e.shift().trim()),e.length>0&&(h=e.shift().trim()),e.length>0&&(i=e.join(",").trim());var k=f.imageUrl(g,h),l={attributes:[{name:"src",value:k},{name:"alt",value:c(i)},{name:"class",value:"smallicon"}]},m=j[n+"/core/pix_icon"];return d=a.render(m,l,p),d.trim()},p=function(a){var b="";return v(a,!1).done(function(a){b=a}).fail(e.exception),b},q=function(a,b){return l.push(b(a,this)),""},r=function(a,b){var c=a.split(","),d="",e="",f="";c.length>0&&(d=c.shift().trim()),c.length>0&&(e=c.shift().trim()),c.length>0&&(f=c.join(",").trim()),""!==f&&(f=b(f,this)),0===f.indexOf("{")&&0!==f.indexOf("{{")&&(f=JSON.parse(f));var g=k.length;return k.push({key:d,component:e,param:f}),"{{_s"+g+"}}"},s=function(a,b){n=b,k=[],l=[],a.uniqid=m++,a.str=function(){return r},a.pix=function(){return o},a.js=function(){return q},a.globals={config:g},a.currentTheme=b},t=function(a){var b="";l.length>0&&(b=l.join(";\n"));var c=0;for(c=0;c<a.length;c++)b=b.replace("{{_s"+c+"}}",a[c]);return b},u=function(c,e,f){var g=b.Deferred();n=f;var h=v("core/pix_icon",!0);return h.done(function(){s(e,f);var b="";try{b=a.render(c,e,p)}catch(h){g.reject(h)}k.length>0?d.get_strings(k).done(function(a){var c;for(c=0;c<a.length;c++)b=b.replace("{{_s"+c+"}}",a[c]);g.resolve(b.trim(),t(a))}).fail(function(a){g.reject(a)}):g.resolve(b.trim(),t([]))}).fail(function(a){g.reject(a)}),g.promise()},v=function(a,d){var e=b.Deferred(),f=a.split("/"),g=f.shift(),i=f.shift(),k=n+"/"+a;if(k in j)return e.resolve(j[k]),e.promise();var l=h.get("core_template/"+k);if(l)return e.resolve(l),j[k]=l,e.promise();var m=c.call([{methodname:"core_output_load_template",args:{component:g,template:i,themename:n}}],d,!1);return m[0].done(function(a){h.set("core_template/"+k,a),j[k]=a,e.resolve(a)}).fail(function(a){e.reject(a)}),e.promise()},w=function(a){if(""!==a.trim()){var c=b("<script>").attr("type","text/javascript").html(a);b("head").append(c)}},x=function(a,c,d,e){var f=b(a);if(f.length){var g=b(c);e?(f.empty(),f.append(g)):f.replaceWith(g),w(d),i.notifyFilterContentUpdated(g)}};return{render:function(a,c,d){var e=b.Deferred();"undefined"==typeof d&&(d=g.theme),n=d;var f=v(a,!0);return f.done(function(a){var b=u(a,c,d);b.done(function(a,b){e.resolve(a,b)}).fail(function(a){e.reject(a)})}).fail(function(a){e.reject(a)}),e.promise()},runTemplateJS:w,replaceNodeContents:function(a,b,c){return x(a,b,c,!0)},replaceNode:function(a,b,c){return x(a,b,c,!1)}}});
|
||||
define(["core/mustache","jquery","core/ajax","core/str","core/notification","core/url","core/config","core/localstorage","core/event"],function(a,b,c,d,e,f,g,h,i){var j={},k=[],l=[],m=1,n="",o=function(a,d){var e=b.Deferred(),f=a.split("/"),g=f.shift(),i=f.shift(),k=n+"/"+a;if(k in j)return e.resolve(j[k]),e.promise();var l=h.get("core_template/"+k);if(l)return e.resolve(l),j[k]=l,e.promise();var m=c.call([{methodname:"core_output_load_template",args:{component:g,template:i,themename:n}}],d,!1);return m[0].done(function(a){h.set("core_template/"+k,a),j[k]=a,e.resolve(a)}).fail(function(a){e.reject(a)}),e.promise()},p=function(a){var b="";return o(a,!1).done(function(a){b=a}).fail(e.exception),b},q=function(b,c){var d,e=b.split(","),g="",h="",i="";e.length>0&&(g=e.shift().trim()),e.length>0&&(h=e.shift().trim()),e.length>0&&(i=e.join(",").trim());var k=f.imageUrl(g,h),l={attributes:[{name:"src",value:k},{name:"alt",value:c(i)},{name:"class",value:"smallicon"}]},m=j[n+"/core/pix_icon"];return d=a.render(m,l,p),d.trim()},r=function(a,b){return l.push(b(a,this)),""},s=function(a,b){var c=a.split(","),d="",e="",f="";c.length>0&&(d=c.shift().trim()),c.length>0&&(e=c.shift().trim()),c.length>0&&(f=c.join(",").trim()),""!==f&&(f=b(f,this)),0===f.indexOf("{")&&0!==f.indexOf("{{")&&(f=JSON.parse(f));var g=k.length;return k.push({key:d,component:e,param:f}),"{{_s"+g+"}}"},t=function(a,b){n=b,k=[],l=[],a.uniqid=m++,a.str=function(){return s},a.pix=function(){return q},a.js=function(){return r},a.globals={config:g},a.currentTheme=b},u=function(a){var b="";l.length>0&&(b=l.join(";\n"));var c=0;for(c=0;c<a.length;c++)b=b.replace("{{_s"+c+"}}",a[c]);return b},v=function(c,e,f){var g=b.Deferred();n=f;var h=o("core/pix_icon",!0);return h.done(function(){t(e,f);var b="";try{b=a.render(c,e,p)}catch(h){g.reject(h)}k.length>0?d.get_strings(k).done(function(a){var c;for(c=0;c<a.length;c++)b=b.replace("{{_s"+c+"}}",a[c]);g.resolve(b.trim(),u(a))}).fail(function(a){g.reject(a)}):g.resolve(b.trim(),u([]))}).fail(function(a){g.reject(a)}),g.promise()},w=function(a){if(""!==a.trim()){var c=b("<script>").attr("type","text/javascript").html(a);b("head").append(c)}},x=function(a,c,d,e){var f=b(a);if(f.length){var g=b(c);e?(f.empty(),f.append(g)):f.replaceWith(g),w(d),i.notifyFilterContentUpdated(g)}};return{render:function(a,c,d){var e=b.Deferred();"undefined"==typeof d&&(d=g.theme),n=d;var f=o(a,!0);return f.done(function(a){var b=v(a,c,d);b.done(function(a,b){e.resolve(a,b)}).fail(function(a){e.reject(a)})}).fail(function(a){e.reject(a)}),e.promise()},runTemplateJS:w,replaceNodeContents:function(a,b,c){return x(a,b,c,!0)},replaceNode:function(a,b,c){return x(a,b,c,!1)}}});
|
@ -69,6 +69,52 @@ define(['jquery', 'core/log', 'core/str', 'core/templates', 'core/notification']
|
||||
selectionElement.attr('aria-activedescendant', itemId);
|
||||
};
|
||||
|
||||
/**
|
||||
* Update the element that shows the currently selected items.
|
||||
*
|
||||
* @method updateSelectionList
|
||||
* @private
|
||||
* @param {Object} options Original options for this autocomplete element.
|
||||
* @param {Object} state State variables for this autocomplete element.
|
||||
* @param {JQuery} originalSelect The JQuery object matching the hidden select list.
|
||||
*/
|
||||
var updateSelectionList = function(options, state, originalSelect) {
|
||||
// Build up a valid context to re-render the template.
|
||||
var items = [];
|
||||
var newSelection = $(document.getElementById(state.selectionId));
|
||||
var activeId = newSelection.attr('aria-activedescendant');
|
||||
var activeValue = false;
|
||||
|
||||
if (activeId) {
|
||||
activeValue = $(document.getElementById(activeId)).attr('data-value');
|
||||
}
|
||||
originalSelect.children('option').each(function(index, ele) {
|
||||
if ($(ele).prop('selected')) {
|
||||
items.push( { label: $(ele).html(), value: $(ele).attr('value') } );
|
||||
}
|
||||
});
|
||||
var context = $.extend({ items: items }, options, state);
|
||||
|
||||
// Render the template.
|
||||
templates.render('core/form_autocomplete_selection', context).done(function(newHTML) {
|
||||
// Add it to the page.
|
||||
newSelection.empty().append($(newHTML).html());
|
||||
|
||||
if (activeValue !== false) {
|
||||
// Reselect any previously selected item.
|
||||
newSelection.children('[aria-selected=true]').each(function(index, ele) {
|
||||
if ($(ele).attr('data-value') === activeValue) {
|
||||
activateSelection(index, state);
|
||||
}
|
||||
});
|
||||
}
|
||||
}).fail(notification.exception);
|
||||
// Because this function get's called after changing the selection, this is a good place
|
||||
// to trigger a change notification.
|
||||
originalSelect.change();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Remove the given item from the list of selected things.
|
||||
*
|
||||
@ -360,51 +406,6 @@ define(['jquery', 'core/log', 'core/str', 'core/templates', 'core/notification']
|
||||
closeSuggestions(state);
|
||||
};
|
||||
|
||||
/**
|
||||
* Update the element that shows the currently selected items.
|
||||
*
|
||||
* @method updateSelectionList
|
||||
* @private
|
||||
* @param {Object} options Original options for this autocomplete element.
|
||||
* @param {Object} state State variables for this autocomplete element.
|
||||
* @param {JQuery} originalSelect The JQuery object matching the hidden select list.
|
||||
*/
|
||||
var updateSelectionList = function(options, state, originalSelect) {
|
||||
// Build up a valid context to re-render the template.
|
||||
var items = [];
|
||||
var newSelection = $(document.getElementById(state.selectionId));
|
||||
var activeId = newSelection.attr('aria-activedescendant');
|
||||
var activeValue = false;
|
||||
|
||||
if (activeId) {
|
||||
activeValue = $(document.getElementById(activeId)).attr('data-value');
|
||||
}
|
||||
originalSelect.children('option').each(function(index, ele) {
|
||||
if ($(ele).prop('selected')) {
|
||||
items.push( { label: $(ele).html(), value: $(ele).attr('value') } );
|
||||
}
|
||||
});
|
||||
var context = $.extend({ items: items }, options, state);
|
||||
|
||||
// Render the template.
|
||||
templates.render('core/form_autocomplete_selection', context).done(function(newHTML) {
|
||||
// Add it to the page.
|
||||
newSelection.empty().append($(newHTML).html());
|
||||
|
||||
if (activeValue !== false) {
|
||||
// Reselect any previously selected item.
|
||||
newSelection.children('[aria-selected=true]').each(function(index, ele) {
|
||||
if ($(ele).attr('data-value') === activeValue) {
|
||||
activateSelection(index, state);
|
||||
}
|
||||
});
|
||||
}
|
||||
}).fail(notification.exception);
|
||||
// Because this function get's called after changing the selection, this is a good place
|
||||
// to trigger a change notification.
|
||||
originalSelect.change();
|
||||
};
|
||||
|
||||
/**
|
||||
* Select the currently active item from the suggestions list.
|
||||
*
|
||||
|
@ -52,6 +52,83 @@ define([ 'core/mustache',
|
||||
/** @var {String} themeName for the current render */
|
||||
var currentThemeName = '';
|
||||
|
||||
/**
|
||||
* Load a template from the cache or local storage or ajax request.
|
||||
*
|
||||
* @method getTemplate
|
||||
* @private
|
||||
* @param {string} templateName - should consist of the component and the name of the template like this:
|
||||
* core/menu (lib/templates/menu.mustache) or
|
||||
* tool_bananas/yellow (admin/tool/bananas/templates/yellow.mustache)
|
||||
* @return {Promise} JQuery promise object resolved when the template has been fetched.
|
||||
*/
|
||||
var getTemplate = function(templateName, async) {
|
||||
var deferred = $.Deferred();
|
||||
var parts = templateName.split('/');
|
||||
var component = parts.shift();
|
||||
var name = parts.shift();
|
||||
|
||||
var searchKey = currentThemeName + '/' + templateName;
|
||||
|
||||
// First try request variables.
|
||||
if (searchKey in templateCache) {
|
||||
deferred.resolve(templateCache[searchKey]);
|
||||
return deferred.promise();
|
||||
}
|
||||
|
||||
// Now try local storage.
|
||||
var cached = storage.get('core_template/' + searchKey);
|
||||
|
||||
if (cached) {
|
||||
deferred.resolve(cached);
|
||||
templateCache[searchKey] = cached;
|
||||
return deferred.promise();
|
||||
}
|
||||
|
||||
// Oh well - load via ajax.
|
||||
var promises = ajax.call([{
|
||||
methodname: 'core_output_load_template',
|
||||
args:{
|
||||
component: component,
|
||||
template: name,
|
||||
themename: currentThemeName
|
||||
}
|
||||
}], async, false);
|
||||
|
||||
promises[0].done(
|
||||
function (templateSource) {
|
||||
storage.set('core_template/' + searchKey, templateSource);
|
||||
templateCache[searchKey] = templateSource;
|
||||
deferred.resolve(templateSource);
|
||||
}
|
||||
).fail(
|
||||
function (ex) {
|
||||
deferred.reject(ex);
|
||||
}
|
||||
);
|
||||
return deferred.promise();
|
||||
};
|
||||
|
||||
/**
|
||||
* Load a partial from the cache or ajax.
|
||||
*
|
||||
* @method partialHelper
|
||||
* @private
|
||||
* @param {string} name The partial name to load.
|
||||
* @return {string}
|
||||
*/
|
||||
var partialHelper = function(name) {
|
||||
var template = '';
|
||||
|
||||
getTemplate(name, false).done(
|
||||
function(source) {
|
||||
template = source;
|
||||
}
|
||||
).fail(notification.exception);
|
||||
|
||||
return template;
|
||||
};
|
||||
|
||||
/**
|
||||
* Render image icons.
|
||||
*
|
||||
@ -92,26 +169,6 @@ define([ 'core/mustache',
|
||||
return result.trim();
|
||||
};
|
||||
|
||||
/**
|
||||
* Load a partial from the cache or ajax.
|
||||
*
|
||||
* @method partialHelper
|
||||
* @private
|
||||
* @param {string} name The partial name to load.
|
||||
* @return {string}
|
||||
*/
|
||||
var partialHelper = function(name) {
|
||||
var template = '';
|
||||
|
||||
getTemplate(name, false).done(
|
||||
function(source) {
|
||||
template = source;
|
||||
}
|
||||
).fail(notification.exception);
|
||||
|
||||
return template;
|
||||
};
|
||||
|
||||
/**
|
||||
* Render blocks of javascript and save them in an array.
|
||||
*
|
||||
@ -270,63 +327,6 @@ define([ 'core/mustache',
|
||||
return deferred.promise();
|
||||
};
|
||||
|
||||
/**
|
||||
* Load a template from the cache or local storage or ajax request.
|
||||
*
|
||||
* @method getTemplate
|
||||
* @private
|
||||
* @param {string} templateName - should consist of the component and the name of the template like this:
|
||||
* core/menu (lib/templates/menu.mustache) or
|
||||
* tool_bananas/yellow (admin/tool/bananas/templates/yellow.mustache)
|
||||
* @return {Promise} JQuery promise object resolved when the template has been fetched.
|
||||
*/
|
||||
var getTemplate = function(templateName, async) {
|
||||
var deferred = $.Deferred();
|
||||
var parts = templateName.split('/');
|
||||
var component = parts.shift();
|
||||
var name = parts.shift();
|
||||
|
||||
var searchKey = currentThemeName + '/' + templateName;
|
||||
|
||||
// First try request variables.
|
||||
if (searchKey in templateCache) {
|
||||
deferred.resolve(templateCache[searchKey]);
|
||||
return deferred.promise();
|
||||
}
|
||||
|
||||
// Now try local storage.
|
||||
var cached = storage.get('core_template/' + searchKey);
|
||||
|
||||
if (cached) {
|
||||
deferred.resolve(cached);
|
||||
templateCache[searchKey] = cached;
|
||||
return deferred.promise();
|
||||
}
|
||||
|
||||
// Oh well - load via ajax.
|
||||
var promises = ajax.call([{
|
||||
methodname: 'core_output_load_template',
|
||||
args:{
|
||||
component: component,
|
||||
template: name,
|
||||
themename: currentThemeName
|
||||
}
|
||||
}], async, false);
|
||||
|
||||
promises[0].done(
|
||||
function (templateSource) {
|
||||
storage.set('core_template/' + searchKey, templateSource);
|
||||
templateCache[searchKey] = templateSource;
|
||||
deferred.resolve(templateSource);
|
||||
}
|
||||
).fail(
|
||||
function (ex) {
|
||||
deferred.reject(ex);
|
||||
}
|
||||
);
|
||||
return deferred.promise();
|
||||
};
|
||||
|
||||
/**
|
||||
* Execute a block of JS returned from a template.
|
||||
* Call this AFTER adding the template HTML into the DOM so the nodes can be found.
|
||||
|
@ -4,7 +4,7 @@
|
||||
"description": "Moodle",
|
||||
"devDependencies": {
|
||||
"grunt": "0.4.5",
|
||||
"grunt-contrib-jshint": "0.11.2",
|
||||
"grunt-contrib-jshint": "0.11.3",
|
||||
"grunt-contrib-less": "1.1.0",
|
||||
"grunt-contrib-uglify": "0.9.1",
|
||||
"shifter": "0.5.0",
|
||||
|
Loading…
x
Reference in New Issue
Block a user