Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AUI-1336 - Demo SF #545

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
65 changes: 58 additions & 7 deletions demos/modal/index.html
Expand Up @@ -7,29 +7,39 @@
<link rel="stylesheet" href="../../build/aui-css/css/bootstrap.css">
<script src="../../build/aui/aui.js"></script>
<style>
#content {
height: 2000px;
}

.modal-content {
overflow: hidden;
}
</style>
</head>
<body class="yui3-skin-sam">
<h1>AlloyUI - Modal</h1>
<div id="content"></div>
<div id="content">
<p>
destroyOnHide: <span id="destroyOnHideValue"></span>
</p>
<button class="btn btn-default" id="showDialog">Show Dialog</button>
<button class="btn btn-default" id="createNewDialog">Create Dialog</button>
<button class="btn btn-default" id="destroyOnHideToggle">Toggle destroyOnHide</button>
</div>
<script>
YUI({ filter:'raw' }).use('aui-modal', 'resize-proxy', function(Y) {

YUI({ filter:'raw' }).use('aui-modal', 'aui-node', 'resize-proxy', function(Y) {
console.time('How long does it take?');

var modal = new Y.Modal({
var config = {
bodyContent: 'One fine body…',
centered: true,
cssClass: 'foo',
destroyOnHide: true,
// destroyOnHide: true,
headerContent: '<h3>Modal header</h3>',
// height: 400,
modal: true,
render: '#content',
visible: true,
visible: true
// draggable: false,
// resizable: {
// handles: 'br, r',
Expand All @@ -48,7 +58,9 @@ <h1>AlloyUI - Modal</h1>
// { icon: 'Footer' }
// ]
// }
}).render();
};

var modal = new Y.Modal(config).render();

modal.addToolbar([
{
Expand All @@ -68,6 +80,45 @@ <h1>AlloyUI - Modal</h1>

console.timeEnd('How long does it take?');

var destroyOnHideValue = Y.one('#destroyOnHideValue');

destroyOnHideValue.html(modal.get('destroyOnHide'));

Y.one('#createNewDialog').on('click', function() {
if (modal.get('destroyed')) {
modal = new Y.Modal(config).render();

modal.addToolbar([
{
label: 'Cancel',
on: {
click: function() { modal.hide(); }
}
},
{
label: 'Okay',
on: {
click: function() { alert('This is the primary action!'); }
},
primary: true
}
]);

destroyOnHideValue.html(modal.get('destroyOnHide'));
}
});

Y.one('#destroyOnHideToggle').on('click', function() {
var destroyOnHide = !modal.get('destroyOnHide');

modal.set('destroyOnHide', destroyOnHide);

destroyOnHideValue.html(destroyOnHide);
});

Y.one('#showDialog').on('click', function() {
modal.show();
});
});
</script>
</body>
Expand Down
6 changes: 3 additions & 3 deletions src/aui-modal/js/aui-modal.js
Expand Up @@ -85,7 +85,7 @@ A.Modal = A.Base.create('modal', A.Widget, [
instance._userInteractionHandle.detach();
}

A.one('body,html').removeClass(CSS_MODAL_OPEN);
A.all('body,html').removeClass(CSS_MODAL_OPEN);
},

/**
Expand Down Expand Up @@ -139,7 +139,7 @@ A.Modal = A.Base.create('modal', A.Widget, [

_afterRender: function() {
if (this.get('visible')) {
A.one('body,html').addClass(CSS_MODAL_OPEN);
A.all('body,html').addClass(CSS_MODAL_OPEN);
}
},

Expand Down Expand Up @@ -175,7 +175,7 @@ A.Modal = A.Base.create('modal', A.Widget, [
A.soon(A.bind('destroy', instance));
}

A.one('body,html').toggleClass(CSS_MODAL_OPEN, event.newVal);
A.all('body,html').toggleClass(CSS_MODAL_OPEN, event.newVal);
},

/**
Expand Down
55 changes: 53 additions & 2 deletions src/aui-modal/tests/unit/js/tests.js
Expand Up @@ -8,6 +8,8 @@ YUI.add('aui-modal-tests', function(Y) {
modal,
boundingBox,

CSS_MODAL_OPEN = Y.getClassName('modal-open'),

ERROR_PLUGIN_AVAILABLE = '{0} plugin should not be available',
ERROR_PLUGIN_MISSING = '{0} plugin was not plugged',
ERROR_PLUGIN_OVERRIDEN = '{0} attribute should not be overriden',
Expand Down Expand Up @@ -143,8 +145,57 @@ YUI.add('aui-modal-tests', function(Y) {

}));

//--------------------------------------------------------------------------
// Test Case for Scroll
//--------------------------------------------------------------------------

suite.add(new Y.Test.Case({

name: 'Scroll',

setUp: function() {
if (modal) {
modal.destroy();
}

modal = new Y.Modal().render('#modal');

boundingBox = modal.get('boundingBox');
},

tearDown: function() {
modal.destroy();

modal = null;
boundingBox = null;
},

//----------------------------------------------------------------------
// Tests
//----------------------------------------------------------------------

// Tests: AUI-1336
'check modal-open class after visibleChange': function() {
var elements = Y.all('body,html');

modal.show();

var modalOpen = elements.hasClass(CSS_MODAL_OPEN);

Y.Assert.isTrue(modalOpen[0]);
Y.Assert.isTrue(modalOpen[1]);

modal.hide();

modalOpen = elements.hasClass(CSS_MODAL_OPEN);

Y.Assert.isFalse(modalOpen[0]);
Y.Assert.isFalse(modalOpen[1]);
}
}));

Y.Test.Runner.add(suite);

}, '', {
requires: ['aui-modal', 'node-event-simulate', 'test']
});
requires: ['aui-modal', 'aui-node-base', 'node-event-simulate', 'test']
});