From aecfdf39dd6d1a1dec9fbed6b436adde8772d5f8 Mon Sep 17 00:00:00 2001 From: Ryan Wyllie Date: Mon, 24 Jul 2017 06:53:32 +0000 Subject: [PATCH] MDL-60052 javascript: fix large styling for modals --- lib/amd/build/modal.min.js | 2 +- lib/amd/src/modal.js | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/amd/build/modal.min.js b/lib/amd/build/modal.min.js index 3803bb60c06..52153245f82 100644 --- a/lib/amd/build/modal.min.js +++ b/lib/amd/build/modal.min.js @@ -1 +1 @@ -define(["jquery","core/templates","core/notification","core/key_codes","core/custom_interaction_events","core/modal_backdrop","core/modal_events"],function(a,b,c,d,e,f,g){var h,i={CONTAINER:'[data-region="modal-container"]',MODAL:'[data-region="modal"]',HEADER:'[data-region="header"]',TITLE:'[data-region="title"]',BODY:'[data-region="body"]',FOOTER:'[data-region="footer"]',HIDE:'[data-action="hide"]',DIALOG:"[role=dialog]",MENU_BAR:"[role=menubar]",HAS_Z_INDEX:".moodle-has-zindex",CAN_RECEIVE_FOCUS:'input:not([type="hidden"]), a[href], button, textarea, select, [tabindex]'},j={LOADING:"core/loading",BACKDROP:"core/modal_backdrop"},k=function(b){this.root=a(b),this.modal=this.root.find(i.MODAL),this.header=this.modal.find(i.HEADER),this.title=this.header.find(i.TITLE),this.body=this.modal.find(i.BODY),this.footer=this.modal.find(i.FOOTER),this.hiddenSiblings=[],this.isAttached=!1,this.bodyJS=null,this.footerJS=null,this.root.is(i.CONTAINER)||c.exception({message:"Element is not a modal container"}),this.modal.length||c.exception({message:"Container does not contain a modal"}),this.header.length||c.exception({message:"Modal is missing a header region"}),this.title.length||c.exception({message:"Modal header is missing a title region"}),this.body.length||c.exception({message:"Modal is missing a body region"}),this.footer.length||c.exception({message:"Modal is missing a footer region"}),this.registerEventListeners()};return k.prototype.attachToDOM=function(){this.isAttached||(a("body").append(this.root),this.bodyJS&&(b.runTemplateJS(this.bodyJS),this.bodyJS=null),this.footerJS&&(b.runTemplateJS(this.footerJS),this.footerJS=null),this.isAttached=!0)},k.prototype.countOtherVisibleModals=function(){var b=0;return a("body").find(i.CONTAINER).each(function(c,d){d=a(d),!this.root.is(d)&&d.hasClass("show")&&b++}.bind(this)),b},k.prototype.getBackdrop=function(){return h||(h=b.render(j.BACKDROP,{}).then(function(b){var c=a(b);return new f(c)}).fail(c.exception)),h},k.prototype.getRoot=function(){return this.root},k.prototype.getModal=function(){return this.modal},k.prototype.getTitle=function(){return this.title},k.prototype.getBody=function(){return this.body},k.prototype.getFooter=function(){return this.footer},k.prototype.setTitle=function(b){var c=this.getTitle(),d=b;"object"==typeof b&&b.hasOwnProperty("then")||(d=a.Deferred(),d.resolve(b)),d.then(function(a){c.html(a)})},k.prototype.setBody=function(a){var c=this.getBody();"string"==typeof a?c.html(a):b.render(j.LOADING,{}).done(function(d){c.html(d),a.done(function(a,d){c.html(a),d&&(this.isAttached?b.runTemplateJS(d):this.bodyJS=d)}.bind(this))}.bind(this))},k.prototype.setFooter=function(a){var c=this.getFooter();"string"==typeof a?c.html(a):b.render(j.LOADING,{}).done(function(d){c.html(d),a.done(function(a,d){c.html(a),d&&(this.isAttached?b.runTemplateJS(d):this.footerJS=d)}.bind(this))}.bind(this))},k.prototype.setLarge=function(){this.isLarge()||this.getRoot().addClass("large")},k.prototype.isLarge=function(){return this.getRoot().hasClass("large")},k.prototype.setSmall=function(){this.isSmall()||this.getRoot().removeClass("large")},k.prototype.isSmall=function(){return!this.getRoot().hasClass("large")},k.prototype.calculateZIndex=function(){var b=a(i.DIALOG+", "+i.MENU_BAR+", "+i.HAS_Z_INDEX),c=parseInt(this.root.css("z-index"));return b.each(function(b,d){d=a(d);var e=d.css("z-index")?parseInt(d.css("z-index")):0;e>c&&(c=e)}),c},k.prototype.isVisible=function(){return this.root.hasClass("show")},k.prototype.hasFocus=function(){var b=a(document.activeElement);return this.root.is(b)||this.root.has(b).length},k.prototype.hasTransitions=function(){return this.getRoot().hasClass("fade")},k.prototype.show=function(){this.isVisible()||(this.isAttached||this.attachToDOM(),this.getBackdrop().done(function(b){var c=this.calculateZIndex(),d=c+2,e=d-1;this.root.css("z-index",d),b.setZIndex(e),b.show(),this.root.removeClass("hide").addClass("show"),this.accessibilityShow(),this.getTitle().focus(),a("body").addClass("modal-open"),this.root.trigger(g.shown,this)}.bind(this)))},k.prototype.hide=function(){this.isVisible()&&this.getBackdrop().done(function(b){this.countOtherVisibleModals()||(b.hide(),a("body").removeClass("modal-open"));var c=parseInt(this.root.css("z-index"));this.root.css("z-index",""),b.setZIndex(c-3),this.accessibilityHide(),this.hasTransitions()?this.getRoot().one("transitionend webkitTransitionEnd oTransitionEnd",function(){this.getRoot().removeClass("show").addClass("hide")}.bind(this)):this.getRoot().removeClass("show").addClass("hide"),this.root.trigger(g.hidden,this)}.bind(this))},k.prototype.destroy=function(){this.root.remove(),this.root.trigger(g.destroyed,this)},k.prototype.accessibilityShow=function(){a("body").children().each(function(b,c){if(!this.root.is(c)){c=a(c);var d=c.attr("aria-hidden");"true"!==d&&(c.data("previous-aria-hidden",d),this.hiddenSiblings.push(c),c.attr("aria-hidden","true"))}}.bind(this)),this.root.attr("aria-hidden","false")},k.prototype.accessibilityHide=function(){this.root.attr("aria-hidden","true"),a.each(this.hiddenSiblings,function(b,c){c=a(c);var d=c.data("previous-aria-hidden");"undefined"==typeof d?c.removeAttr("aria-hidden"):c.attr("aria-hidden",d)}),this.hiddenSiblings=[]},k.prototype.handleTabLock=function(b){if(this.hasFocus()){var c=a(document.activeElement),d=this.modal.find(i.CAN_RECEIVE_FOCUS),e=d.first(),f=d.last();c.is(e)&&b.shiftKey?(f.focus(),b.preventDefault()):c.is(f)&&!b.shiftKey&&(e.focus(),b.preventDefault())}},k.prototype.registerEventListeners=function(){this.getRoot().on("keydown",function(a){this.isVisible()&&(a.keyCode==d.tab?this.handleTabLock(a):a.keyCode==d.escape&&this.hide())}.bind(this)),e.define(this.getModal(),[e.events.activate]),this.getModal().on(e.events.activate,i.HIDE,function(a,b){this.hide(),b.originalEvent.preventDefault()}.bind(this))},k}); \ No newline at end of file +define(["jquery","core/templates","core/notification","core/key_codes","core/custom_interaction_events","core/modal_backdrop","core/modal_events"],function(a,b,c,d,e,f,g){var h,i={CONTAINER:'[data-region="modal-container"]',MODAL:'[data-region="modal"]',HEADER:'[data-region="header"]',TITLE:'[data-region="title"]',BODY:'[data-region="body"]',FOOTER:'[data-region="footer"]',HIDE:'[data-action="hide"]',DIALOG:"[role=dialog]",MENU_BAR:"[role=menubar]",HAS_Z_INDEX:".moodle-has-zindex",CAN_RECEIVE_FOCUS:'input:not([type="hidden"]), a[href], button, textarea, select, [tabindex]'},j={LOADING:"core/loading",BACKDROP:"core/modal_backdrop"},k=function(b){this.root=a(b),this.modal=this.root.find(i.MODAL),this.header=this.modal.find(i.HEADER),this.title=this.header.find(i.TITLE),this.body=this.modal.find(i.BODY),this.footer=this.modal.find(i.FOOTER),this.hiddenSiblings=[],this.isAttached=!1,this.bodyJS=null,this.footerJS=null,this.root.is(i.CONTAINER)||c.exception({message:"Element is not a modal container"}),this.modal.length||c.exception({message:"Container does not contain a modal"}),this.header.length||c.exception({message:"Modal is missing a header region"}),this.title.length||c.exception({message:"Modal header is missing a title region"}),this.body.length||c.exception({message:"Modal is missing a body region"}),this.footer.length||c.exception({message:"Modal is missing a footer region"}),this.registerEventListeners()};return k.prototype.attachToDOM=function(){this.isAttached||(a("body").append(this.root),this.bodyJS&&(b.runTemplateJS(this.bodyJS),this.bodyJS=null),this.footerJS&&(b.runTemplateJS(this.footerJS),this.footerJS=null),this.isAttached=!0)},k.prototype.countOtherVisibleModals=function(){var b=0;return a("body").find(i.CONTAINER).each(function(c,d){d=a(d),!this.root.is(d)&&d.hasClass("show")&&b++}.bind(this)),b},k.prototype.getBackdrop=function(){return h||(h=b.render(j.BACKDROP,{}).then(function(b){var c=a(b);return new f(c)}).fail(c.exception)),h},k.prototype.getRoot=function(){return this.root},k.prototype.getModal=function(){return this.modal},k.prototype.getTitle=function(){return this.title},k.prototype.getBody=function(){return this.body},k.prototype.getFooter=function(){return this.footer},k.prototype.setTitle=function(b){var c=this.getTitle(),d=b;"object"==typeof b&&b.hasOwnProperty("then")||(d=a.Deferred(),d.resolve(b)),d.then(function(a){c.html(a)})},k.prototype.setBody=function(a){var c=this.getBody();"string"==typeof a?c.html(a):b.render(j.LOADING,{}).done(function(d){c.html(d),a.done(function(a,d){c.html(a),d&&(this.isAttached?b.runTemplateJS(d):this.bodyJS=d)}.bind(this))}.bind(this))},k.prototype.setFooter=function(a){var c=this.getFooter();"string"==typeof a?c.html(a):b.render(j.LOADING,{}).done(function(d){c.html(d),a.done(function(a,d){c.html(a),d&&(this.isAttached?b.runTemplateJS(d):this.footerJS=d)}.bind(this))}.bind(this))},k.prototype.setLarge=function(){this.isLarge()||this.getModal().addClass("modal-lg")},k.prototype.isLarge=function(){return this.getModal().hasClass("modal-lg")},k.prototype.setSmall=function(){this.isSmall()||this.getModal().removeClass("modal-lg")},k.prototype.isSmall=function(){return!this.getModal().hasClass("modal-lg")},k.prototype.calculateZIndex=function(){var b=a(i.DIALOG+", "+i.MENU_BAR+", "+i.HAS_Z_INDEX),c=parseInt(this.root.css("z-index"));return b.each(function(b,d){d=a(d);var e=d.css("z-index")?parseInt(d.css("z-index")):0;e>c&&(c=e)}),c},k.prototype.isVisible=function(){return this.root.hasClass("show")},k.prototype.hasFocus=function(){var b=a(document.activeElement);return this.root.is(b)||this.root.has(b).length},k.prototype.hasTransitions=function(){return this.getRoot().hasClass("fade")},k.prototype.show=function(){this.isVisible()||(this.isAttached||this.attachToDOM(),this.getBackdrop().done(function(b){var c=this.calculateZIndex(),d=c+2,e=d-1;this.root.css("z-index",d),b.setZIndex(e),b.show(),this.root.removeClass("hide").addClass("show"),this.accessibilityShow(),this.getTitle().focus(),a("body").addClass("modal-open"),this.root.trigger(g.shown,this)}.bind(this)))},k.prototype.hide=function(){this.isVisible()&&this.getBackdrop().done(function(b){this.countOtherVisibleModals()||(b.hide(),a("body").removeClass("modal-open"));var c=parseInt(this.root.css("z-index"));this.root.css("z-index",""),b.setZIndex(c-3),this.accessibilityHide(),this.hasTransitions()?this.getRoot().one("transitionend webkitTransitionEnd oTransitionEnd",function(){this.getRoot().removeClass("show").addClass("hide")}.bind(this)):this.getRoot().removeClass("show").addClass("hide"),this.root.trigger(g.hidden,this)}.bind(this))},k.prototype.destroy=function(){this.root.remove(),this.root.trigger(g.destroyed,this)},k.prototype.accessibilityShow=function(){a("body").children().each(function(b,c){if(!this.root.is(c)){c=a(c);var d=c.attr("aria-hidden");"true"!==d&&(c.data("previous-aria-hidden",d),this.hiddenSiblings.push(c),c.attr("aria-hidden","true"))}}.bind(this)),this.root.attr("aria-hidden","false")},k.prototype.accessibilityHide=function(){this.root.attr("aria-hidden","true"),a.each(this.hiddenSiblings,function(b,c){c=a(c);var d=c.data("previous-aria-hidden");"undefined"==typeof d?c.removeAttr("aria-hidden"):c.attr("aria-hidden",d)}),this.hiddenSiblings=[]},k.prototype.handleTabLock=function(b){if(this.hasFocus()){var c=a(document.activeElement),d=this.modal.find(i.CAN_RECEIVE_FOCUS),e=d.first(),f=d.last();c.is(e)&&b.shiftKey?(f.focus(),b.preventDefault()):c.is(f)&&!b.shiftKey&&(e.focus(),b.preventDefault())}},k.prototype.registerEventListeners=function(){this.getRoot().on("keydown",function(a){this.isVisible()&&(a.keyCode==d.tab?this.handleTabLock(a):a.keyCode==d.escape&&this.hide())}.bind(this)),e.define(this.getModal(),[e.events.activate]),this.getModal().on(e.events.activate,i.HIDE,function(a,b){this.hide(),b.originalEvent.preventDefault()}.bind(this))},k}); \ No newline at end of file diff --git a/lib/amd/src/modal.js b/lib/amd/src/modal.js index b2e25262a14..b0a570c4cae 100644 --- a/lib/amd/src/modal.js +++ b/lib/amd/src/modal.js @@ -324,7 +324,7 @@ define(['jquery', 'core/templates', 'core/notification', 'core/key_codes', return; } - this.getRoot().addClass('large'); + this.getModal().addClass('modal-lg'); }; /** @@ -334,7 +334,7 @@ define(['jquery', 'core/templates', 'core/notification', 'core/key_codes', * @return {bool} */ Modal.prototype.isLarge = function() { - return this.getRoot().hasClass('large'); + return this.getModal().hasClass('modal-lg'); }; /** @@ -347,7 +347,7 @@ define(['jquery', 'core/templates', 'core/notification', 'core/key_codes', return; } - this.getRoot().removeClass('large'); + this.getModal().removeClass('modal-lg'); }; /** @@ -357,7 +357,7 @@ define(['jquery', 'core/templates', 'core/notification', 'core/key_codes', * @return {bool} */ Modal.prototype.isSmall = function() { - return !this.getRoot().hasClass('large'); + return !this.getModal().hasClass('modal-lg'); }; /**