sh-modal-dialog
Version:
Modal Dialog box for React
922 lines (784 loc) • 34.5 kB
JavaScript
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory(require("react"), require("react-dom"), require("lodash"));
else if(typeof define === 'function' && define.amd)
define(["react", "react-dom", "lodash"], factory);
else if(typeof exports === 'object')
exports["sh-modal-service"] = factory(require("react"), require("react-dom"), require("lodash"));
else
root["sh-modal-service"] = factory(root["React"], root["ReactDOM"], root["_"]);
})(this, function(__WEBPACK_EXTERNAL_MODULE_1__, __WEBPACK_EXTERNAL_MODULE_2__, __WEBPACK_EXTERNAL_MODULE_5__) {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
/******/
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.loaded = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/*!*********************************!*\
!*** ./src/sh-modal-service.js ***!
\*********************************/
/***/ function(module, exports, __webpack_require__) {
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _react = __webpack_require__(/*! react */ 1);
var _react2 = _interopRequireDefault(_react);
var _reactDom = __webpack_require__(/*! react-dom */ 2);
var _reactDom2 = _interopRequireDefault(_reactDom);
var _shModalDialog = __webpack_require__(/*! ./sh-modal-dialog */ 3);
var _shModalDialog2 = _interopRequireDefault(_shModalDialog);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var rootElement = document.createElement('div');
rootElement.classList.add('sh-modal-Dialog-wrapper');
document.body.appendChild(rootElement);
var ShModalService = function () {
function ShModalService(contentElement, title, saveButton, cssClass, forceValid) {
_classCallCheck(this, ShModalService);
this.contentElement = contentElement;
this.title = title;
this.saveButton = saveButton;
this.cssClass = cssClass || '';
this.forceValid = forceValid;
}
_createClass(ShModalService, [{
key: 'open',
value: function open() {
var _this = this;
return new Promise(function (resolve, reject) {
var cancel = function cancel() {
_this.close();
reject();
};
_reactDom2.default.render(_react2.default.createElement(
_shModalDialog2.default,
{ callBackFunction: true, shModalTitle: _this.title, shForceValid: _this.forceValid, shModalSaveButton: _this.saveButton, shSuccess: resolve, shCancel: cancel, shClass: _this.cssClass },
_this.contentElement
), rootElement);
});
}
}, {
key: 'close',
value: function close() {
this.fadeOut();
setTimeout(function () {
_reactDom2.default.unmountComponentAtNode(rootElement);
}, 1000);
}
}, {
key: 'fadeOut',
value: function fadeOut() {
document.getElementById('sh-modal').classList.remove('fade-in');
}
}, {
key: 'setValid',
value: function setValid() {
document.getElementById('sh-modal').classList.add('sh-valid');
}
}, {
key: 'removeValid',
value: function removeValid() {
document.getElementById('sh-modal').classList.remove('sh-valid');
}
}]);
return ShModalService;
}();
exports.default = ShModalService;
/***/ },
/* 1 */
/*!**************************************************************************************!*\
!*** external {"root":"React","commonjs2":"react","commonjs":"react","amd":"react"} ***!
\**************************************************************************************/
/***/ function(module, exports) {
module.exports = __WEBPACK_EXTERNAL_MODULE_1__;
/***/ },
/* 2 */
/*!*****************************************************************************************************!*\
!*** external {"root":"ReactDOM","commonjs2":"react-dom","commonjs":"react-dom","amd":"react-dom"} ***!
\*****************************************************************************************************/
/***/ function(module, exports) {
module.exports = __WEBPACK_EXTERNAL_MODULE_2__;
/***/ },
/* 3 */
/*!********************************!*\
!*** ./src/sh-modal-dialog.js ***!
\********************************/
/***/ function(module, exports, __webpack_require__) {
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _react = __webpack_require__(/*! react */ 1);
var _react2 = _interopRequireDefault(_react);
var _shCore = __webpack_require__(/*! sh-core */ 4);
var _shCore2 = _interopRequireDefault(_shCore);
var _lodash = __webpack_require__(/*! lodash */ 5);
var _ = _interopRequireWildcard(_lodash);
__webpack_require__(/*! ./sh-modal-dialog.scss */ 6);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var ShModalDialog = function (_React$Component) {
_inherits(ShModalDialog, _React$Component);
function ShModalDialog(props) {
_classCallCheck(this, ShModalDialog);
var _this = _possibleConstructorReturn(this, (ShModalDialog.__proto__ || Object.getPrototypeOf(ShModalDialog)).call(this, props));
_this.state = {
classList: {
displayModal: false,
fadeIn: false,
firstRun: true,
shValid: true
}
};
_this.showModal = _this.showModal.bind(_this);
_this.handleSuccess = _this.handleSuccess.bind(_this);
_this.handleCancel = _this.handleCancel.bind(_this);
return _this;
}
_createClass(ShModalDialog, [{
key: 'showModal',
value: function showModal(props) {
var _this2 = this;
this.setState({
classList: {
displayModal: true
}
}, function () {
setTimeout(function () {
var classList = {};
classList.displayModal = true;
classList.fadeIn = true;
classList.shValid = props.shForceValid;
_this2.setState({
classList: classList
});
}, 100);
});
}
}, {
key: 'componentDidMount',
value: function componentDidMount() {
this.showModal(this.props);
}
}, {
key: 'handleSuccess',
value: function handleSuccess() {
this.props.shSuccess();
}
}, {
key: 'handleCancel',
value: function handleCancel() {
this.props.shCancel();
}
}, {
key: 'getSaveButton',
value: function getSaveButton() {
if (!this.props.shModalSaveButton || _.isString(this.props.shModalSaveButton)) {
var buttonText = this.props.shModalSaveButton;
if (!buttonText) {
buttonText = 'Save';
}
return _react2.default.createElement(
'button',
{ id: 'sh-save-button', className: 'sh-btn sh-btn-primary',
onClick: this.handleSuccess },
buttonText
);
} else {
return this.props.shModalSaveButton;
}
}
}, {
key: 'render',
value: function render() {
return _react2.default.createElement(
'div',
{ className: 'sh-modal-dialog ' + _shCore2.default.getClassNames(this.state.classList),
id: 'sh-modal' },
_react2.default.createElement(
'div',
{ className: "sh-modal-content " + this.props.shClass },
_react2.default.createElement('i', { className: 'sh-icon icon-x sh-close', onClick: this.handleCancel }),
_react2.default.createElement(
'div',
{ className: 'sh-modal-title' },
this.props.shModalTitle
),
_react2.default.createElement(
'div',
{ className: 'sh-dynamic-content' },
this.props.children
),
_react2.default.createElement('div', { className: 'sh-button-divider' }),
_react2.default.createElement(
'div',
{ className: 'sh-button-group' },
_react2.default.createElement(
'button',
{ className: 'sh-btn sh-btn-default sh-cancel', onClick: this.handleCancel },
'Cancel'
),
this.getSaveButton()
)
)
);
}
}]);
return ShModalDialog;
}(_react2.default.Component);
ShModalDialog.propTypes = {
shModalTitle: _react2.default.PropTypes.string,
shModalSaveButton: _react2.default.PropTypes.any,
shSuccess: _react2.default.PropTypes.func,
shCancel: _react2.default.PropTypes.func
};
exports.default = ShModalDialog;
/***/ },
/* 4 */
/*!**********************************!*\
!*** ./~/sh-core/bin/sh-core.js ***!
\**********************************/
/***/ function(module, exports, __webpack_require__) {
(function webpackUniversalModuleDefinition(root, factory) {
if(true)
module.exports = factory(__webpack_require__(/*! lodash */ 5));
else if(typeof define === 'function' && define.amd)
define(["lodash"], factory);
else if(typeof exports === 'object')
exports["sh-core"] = factory(require("lodash"));
else
root["sh-core"] = factory(root["_"]);
})(this, function(__WEBPACK_EXTERNAL_MODULE_2__) {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
/******/
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.loaded = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/*!**********************!*\
!*** ./src/index.js ***!
\**********************/
/***/ function(module, exports, __webpack_require__) {
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getDecimal = exports.getClassNames = undefined;
var _getClassNames = __webpack_require__(/*! ./util/get-class-names */ 1);
var _getClassNames2 = _interopRequireDefault(_getClassNames);
var _getDecimal = __webpack_require__(/*! ./util/get-decimal */ 3);
var _getDecimal2 = _interopRequireDefault(_getDecimal);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
exports.getClassNames = _getClassNames2.default;
exports.getDecimal = _getDecimal2.default;
exports.default = {
getClassNames: _getClassNames2.default,
getDecimal: _getDecimal2.default
};
/***/ },
/* 1 */
/*!*************************************!*\
!*** ./src/util/get-class-names.js ***!
\*************************************/
/***/ function(module, exports, __webpack_require__) {
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _lodash = __webpack_require__(/*! lodash */ 2);
var _ = _interopRequireWildcard(_lodash);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
/**
* Get a string of classNames from the object passed in. Uses the keys for class names and only adds them if the value is true. Value of keys can be boolean, function, or strings. Functions are evaluated on call. Strings are appended to end of key.
*
* @param {object} classObject Object containing keys of class names.
* @returns {string}
*/
function getClassNames(classObject) {
var classNames = [];
for (var key in classObject) {
if (classObject.hasOwnProperty(key)) {
var check = classObject[key];
var className = _.kebabCase(key);
if (_.isFunction(check)) {
if (check()) {
classNames.push(className);
}
} else if (_.isString(check)) {
if (className === 'include' || _.includes(check, ' ')) {
classNames = _.concat(classNames, check.split(' '));
} else {
classNames.push(className + '-' + _.kebabCase(check));
}
} else if (check) {
classNames.push(className);
}
}
}
classNames = _.uniq(classNames);
return classNames.join(' ');
}
exports.default = getClassNames;
/***/ },
/* 2 */
/*!*************************************************************************************!*\
!*** external {"root":"_","commonjs2":"lodash","commonjs":"lodash","amd":"lodash"} ***!
\*************************************************************************************/
/***/ function(module, exports) {
module.exports = __WEBPACK_EXTERNAL_MODULE_2__;
/***/ },
/* 3 */
/*!*********************************!*\
!*** ./src/util/get-decimal.js ***!
\*********************************/
/***/ function(module, exports, __webpack_require__) {
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _lodash = __webpack_require__(/*! lodash */ 2);
var _ = _interopRequireWildcard(_lodash);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
/**
* Get a decimal value from a string or number, remove any unnecessary characters.
*
* @param {string} value Alpha characters will be removed and a decimal will be returned. For example if you give it 'b.123' 0.123 will be returned.
* @returns {number}
*/
function getDecimal(value) {
if (!value) {
return 0;
}
var num = value;
if (!_.isNumber(value)) {
var isNeg = '-' && _.includes(value, '-');
var regExp = '[^0-9.]';
var numString = value.toString().replace(new RegExp(regExp, 'g'), '');
var numList = numString.split('.');
// numList will always have at least one value in array because we checked for an empty string earlier.
numList[0] += '.';
numString = numList.join('');
num = parseFloat(numString);
if (!num) {
num = 0;
} else if (isNeg) {
num *= -1;
}
}
return num;
}
exports.default = getDecimal;
/***/ }
/******/ ])
});
;
//# sourceMappingURL=sh-core.js.map
/***/ },
/* 5 */
/*!*************************************************************************************!*\
!*** external {"root":"_","commonjs2":"lodash","commonjs":"lodash","amd":"lodash"} ***!
\*************************************************************************************/
/***/ function(module, exports) {
module.exports = __WEBPACK_EXTERNAL_MODULE_5__;
/***/ },
/* 6 */
/*!**********************************!*\
!*** ./src/sh-modal-dialog.scss ***!
\**********************************/
/***/ function(module, exports, __webpack_require__) {
// style-loader: Adds some css to the DOM by adding a <style> tag
// load the styles
var content = __webpack_require__(/*! !./../~/css-loader!./../~/sass-loader!./sh-modal-dialog.scss */ 7);
if(typeof content === 'string') content = [[module.id, content, '']];
// add the styles to the DOM
var update = __webpack_require__(/*! ./../~/style-loader/addStyles.js */ 9)(content, {});
if(content.locals) module.exports = content.locals;
// Hot Module Replacement
if(false) {
// When the styles change, update the <style> tags
if(!content.locals) {
module.hot.accept("!!./../node_modules/css-loader/index.js!./../node_modules/sass-loader/index.js!./sh-modal-dialog.scss", function() {
var newContent = require("!!./../node_modules/css-loader/index.js!./../node_modules/sass-loader/index.js!./sh-modal-dialog.scss");
if(typeof newContent === 'string') newContent = [[module.id, newContent, '']];
update(newContent);
});
}
// When the module is disposed, remove the <style> tags
module.hot.dispose(function() { update(); });
}
/***/ },
/* 7 */
/*!*****************************************************************!*\
!*** ./~/css-loader!./~/sass-loader!./src/sh-modal-dialog.scss ***!
\*****************************************************************/
/***/ function(module, exports, __webpack_require__) {
exports = module.exports = __webpack_require__(/*! ./../~/css-loader/lib/css-base.js */ 8)();
// imports
// module
exports.push([module.id, ".sh-modal-dialog {\n color: white;\n position: fixed;\n top: 0;\n bottom: 0;\n left: 0;\n right: 0;\n background-color: rgba(0, 0, 0, 0.8);\n display: none;\n transition: opacity 0.5s ease-in-out;\n opacity: 0; }\n .sh-modal-dialog.fade-in {\n opacity: 1;\n transition: opacity 0.5s ease-in-out; }\n .sh-modal-dialog.display-modal {\n display: block;\n z-index: 10000000; }\n .sh-modal-dialog:not(.sh-valid) .sh-button-group .sh-btn.sh-btn-primary {\n transition: opacity .5s;\n cursor: not-allowed;\n opacity: .4; }\n .sh-modal-dialog.sh-valid .sh-button-group .sh-btn.sh-btn-primary {\n opacity: 1;\n transition: opacity .5s; }\n .sh-modal-dialog .sh-modal-content {\n position: absolute;\n left: calc(50% - 300px);\n right: calc(50% - 300px);\n top: calc(50% - 300px);\n bottom: calc(50% - 300px);\n background-color: #304853;\n border-radius: 4px;\n padding: 40px 50px; }\n .sh-modal-dialog .sh-modal-content.sh-small {\n left: calc(50% - 300px);\n right: calc(50% - 300px);\n top: calc(50% - 150px);\n bottom: calc(50% - 150px); }\n .sh-modal-dialog .sh-modal-content.sh-small .sh-modal-title {\n font-size: 32px; }\n .sh-modal-dialog .sh-modal-content .sh-close {\n position: absolute;\n top: 20px;\n right: 20px;\n font-size: 20px;\n color: rgba(255, 255, 255, 0.4);\n cursor: pointer; }\n .sh-modal-dialog .sh-modal-content .sh-modal-title {\n line-height: 1.1;\n color: white;\n font-size: 45px;\n font-family: \"Roboto Condensed\", \"Open Sans\";\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis; }\n .sh-modal-dialog .sh-modal-content .sh-dynamic-content {\n position: absolute;\n left: 50px;\n right: 50px;\n top: 115px;\n bottom: 100px;\n overflow-y: auto;\n color: rgba(255, 255, 255, 0.4); }\n .sh-modal-dialog .sh-modal-content .sh-button-divider {\n position: absolute;\n bottom: 100px;\n width: 100%;\n border-top: 1px solid #1b2126;\n left: 0; }\n .sh-modal-dialog .sh-modal-content .sh-button-group {\n position: absolute;\n right: 70px;\n bottom: 30px; }\n .sh-modal-dialog .sh-modal-content .sh-button-group .sh-cancel {\n margin-right: 20px;\n background-color: transparent;\n color: #3ab676; }\n", ""]);
// exports
/***/ },
/* 8 */
/*!**************************************!*\
!*** ./~/css-loader/lib/css-base.js ***!
\**************************************/
/***/ function(module, exports) {
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
// css base code, injected by the css-loader
module.exports = function() {
var list = [];
// return the list of modules as css string
list.toString = function toString() {
var result = [];
for(var i = 0; i < this.length; i++) {
var item = this[i];
if(item[2]) {
result.push("@media " + item[2] + "{" + item[1] + "}");
} else {
result.push(item[1]);
}
}
return result.join("");
};
// import a list of modules into the list
list.i = function(modules, mediaQuery) {
if(typeof modules === "string")
modules = [[null, modules, ""]];
var alreadyImportedModules = {};
for(var i = 0; i < this.length; i++) {
var id = this[i][0];
if(typeof id === "number")
alreadyImportedModules[id] = true;
}
for(i = 0; i < modules.length; i++) {
var item = modules[i];
// skip already imported module
// this implementation is not 100% perfect for weird media query combinations
// when a module is imported multiple times with different media queries.
// I hope this will never occur (Hey this way we have smaller bundles)
if(typeof item[0] !== "number" || !alreadyImportedModules[item[0]]) {
if(mediaQuery && !item[2]) {
item[2] = mediaQuery;
} else if(mediaQuery) {
item[2] = "(" + item[2] + ") and (" + mediaQuery + ")";
}
list.push(item);
}
}
};
return list;
};
/***/ },
/* 9 */
/*!*************************************!*\
!*** ./~/style-loader/addStyles.js ***!
\*************************************/
/***/ function(module, exports, __webpack_require__) {
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
var stylesInDom = {},
memoize = function(fn) {
var memo;
return function () {
if (typeof memo === "undefined") memo = fn.apply(this, arguments);
return memo;
};
},
isOldIE = memoize(function() {
return /msie [6-9]\b/.test(window.navigator.userAgent.toLowerCase());
}),
getHeadElement = memoize(function () {
return document.head || document.getElementsByTagName("head")[0];
}),
singletonElement = null,
singletonCounter = 0,
styleElementsInsertedAtTop = [];
module.exports = function(list, options) {
if(true) {
if(typeof document !== "object") throw new Error("The style-loader cannot be used in a non-browser environment");
}
options = options || {};
// Force single-tag solution on IE6-9, which has a hard limit on the # of <style>
// tags it will allow on a page
if (typeof options.singleton === "undefined") options.singleton = isOldIE();
// By default, add <style> tags to the bottom of <head>.
if (typeof options.insertAt === "undefined") options.insertAt = "bottom";
var styles = listToStyles(list);
addStylesToDom(styles, options);
return function update(newList) {
var mayRemove = [];
for(var i = 0; i < styles.length; i++) {
var item = styles[i];
var domStyle = stylesInDom[item.id];
domStyle.refs--;
mayRemove.push(domStyle);
}
if(newList) {
var newStyles = listToStyles(newList);
addStylesToDom(newStyles, options);
}
for(var i = 0; i < mayRemove.length; i++) {
var domStyle = mayRemove[i];
if(domStyle.refs === 0) {
for(var j = 0; j < domStyle.parts.length; j++)
domStyle.parts[j]();
delete stylesInDom[domStyle.id];
}
}
};
}
function addStylesToDom(styles, options) {
for(var i = 0; i < styles.length; i++) {
var item = styles[i];
var domStyle = stylesInDom[item.id];
if(domStyle) {
domStyle.refs++;
for(var j = 0; j < domStyle.parts.length; j++) {
domStyle.parts[j](item.parts[j]);
}
for(; j < item.parts.length; j++) {
domStyle.parts.push(addStyle(item.parts[j], options));
}
} else {
var parts = [];
for(var j = 0; j < item.parts.length; j++) {
parts.push(addStyle(item.parts[j], options));
}
stylesInDom[item.id] = {id: item.id, refs: 1, parts: parts};
}
}
}
function listToStyles(list) {
var styles = [];
var newStyles = {};
for(var i = 0; i < list.length; i++) {
var item = list[i];
var id = item[0];
var css = item[1];
var media = item[2];
var sourceMap = item[3];
var part = {css: css, media: media, sourceMap: sourceMap};
if(!newStyles[id])
styles.push(newStyles[id] = {id: id, parts: [part]});
else
newStyles[id].parts.push(part);
}
return styles;
}
function insertStyleElement(options, styleElement) {
var head = getHeadElement();
var lastStyleElementInsertedAtTop = styleElementsInsertedAtTop[styleElementsInsertedAtTop.length - 1];
if (options.insertAt === "top") {
if(!lastStyleElementInsertedAtTop) {
head.insertBefore(styleElement, head.firstChild);
} else if(lastStyleElementInsertedAtTop.nextSibling) {
head.insertBefore(styleElement, lastStyleElementInsertedAtTop.nextSibling);
} else {
head.appendChild(styleElement);
}
styleElementsInsertedAtTop.push(styleElement);
} else if (options.insertAt === "bottom") {
head.appendChild(styleElement);
} else {
throw new Error("Invalid value for parameter 'insertAt'. Must be 'top' or 'bottom'.");
}
}
function removeStyleElement(styleElement) {
styleElement.parentNode.removeChild(styleElement);
var idx = styleElementsInsertedAtTop.indexOf(styleElement);
if(idx >= 0) {
styleElementsInsertedAtTop.splice(idx, 1);
}
}
function createStyleElement(options) {
var styleElement = document.createElement("style");
styleElement.type = "text/css";
insertStyleElement(options, styleElement);
return styleElement;
}
function createLinkElement(options) {
var linkElement = document.createElement("link");
linkElement.rel = "stylesheet";
insertStyleElement(options, linkElement);
return linkElement;
}
function addStyle(obj, options) {
var styleElement, update, remove;
if (options.singleton) {
var styleIndex = singletonCounter++;
styleElement = singletonElement || (singletonElement = createStyleElement(options));
update = applyToSingletonTag.bind(null, styleElement, styleIndex, false);
remove = applyToSingletonTag.bind(null, styleElement, styleIndex, true);
} else if(obj.sourceMap &&
typeof URL === "function" &&
typeof URL.createObjectURL === "function" &&
typeof URL.revokeObjectURL === "function" &&
typeof Blob === "function" &&
typeof btoa === "function") {
styleElement = createLinkElement(options);
update = updateLink.bind(null, styleElement);
remove = function() {
removeStyleElement(styleElement);
if(styleElement.href)
URL.revokeObjectURL(styleElement.href);
};
} else {
styleElement = createStyleElement(options);
update = applyToTag.bind(null, styleElement);
remove = function() {
removeStyleElement(styleElement);
};
}
update(obj);
return function updateStyle(newObj) {
if(newObj) {
if(newObj.css === obj.css && newObj.media === obj.media && newObj.sourceMap === obj.sourceMap)
return;
update(obj = newObj);
} else {
remove();
}
};
}
var replaceText = (function () {
var textStore = [];
return function (index, replacement) {
textStore[index] = replacement;
return textStore.filter(Boolean).join('\n');
};
})();
function applyToSingletonTag(styleElement, index, remove, obj) {
var css = remove ? "" : obj.css;
if (styleElement.styleSheet) {
styleElement.styleSheet.cssText = replaceText(index, css);
} else {
var cssNode = document.createTextNode(css);
var childNodes = styleElement.childNodes;
if (childNodes[index]) styleElement.removeChild(childNodes[index]);
if (childNodes.length) {
styleElement.insertBefore(cssNode, childNodes[index]);
} else {
styleElement.appendChild(cssNode);
}
}
}
function applyToTag(styleElement, obj) {
var css = obj.css;
var media = obj.media;
if(media) {
styleElement.setAttribute("media", media)
}
if(styleElement.styleSheet) {
styleElement.styleSheet.cssText = css;
} else {
while(styleElement.firstChild) {
styleElement.removeChild(styleElement.firstChild);
}
styleElement.appendChild(document.createTextNode(css));
}
}
function updateLink(linkElement, obj) {
var css = obj.css;
var sourceMap = obj.sourceMap;
if(sourceMap) {
// http://stackoverflow.com/a/26603875
css += "\n/*# sourceMappingURL=data:application/json;base64," + btoa(unescape(encodeURIComponent(JSON.stringify(sourceMap)))) + " */";
}
var blob = new Blob([css], { type: "text/css" });
var oldSrc = linkElement.href;
linkElement.href = URL.createObjectURL(blob);
if(oldSrc)
URL.revokeObjectURL(oldSrc);
}
/***/ }
/******/ ])
});
;
//# sourceMappingURL=sh-modal-service.js.map