switch.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  1. module.exports =
  2. /******/ (function(modules) { // webpackBootstrap
  3. /******/ // The module cache
  4. /******/ var installedModules = {};
  5. /******/
  6. /******/ // The require function
  7. /******/ function __webpack_require__(moduleId) {
  8. /******/
  9. /******/ // Check if module is in cache
  10. /******/ if(installedModules[moduleId]) {
  11. /******/ return installedModules[moduleId].exports;
  12. /******/ }
  13. /******/ // Create a new module (and put it into the cache)
  14. /******/ var module = installedModules[moduleId] = {
  15. /******/ i: moduleId,
  16. /******/ l: false,
  17. /******/ exports: {}
  18. /******/ };
  19. /******/
  20. /******/ // Execute the module function
  21. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  22. /******/
  23. /******/ // Flag the module as loaded
  24. /******/ module.l = true;
  25. /******/
  26. /******/ // Return the exports of the module
  27. /******/ return module.exports;
  28. /******/ }
  29. /******/
  30. /******/
  31. /******/ // expose the modules object (__webpack_modules__)
  32. /******/ __webpack_require__.m = modules;
  33. /******/
  34. /******/ // expose the module cache
  35. /******/ __webpack_require__.c = installedModules;
  36. /******/
  37. /******/ // define getter function for harmony exports
  38. /******/ __webpack_require__.d = function(exports, name, getter) {
  39. /******/ if(!__webpack_require__.o(exports, name)) {
  40. /******/ Object.defineProperty(exports, name, {
  41. /******/ configurable: false,
  42. /******/ enumerable: true,
  43. /******/ get: getter
  44. /******/ });
  45. /******/ }
  46. /******/ };
  47. /******/
  48. /******/ // getDefaultExport function for compatibility with non-harmony modules
  49. /******/ __webpack_require__.n = function(module) {
  50. /******/ var getter = module && module.__esModule ?
  51. /******/ function getDefault() { return module['default']; } :
  52. /******/ function getModuleExports() { return module; };
  53. /******/ __webpack_require__.d(getter, 'a', getter);
  54. /******/ return getter;
  55. /******/ };
  56. /******/
  57. /******/ // Object.prototype.hasOwnProperty.call
  58. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  59. /******/
  60. /******/ // __webpack_public_path__
  61. /******/ __webpack_require__.p = "/dist/";
  62. /******/
  63. /******/ // Load entry module and return exports
  64. /******/ return __webpack_require__(__webpack_require__.s = 134);
  65. /******/ })
  66. /************************************************************************/
  67. /******/ ({
  68. /***/ 0:
  69. /***/ (function(module, exports) {
  70. /* globals __VUE_SSR_CONTEXT__ */
  71. // IMPORTANT: Do NOT use ES2015 features in this file.
  72. // This module is a runtime utility for cleaner component module output and will
  73. // be included in the final webpack user bundle.
  74. module.exports = function normalizeComponent (
  75. rawScriptExports,
  76. compiledTemplate,
  77. functionalTemplate,
  78. injectStyles,
  79. scopeId,
  80. moduleIdentifier /* server only */
  81. ) {
  82. var esModule
  83. var scriptExports = rawScriptExports = rawScriptExports || {}
  84. // ES6 modules interop
  85. var type = typeof rawScriptExports.default
  86. if (type === 'object' || type === 'function') {
  87. esModule = rawScriptExports
  88. scriptExports = rawScriptExports.default
  89. }
  90. // Vue.extend constructor export interop
  91. var options = typeof scriptExports === 'function'
  92. ? scriptExports.options
  93. : scriptExports
  94. // render functions
  95. if (compiledTemplate) {
  96. options.render = compiledTemplate.render
  97. options.staticRenderFns = compiledTemplate.staticRenderFns
  98. options._compiled = true
  99. }
  100. // functional template
  101. if (functionalTemplate) {
  102. options.functional = true
  103. }
  104. // scopedId
  105. if (scopeId) {
  106. options._scopeId = scopeId
  107. }
  108. var hook
  109. if (moduleIdentifier) { // server build
  110. hook = function (context) {
  111. // 2.3 injection
  112. context =
  113. context || // cached call
  114. (this.$vnode && this.$vnode.ssrContext) || // stateful
  115. (this.parent && this.parent.$vnode && this.parent.$vnode.ssrContext) // functional
  116. // 2.2 with runInNewContext: true
  117. if (!context && typeof __VUE_SSR_CONTEXT__ !== 'undefined') {
  118. context = __VUE_SSR_CONTEXT__
  119. }
  120. // inject component styles
  121. if (injectStyles) {
  122. injectStyles.call(this, context)
  123. }
  124. // register component module identifier for async chunk inferrence
  125. if (context && context._registeredComponents) {
  126. context._registeredComponents.add(moduleIdentifier)
  127. }
  128. }
  129. // used by ssr in case component is cached and beforeCreate
  130. // never gets called
  131. options._ssrRegister = hook
  132. } else if (injectStyles) {
  133. hook = injectStyles
  134. }
  135. if (hook) {
  136. var functional = options.functional
  137. var existing = functional
  138. ? options.render
  139. : options.beforeCreate
  140. if (!functional) {
  141. // inject component registration as beforeCreate hook
  142. options.beforeCreate = existing
  143. ? [].concat(existing, hook)
  144. : [hook]
  145. } else {
  146. // for template-only hot-reload because in that case the render fn doesn't
  147. // go through the normalizer
  148. options._injectStyles = hook
  149. // register for functioal component in vue file
  150. options.render = function renderWithStyleInjection (h, context) {
  151. hook.call(context)
  152. return existing(h, context)
  153. }
  154. }
  155. }
  156. return {
  157. esModule: esModule,
  158. exports: scriptExports,
  159. options: options
  160. }
  161. }
  162. /***/ }),
  163. /***/ 134:
  164. /***/ (function(module, exports, __webpack_require__) {
  165. "use strict";
  166. exports.__esModule = true;
  167. var _component = __webpack_require__(135);
  168. var _component2 = _interopRequireDefault(_component);
  169. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  170. /* istanbul ignore next */
  171. _component2.default.install = function (Vue) {
  172. Vue.component(_component2.default.name, _component2.default);
  173. };
  174. exports.default = _component2.default;
  175. /***/ }),
  176. /***/ 135:
  177. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  178. "use strict";
  179. Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
  180. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_component_vue__ = __webpack_require__(136);
  181. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_component_vue___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_component_vue__);
  182. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__node_modules_vue_loader_lib_template_compiler_index_id_data_v_80721fd0_hasScoped_false_preserveWhitespace_false_buble_transforms_node_modules_vue_loader_lib_selector_type_template_index_0_component_vue__ = __webpack_require__(137);
  183. var normalizeComponent = __webpack_require__(0)
  184. /* script */
  185. /* template */
  186. /* template functional */
  187. var __vue_template_functional__ = false
  188. /* styles */
  189. var __vue_styles__ = null
  190. /* scopeId */
  191. var __vue_scopeId__ = null
  192. /* moduleIdentifier (server only) */
  193. var __vue_module_identifier__ = null
  194. var Component = normalizeComponent(
  195. __WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_component_vue___default.a,
  196. __WEBPACK_IMPORTED_MODULE_1__node_modules_vue_loader_lib_template_compiler_index_id_data_v_80721fd0_hasScoped_false_preserveWhitespace_false_buble_transforms_node_modules_vue_loader_lib_selector_type_template_index_0_component_vue__["a" /* default */],
  197. __vue_template_functional__,
  198. __vue_styles__,
  199. __vue_scopeId__,
  200. __vue_module_identifier__
  201. )
  202. /* harmony default export */ __webpack_exports__["default"] = (Component.exports);
  203. /***/ }),
  204. /***/ 136:
  205. /***/ (function(module, exports, __webpack_require__) {
  206. "use strict";
  207. exports.__esModule = true;
  208. var _focus = __webpack_require__(19);
  209. var _focus2 = _interopRequireDefault(_focus);
  210. var _migrating = __webpack_require__(8);
  211. var _migrating2 = _interopRequireDefault(_migrating);
  212. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  213. //
  214. //
  215. //
  216. //
  217. //
  218. //
  219. //
  220. //
  221. //
  222. //
  223. //
  224. //
  225. //
  226. //
  227. //
  228. //
  229. //
  230. //
  231. //
  232. //
  233. //
  234. //
  235. //
  236. //
  237. //
  238. //
  239. //
  240. //
  241. //
  242. //
  243. //
  244. //
  245. //
  246. //
  247. //
  248. //
  249. //
  250. exports.default = {
  251. name: 'ElSwitch',
  252. mixins: [(0, _focus2.default)('input'), _migrating2.default],
  253. inject: {
  254. elForm: {
  255. default: ''
  256. }
  257. },
  258. props: {
  259. value: {
  260. type: [Boolean, String, Number],
  261. default: false
  262. },
  263. disabled: {
  264. type: Boolean,
  265. default: false
  266. },
  267. width: {
  268. type: Number,
  269. default: 40
  270. },
  271. activeIconClass: {
  272. type: String,
  273. default: ''
  274. },
  275. inactiveIconClass: {
  276. type: String,
  277. default: ''
  278. },
  279. activeText: String,
  280. inactiveText: String,
  281. activeColor: {
  282. type: String,
  283. default: ''
  284. },
  285. inactiveColor: {
  286. type: String,
  287. default: ''
  288. },
  289. activeValue: {
  290. type: [Boolean, String, Number],
  291. default: true
  292. },
  293. inactiveValue: {
  294. type: [Boolean, String, Number],
  295. default: false
  296. },
  297. name: {
  298. type: String,
  299. default: ''
  300. },
  301. id: String
  302. },
  303. data: function data() {
  304. return {
  305. coreWidth: this.width
  306. };
  307. },
  308. created: function created() {
  309. if (!~[this.activeValue, this.inactiveValue].indexOf(this.value)) {
  310. this.$emit('input', this.inactiveValue);
  311. }
  312. },
  313. computed: {
  314. checked: function checked() {
  315. return this.value === this.activeValue;
  316. },
  317. switchDisabled: function switchDisabled() {
  318. return this.disabled || (this.elForm || {}).disabled;
  319. }
  320. },
  321. watch: {
  322. checked: function checked() {
  323. this.$refs.input.checked = this.checked;
  324. if (this.activeColor || this.inactiveColor) {
  325. this.setBackgroundColor();
  326. }
  327. }
  328. },
  329. methods: {
  330. handleChange: function handleChange(event) {
  331. var _this = this;
  332. this.$emit('input', !this.checked ? this.activeValue : this.inactiveValue);
  333. this.$emit('change', !this.checked ? this.activeValue : this.inactiveValue);
  334. this.$nextTick(function () {
  335. // set input's checked property
  336. // in case parent refuses to change component's value
  337. _this.$refs.input.checked = _this.checked;
  338. });
  339. },
  340. setBackgroundColor: function setBackgroundColor() {
  341. var newColor = this.checked ? this.activeColor : this.inactiveColor;
  342. this.$refs.core.style.borderColor = newColor;
  343. this.$refs.core.style.backgroundColor = newColor;
  344. },
  345. switchValue: function switchValue() {
  346. !this.switchDisabled && this.handleChange();
  347. },
  348. getMigratingConfig: function getMigratingConfig() {
  349. return {
  350. props: {
  351. 'on-color': 'on-color is renamed to active-color.',
  352. 'off-color': 'off-color is renamed to inactive-color.',
  353. 'on-text': 'on-text is renamed to active-text.',
  354. 'off-text': 'off-text is renamed to inactive-text.',
  355. 'on-value': 'on-value is renamed to active-value.',
  356. 'off-value': 'off-value is renamed to inactive-value.',
  357. 'on-icon-class': 'on-icon-class is renamed to active-icon-class.',
  358. 'off-icon-class': 'off-icon-class is renamed to inactive-icon-class.'
  359. }
  360. };
  361. }
  362. },
  363. mounted: function mounted() {
  364. /* istanbul ignore if */
  365. this.coreWidth = this.width || 40;
  366. if (this.activeColor || this.inactiveColor) {
  367. this.setBackgroundColor();
  368. }
  369. this.$refs.input.checked = this.checked;
  370. }
  371. };
  372. /***/ }),
  373. /***/ 137:
  374. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  375. "use strict";
  376. var render = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('div',{staticClass:"el-switch",class:{ 'is-disabled': _vm.switchDisabled, 'is-checked': _vm.checked },attrs:{"role":"switch","aria-checked":_vm.checked,"aria-disabled":_vm.switchDisabled},on:{"click":_vm.switchValue}},[_c('input',{ref:"input",staticClass:"el-switch__input",attrs:{"type":"checkbox","id":_vm.id,"name":_vm.name,"true-value":_vm.activeValue,"false-value":_vm.inactiveValue,"disabled":_vm.switchDisabled},on:{"change":_vm.handleChange,"keydown":function($event){if(!('button' in $event)&&_vm._k($event.keyCode,"enter",13,$event.key)){ return null; }_vm.switchValue($event)}}}),(_vm.inactiveIconClass || _vm.inactiveText)?_c('span',{class:['el-switch__label', 'el-switch__label--left', !_vm.checked ? 'is-active' : '']},[(_vm.inactiveIconClass)?_c('i',{class:[_vm.inactiveIconClass]}):_vm._e(),(!_vm.inactiveIconClass && _vm.inactiveText)?_c('span',{attrs:{"aria-hidden":_vm.checked}},[_vm._v(_vm._s(_vm.inactiveText))]):_vm._e()]):_vm._e(),_c('span',{ref:"core",staticClass:"el-switch__core",style:({ 'width': _vm.coreWidth + 'px' })}),(_vm.activeIconClass || _vm.activeText)?_c('span',{class:['el-switch__label', 'el-switch__label--right', _vm.checked ? 'is-active' : '']},[(_vm.activeIconClass)?_c('i',{class:[_vm.activeIconClass]}):_vm._e(),(!_vm.activeIconClass && _vm.activeText)?_c('span',{attrs:{"aria-hidden":!_vm.checked}},[_vm._v(_vm._s(_vm.activeText))]):_vm._e()]):_vm._e()])}
  377. var staticRenderFns = []
  378. var esExports = { render: render, staticRenderFns: staticRenderFns }
  379. /* harmony default export */ __webpack_exports__["a"] = (esExports);
  380. /***/ }),
  381. /***/ 19:
  382. /***/ (function(module, exports) {
  383. module.exports = require("element-ui/lib/mixins/focus");
  384. /***/ }),
  385. /***/ 8:
  386. /***/ (function(module, exports) {
  387. module.exports = require("element-ui/lib/mixins/migrating");
  388. /***/ })
  389. /******/ });