Skip to content

Commit

Permalink
Update MaterialZ
Browse files Browse the repository at this point in the history
  • Loading branch information
ZMYaro committed May 3, 2021
1 parent d02bd4c commit bb758f2
Show file tree
Hide file tree
Showing 4 changed files with 702 additions and 327 deletions.
88 changes: 40 additions & 48 deletions scripts/material-touch.js
Original file line number Diff line number Diff line change
@@ -1,70 +1,62 @@
/* Script for triggering element active states when touched
* Supplement to the MaterialZ CSS library
*
* Copyright 2015 Zachary Yaro
* Copyright 2015-2021 Zachary Yaro
* Released under the MIT license
* http://materialz.zmyaro.com/LICENSE.txt
* https://materialz.dev/LICENSE.txt
*/

window.addEventListener("load", function(e) {
// Do not run the script on Chrome 32 or higher.
/*if(/Chrome\/[3-9][2-9]/.test(navigator.userAgent)) {
return;
}*/
(function () {
var ELEM_TYPES = ["button", "select"],
INPUT_TYPES = ["button", "checkbox", "radio", "range", "reset", "submit"];

// Create an array of all input elements.
var inputElems = Array.prototype.slice.call(document.getElementsByTagName("button")).concat(
Array.prototype.slice.call(document.getElementsByTagName("select"))).concat(
Array.prototype.slice.call(document.getElementsByTagName("input")));

// If they can be found, identify all elements with role="button".
if(document.querySelectorAll) {
inputElems = inputElems.concat(
Array.prototype.slice.call(document.querySelectorAll("*[role=\"button\"]")));
}

var elemTypes = ["button", "select"];
var inputTypes = ["button", "checkbox", "radio", "range", "reset", "submit"];

for(var i = 0; i < inputElems.length; i++) {
// If the element is a supported form element,
if(elemTypes.indexOf(inputElems[i].tagName.toLowerCase()) !== -1 ||
// Or the element is a supported <input> type,
(inputElems[i].type && inputTypes.indexOf(inputElems[i].type.toLowerCase()) !== -1) ||
// Or the element has role="button",
(inputElems[i].getAttribute("role") && inputElems[i].getAttribute("role").toLowerCase() === "button")) {
// Add the touch event listeners.
inputElems[i].addEventListener("touchstart", makeActive, false);
inputElems[i].addEventListener("touchend", makeInactive, false);
inputElems[i].addEventListener("touchcancel", makeInactive, false);
}
/**
* Check whether a given element is a supported form element.
* @param {HTMLElement} elem
*/
function isSupported(elem) {
// Check whether the element is a supported form element,
return (ELEM_TYPES.indexOf(elem.tagName.toLowerCase()) !== -1 ||
// a supported <input> type,
(elem.type && INPUT_TYPES.indexOf(elem.type.toLowerCase()) !== -1) ||
// or has role="button".
elem.getAttribute('role') === 'button');
}


/**
* Adds the “active” class to the touched element
* Add the “active” class to the touched element
* @param {TouchEvent} e
*/
function makeActive(e) {
if(!!e.srcElement.classList) { // use classList API if available
e.srcElement.classList.add("active");
} else {
e.srcElement.className += " active";
if (isSupported(e.target)) {
if(!!e.target.classList) { // use classList API if available
e.target.classList.add("active");
} else {
e.target.className += " active";
}
e.stopPropagation();
}

}

/**
* Removes the “active” class from the touched element
* Remove the “active” class from the touched element
* @param {TouchEvent} e
*/
function makeInactive(e) {
if(!!e.srcElement.classList) { // use classList API if available
e.srcElement.classList.remove("active");
} else {
e.srcElement.className = e.srcElement.className.replace(/\s*active/g, "");
if (isSupported(e.target)) {
if(!!e.target.classList) { // use classList API if available
e.target.classList.remove("active");
} else {
e.target.className = e.srcElement.className.replace(/\s*active/g, "");
}
e.stopPropagation();
}

}
}, false);


window.addEventListener('load', function(e) {
// Add the event listeners to the body.
document.body.addEventListener('touchstart', makeActive, false);
document.body.addEventListener("touchend", makeInactive, false);
document.body.addEventListener("touchcancel", makeInactive, false);
}, false);
})();
109 changes: 63 additions & 46 deletions styles/material-depth.css
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* Base Material styles for depth
* Part of the MaterialZ CSS library
*
* Copyright 2015 Zachary Yaro
* Copyright 2015-2021 Zachary Yaro
* Released under the MIT license
* http://materialz.zmyaro.com/LICENSE.txt
* https://materialz.dev/LICENSE.txt
*/

@charset "UTF-8";
Expand All @@ -29,16 +29,27 @@
-o-transition-property: box-shadow;
transition-property: box-shadow;
}
.card.full-width.z1,
.card.full-width.z2,
.card.full-width.z3,
.card.full-width.z4,
.card.full-width.z5 {
-webkit-transition-property: margin, border-radius, -webkit-box-shadow, box-shadow;
-moz-transition-property: margin, border-radius, -moz-box-shadow, box-shadow;
-ms-transition-property: margin, border-radius, box-shadow;
-o-transition-property: margin, border-radius, box-shadow;
transition-property: margin, border-radius, box-shadow;
}
button.z1,
button.z2,
button.z3,
button.z4,
button.z5,
*[role="button"].z1,
*[role="button"].z2,
*[role="button"].z3,
*[role="button"].z4,
*[role="button"].z5 ,
[role="button"].z1,
[role="button"].z2,
[role="button"].z3,
[role="button"].z4,
[role="button"].z5 ,
input[type="button"].z1,
input[type="button"].z2,
input[type="button"].z3,
Expand All @@ -61,11 +72,11 @@ input[type="reset"].z5 {
button.z3:hover,
button.z4:hover,
button.z5:hover,
*[role="button"].z1:hover,
*[role="button"].z2:hover,
*[role="button"].z3:hover,
*[role="button"].z4:hover,
*[role="button"].z5:hover,
[role="button"].z1:hover,
[role="button"].z2:hover,
[role="button"].z3:hover,
[role="button"].z4:hover,
[role="button"].z5:hover,
input[type="button"].z1:hover,
input[type="button"].z2:hover,
input[type="button"].z3:hover,
Expand All @@ -86,11 +97,11 @@ input[type="reset"].z5 {
button.z3:focus,
button.z4:focus,
button.z5:focus,
*[role="button"].z1:focus,
*[role="button"].z2:focus,
*[role="button"].z3:focus,
*[role="button"].z4:focus,
*[role="button"].z5:focus,
[role="button"].z1:focus,
[role="button"].z2:focus,
[role="button"].z3:focus,
[role="button"].z4:focus,
[role="button"].z5:focus,
input[type="button"].z1:focus,
input[type="button"].z2:focus,
input[type="button"].z3:focus,
Expand All @@ -113,11 +124,11 @@ input[type="reset"].z5 {
button.z3:enabled:active,
button.z4:enabled:active,
button.z5:enabled:active,
*[role="button"].z1:active,
*[role="button"].z2:active,
*[role="button"].z3:active,
*[role="button"].z4:active,
*[role="button"].z5:active,
[role="button"].z1:active,
[role="button"].z2:active,
[role="button"].z3:active,
[role="button"].z4:active,
[role="button"].z5:active,
input[type="button"].z1:enabled:active,
input[type="button"].z2:enabled:active,
input[type="button"].z3:enabled:active,
Expand All @@ -138,11 +149,11 @@ input[type="reset"].z5 {
button.z3:enabled.active,
button.z4:enabled.active,
button.z5:enabled.active,
*[role="button"].z1.active,
*[role="button"].z2.active,
*[role="button"].z3.active,
*[role="button"].z4.active,
*[role="button"].z5.active,
[role="button"].z1.active,
[role="button"].z2.active,
[role="button"].z3.active,
[role="button"].z4.active,
[role="button"].z5.active,
input[type="button"].z1:enabled.active,
input[type="button"].z2:enabled.active,
input[type="button"].z3:enabled.active,
Expand All @@ -165,14 +176,12 @@ input[type="reset"].z5 {
-webkit-box-shadow: rgba(0, 0, 0, 0.26) 0 2px 5px 0, rgba(0, 0, 0, 0.16) 0 2px 10px 0;
-moz-box-shadow: rgba(0, 0, 0, 0.26) 0 2px 5px 0, rgba(0, 0, 0, 0.16) 0 2px 10px 0;
box-shadow: rgba(0, 0, 0, 0.26) 0 2px 5px 0, rgba(0, 0, 0, 0.16) 0 2px 10px 0;
filter: progid:DXImageTransform.Microsoft.Glow(Color=#b8b8b8,Strength=5);
-ms-filter: "progid:DXImageTransform.Microsoft.Glow(Color=#b8b8b8,Strength=5)";
}

button.z1:hover,
button.z1:focus,
*[role="button"].z1:hover,
*[role="button"].z1:focus,
[role="button"].z1:hover,
[role="button"].z1:focus,
input[type="button"].z1:hover,
input[type="button"].z1:focus,
input[type="submit"].z1:hover,
Expand All @@ -182,14 +191,12 @@ input[type="reset"].z1:focus {
-webkit-box-shadow: 0 4px 10px 0 rgba(0, 0, 0, 0.23), 0 4px 15px 0 rgba(0, 0, 0, 0.175);
-moz-box-shadow: 0 4px 10px 0 rgba(0, 0, 0, 0.23), 0 4px 15px 0 rgba(0, 0, 0, 0.175);
box-shadow: 0 4px 10px 0 rgba(0, 0, 0, 0.23), 0 4px 15px 0 rgba(0, 0, 0, 0.175);
filter: progid:DXImageTransform.Microsoft.Glow(Color=#b4b4b4,Strength=7);
-ms-filter: "progid:DXImageTransform.Microsoft.Glow(Color=#b4b4b4,Strength=7)";
}
.z2,
button.z1:enabled:active,
button.z1:enabled.active,
*[role="button"].z1:active,
*[role="button"].z1.active,
[role="button"].z1:active,
[role="button"].z1.active,
input[type="button"].z1:active,
input[type="button"].z1.active,
input[type="submit"].z1:active,
Expand All @@ -199,14 +206,12 @@ input[type="reset"].z1.active {
-webkit-box-shadow: rgba(0, 0, 0, 0.2) 0 8px 17px 0, rgba(0, 0, 0, 0.19) 0 6px 20px 0;
-moz-box-shadow: rgba(0, 0, 0, 0.2) 0 8px 17px 0, rgba(0, 0, 0, 0.19) 0 6px 20px 0;
box-shadow: rgba(0, 0, 0, 0.2) 0 8px 17px 0, rgba(0, 0, 0, 0.19) 0 6px 20px 0;
filter: progid:DXImageTransform.Microsoft.Glow(Color=#b0b0b0,Strength=10);
-ms-filter: "progid:DXImageTransform.Microsoft.Glow(Color=#b0b0b0,Strength=10)";
}
.z3,
button.z2:enabled:active,
button.z2:enabled.active,
*[role="button"].z2:active,
*[role="button"].z2.active,
[role="button"].z2:active,
[role="button"].z2.active,
input[type="button"].z2:active,
input[type="button"].z2.active,
input[type="submit"].z2:active,
Expand All @@ -220,8 +225,8 @@ input[type="reset"].z2.active {
.z4,
button.z3:enabled:active,
button.z3:enabled.active,
*[role="button"].z3:active,
*[role="button"].z3.active,
[role="button"].z3:active,
[role="button"].z3.active,
input[type="button"].z3:active,
input[type="button"].z3.active,
input[type="submit"].z3:active,
Expand All @@ -235,8 +240,8 @@ input[type="reset"].z3.active {
.z5,
button.z4:enabled:active,
button.z4:enabled.active,
*[role="button"].z4:active,
*[role="button"].z4.active,
[role="button"].z4:active,
[role="button"].z4.active,
input[type="button"].z4:active,
input[type="button"].z4.active,
input[type="submit"].z4:active,
Expand All @@ -248,13 +253,25 @@ input[type="reset"].z4.active {
box-shadow: rgba(0, 0, 0, 0.2) 0 27px 24px 0, rgba(0, 0, 0, 0.22) 0 40px 77px 0;
}
button.z1:disabled,
*[role="button"].z1.disabled,
[role="button"].z1.disabled,
input[type="button"].z1.disabled,
input[type="submit"].z1.disabled,
input[type="reset"].z1.disabled {
-webkit-box-shadow: rgba(0, 0, 0, 0.2) 0 2px 2px 0, rgba(0, 0, 0, 0.14) 0 2px 5px 0;
-moz-box-shadow: rgba(0, 0, 0, 0.2) 0 2px 2px 0, rgba(0, 0, 0, 0.14) 0 2px 5px 0;
box-shadow: rgba(0, 0, 0, 0.2) 0 2px 2px 0, rgba(0, 0, 0, 0.14) 0 2px 5px 0;
filter: progid:DXImageTransform.Microsoft.Glow(Color=#b8b8b8,Strength=5);
-ms-filter: "progid:DXImageTransform.Microsoft.Glow(Color=#b8b8b8,Strength=5)";
}

@media (prefers-reduced-motion: reduce) {
.z1,
.z2,
.z3,
.z4,
.z5 {
-webkit-transition-duration: 0s;
-moz-transition-duration: 0s;
-ms-transition-duration: 0s;
-o-transition-duration: 0s;
transition-duration: 0s;
}
}
Loading

0 comments on commit bb758f2

Please sign in to comment.