| /* |
| * Licensed to the Apache Software Foundation (ASF) under one |
| * or more contributor license agreements. See the NOTICE file |
| * distributed with this work for additional information |
| * regarding copyright ownership. The ASF licenses this file |
| * to you under the Apache License, Version 2.0 (the |
| * "License"); you may not use this file except in compliance |
| * with the License. You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, |
| * software distributed under the License is distributed on an |
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| * KIND, either express or implied. See the License for the |
| * specific language governing permissions and limitations |
| * under the License. |
| */ |
| import Modal from './modal' |
| |
| const CONTENT_CLASS = 'content' |
| const MSG_CLASS = 'content-msg' |
| const BUTTON_GROUP_CLASS = 'btn-group' |
| const BUTTON_CLASS = 'btn' |
| |
| export default function Alert (config) { |
| this.msg = config.message || '' |
| this.callback = config.callback |
| this.okTitle = config.okTitle || 'OK' |
| Modal.call(this) |
| this.node.classList.add('weex-alert') |
| } |
| |
| Alert.prototype = Object.create(Modal.prototype) |
| |
| Alert.prototype.createNodeContent = function () { |
| const content = document.createElement('div') |
| content.classList.add(CONTENT_CLASS) |
| this.node.appendChild(content) |
| |
| const msg = document.createElement('div') |
| msg.classList.add(MSG_CLASS) |
| msg.appendChild(document.createTextNode(this.msg)) |
| content.appendChild(msg) |
| |
| const buttonGroup = document.createElement('div') |
| buttonGroup.classList.add(BUTTON_GROUP_CLASS) |
| this.node.appendChild(buttonGroup) |
| const button = document.createElement('div') |
| button.classList.add(BUTTON_CLASS, 'alert-ok') |
| button.appendChild(document.createTextNode(this.okTitle)) |
| buttonGroup.appendChild(button) |
| } |
| |
| Alert.prototype.bindEvents = function () { |
| Modal.prototype.bindEvents.call(this) |
| const button = this.node.querySelector('.' + BUTTON_CLASS) |
| button.addEventListener('click', function () { |
| this.destroy() |
| this.callback && this.callback() |
| }.bind(this)) |
| } |