Skip to content

Commit

Permalink
beta(carousel): Beta release of Image Carousel
Browse files Browse the repository at this point in the history
  • Loading branch information
leifoolsen committed May 28, 2016
1 parent 32facdf commit e069795
Show file tree
Hide file tree
Showing 22 changed files with 317 additions and 224 deletions.
146 changes: 83 additions & 63 deletions demo/carousel.html
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ <h5>Carousel</h5>
</nav>
</footer>

<div id="carousel-container">
<section id="carousel-container">
<ul id="mdlext-carousel-demo2" class="mdlext-carousel mdlext-js-carousel mdl-js-ripple-effect mdl-js-ripple-effect--ignore-events">
<li class="mdlext-carousel__slide" aria-selected="">
<a href="./images/_D802143-2.jpg">
Expand Down Expand Up @@ -633,10 +633,20 @@ <h5>Carousel</h5>
</figure>
</li>
</ul>
</div>
</section>
</artichle>


<div style="margin-top: 8px">
<button id="btn-add-image" class="mdl-button mdl-js-button mdl-button--raised mdl-button--colored">
Add image to carousel
</button>
<p class="mdl-typography--caption" style="margin-top: 8px">
Verify that the MutationObserver works: Click the button to add a new image to the carousel. Move to the inserted
image and click it. It should have ripple effect if upgraded correctly.
</p>
</div>

<p class="mdl-typography--caption" style="margin-top: 32px;">
All images appearing in this page are the exclusive property of Leif Olsen and are protected under the United States
and International Copyright laws. The images may not be reproduced or manipulated without the written permission of
Expand All @@ -649,70 +659,80 @@ <h5>Carousel</h5>
(function() {
'use strict';

document.querySelector('#carousel-btn-first').addEventListener('click', function(e) {
var ev = new CustomEvent('command', { detail: { action : 'first' } });
document.querySelector('#mdlext-carousel-demo2').dispatchEvent(ev);
});

document.querySelector('#carousel-btn-scroll-prev').addEventListener('click', function(e) {
var ev = new CustomEvent('command', { detail: { action : 'scroll-prev' } });
document.querySelector('#mdlext-carousel-demo2').dispatchEvent(ev);
});

document.querySelector('#carousel-btn-prev').addEventListener('click', function(e) {
var ev = new CustomEvent('command', { detail: { action : 'prev' } });
document.querySelector('#mdlext-carousel-demo2').dispatchEvent(ev);
});

document.querySelector('#carousel-btn-next').addEventListener('click', function(e) {
var ev = new CustomEvent('command', { detail: { action : 'next' } });
document.querySelector('#mdlext-carousel-demo2').dispatchEvent(ev);
});

document.querySelector('#carousel-btn-scroll-next').addEventListener('click', function(e) {
var ev = new CustomEvent('command', { detail: { action : 'scroll-next' } });
document.querySelector('#mdlext-carousel-demo2').dispatchEvent(ev);
});

document.querySelector('#carousel-btn-last').addEventListener('click', function(e) {
var ev = new CustomEvent('command', { detail: { action : 'last' } });
document.querySelector('#mdlext-carousel-demo2').dispatchEvent(ev);
});

document.querySelector('#carousel-btn-play-pause').addEventListener('click', function(e) {
// Toggle play icon
var i = this.querySelector('i');
var action = i.innerText === 'play_circle_outline' ? 'play' : 'pause';
i.textContent = action === 'play' ? 'pause_circle_outline' : 'play_circle_outline';

var ev = new CustomEvent('command', { detail: { action : action, interval: 3000 } });
document.querySelector('#mdlext-carousel-demo2').dispatchEvent(ev);
});

document.querySelector('#mdlext-carousel-demo2').addEventListener('select', function(e) {

if('pause' === e.detail.command) {
// Set play icon
var i = document.querySelector('#carousel-btn-play-pause i');
i.textContent = 'play_circle_outline';
}
else {
var oldImage = document.querySelector('#carousel-imgviewer img');
var selectImage = e.detail.source.querySelector('img');
var selectImageSrc = selectImage.src;
if(e.detail.source.querySelector('a')) {
selectImageSrc = e.detail.source.querySelector('a').href;
window.addEventListener('load', function() {

document.querySelector('#carousel-btn-first').addEventListener('click', function (e) {
var ev = new CustomEvent('command', {detail: {action: 'first'}});
document.querySelector('#mdlext-carousel-demo2').dispatchEvent(ev);
});

document.querySelector('#carousel-btn-scroll-prev').addEventListener('click', function (e) {
var ev = new CustomEvent('command', {detail: {action: 'scroll-prev'}});
document.querySelector('#mdlext-carousel-demo2').dispatchEvent(ev);
});

document.querySelector('#carousel-btn-prev').addEventListener('click', function (e) {
var ev = new CustomEvent('command', {detail: {action: 'prev'}});
document.querySelector('#mdlext-carousel-demo2').dispatchEvent(ev);
});

document.querySelector('#carousel-btn-next').addEventListener('click', function (e) {
var ev = new CustomEvent('command', {detail: {action: 'next'}});
document.querySelector('#mdlext-carousel-demo2').dispatchEvent(ev);
});

document.querySelector('#carousel-btn-scroll-next').addEventListener('click', function (e) {
var ev = new CustomEvent('command', {detail: {action: 'scroll-next'}});
document.querySelector('#mdlext-carousel-demo2').dispatchEvent(ev);
});

document.querySelector('#carousel-btn-last').addEventListener('click', function (e) {
var ev = new CustomEvent('command', {detail: {action: 'last'}});
document.querySelector('#mdlext-carousel-demo2').dispatchEvent(ev);
});

document.querySelector('#carousel-btn-play-pause').addEventListener('click', function (e) {
// Toggle play icon
var i = this.querySelector('i');
var action = i.innerText === 'play_circle_outline' ? 'play' : 'pause';
i.textContent = action === 'play' ? 'pause_circle_outline' : 'play_circle_outline';

var ev = new CustomEvent('command', {detail: {action: action, interval: 3000}});
document.querySelector('#mdlext-carousel-demo2').dispatchEvent(ev);
});

document.querySelector('#mdlext-carousel-demo2').addEventListener('select', function (e) {

if ('pause' === e.detail.command) {
// Set play icon
var i = document.querySelector('#carousel-btn-play-pause i');
i.textContent = 'play_circle_outline';
}
else {
var oldImage = document.querySelector('#carousel-imgviewer img');
var selectImage = e.detail.source.querySelector('img');
var selectImageSrc = selectImage.src;
if (e.detail.source.querySelector('a')) {
selectImageSrc = e.detail.source.querySelector('a').href;
}

if (selectImageSrc !== oldImage.src) {
var newImage = oldImage.cloneNode(true);
newImage.src = selectImageSrc;
oldImage.parentNode.replaceChild(newImage, oldImage);

var title = document.querySelector('#carousel-viewer-title');
title.textContent = selectImage.title;
}
}
});

if(selectImageSrc !== oldImage.src) {
var newImage = oldImage.cloneNode(true);
newImage.src = selectImageSrc;
oldImage.parentNode.replaceChild(newImage, oldImage);
document.querySelector('#btn-add-image').addEventListener('click', function (e) {
var slide_fragment = '<li class="mdlext-carousel__slide"><figure><img src="./images/_D809914-2.jpg" alt="Humpback whale" title="Humpback whale"/></figure></li>';
var carousel = document.querySelector('#mdlext-carousel-demo2');
carousel.insertAdjacentHTML('beforeend', slide_fragment);
});

var title = document.querySelector('#carousel-viewer-title');
title.textContent = selectImage.title;
}
}
});

}());
Expand Down
5 changes: 2 additions & 3 deletions lib/mdl-ext-eqjs.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/mdl-ext-eqjs.css.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/mdl-ext-eqjs.min.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/mdl-ext-eqjs.min.css.map

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions lib/mdl-ext.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/mdl-ext.css.map

Large diffs are not rendered by default.

62 changes: 29 additions & 33 deletions lib/mdl-ext.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/mdl-ext.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/mdl-ext.min.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/mdl-ext.min.css.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/mdl-ext.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/mdl-ext.min.js.map

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mdl-ext",
"version": "0.0.0-semantically-released",
"version": "0.9.0-beta.0",
"description": "Components based on the Google Material Design Lite framework",
"main": "lib/mdl-ext.js",
"scripts": {
Expand Down Expand Up @@ -87,7 +87,7 @@
"doctrine": "1.2.2",
"eq.js": "1.9.0",
"es6-promise": "3.2.1",
"eslint": "2.10.2",
"eslint": "2.11.0",
"eslint-loader": "1.3.0",
"extract-text-webpack-plugin": "1.0.1",
"file-loader": "0.8.5",
Expand All @@ -97,10 +97,10 @@
"gulp-posthtml": "1.5.2",
"ignore-styles": "2.0.0",
"istanbul": "1.0.0-alpha.2",
"jsdom": "9.1.0",
"jsdom": "9.2.0",
"jsdomify": "2.1.0",
"material-design-lite": "1.1.3",
"mocha": "2.5.1",
"mocha": "2.5.3",
"node-sass": "3.7.0",
"null-loader": "0.1.1",
"object-assign": "4.1.0",
Expand Down
1 change: 1 addition & 0 deletions src/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ $mdlext-lightboard-figcaption-text-color : unquote('rgb(#{$palette-grey-40

/* ========== Carousel ========== */
$mdlext-carousel-slide-border-top-width : 3px;
$mdlext-carousel-slide-margin-horizontal : 0;
$mdlext-carousel-slide-border-top-color : unquote("rgb(#{$color-accent})");
$mdlext-carousel-slide-figcaption-color : $mdlext-lightboard-figcaption-text-color;
$mdlext-carousel-slide-ripple-color : $mdlext-lightboard-ripple-color;
Expand Down
Loading

0 comments on commit e069795

Please sign in to comment.