| 146 | |
| 147 | // 组件构造器 |
| 148 | var Class = function (options) { |
| 149 | var that = this; |
| 150 | that.index = ++laydate.index; |
| 151 | that.config = lay.extend( |
| 152 | {}, |
| 153 | that.config, |
| 154 | laydate.config, |
| 155 | options, |
| 156 | overwriteArray |
| 157 | ); |
| 158 | |
| 159 | // 若 elem 非唯一,则拆分为多个实例 |
| 160 | var elem = lay(options.elem || that.config.elem); |
| 161 | if (elem.length > 1) { |
| 162 | lay.each(elem, function () { |
| 163 | laydate.render( |
| 164 | lay.extend( |
| 165 | {}, |
| 166 | that.config, |
| 167 | { |
| 168 | elem: this |
| 169 | }, |
| 170 | overwriteArray |
| 171 | ) |
| 172 | ); |
| 173 | }); |
| 174 | return that; |
| 175 | } |
| 176 | |
| 177 | // 初始化属性 |
| 178 | options = lay.extend(that.config, lay.options(elem[0]), overwriteArray); // 继承节点上的属性 |
| 179 | |
| 180 | // 更新 i18n 消息对象 |
| 181 | that.i18nMessages = that.getI18nMessages(); |
| 182 | |
| 183 | // 处理日期面板顶部年月顺序 |
| 184 | // 这是一个变通的方法,因为 i18nMessages.monthBeforeYear 不存在 |
| 185 | if (typeof that.i18nMessages.monthBeforeYear !== 'boolean') { |
| 186 | if (!window.Intl) { |
| 187 | that.i18nMessages.monthBeforeYear = !( |
| 188 | YearBeforeMonthLocale.indexOf(options.lang) > -1 |
| 189 | ); |
| 190 | } else { |
| 191 | try { |
| 192 | var formatter = new Intl.DateTimeFormat(options.lang, { |
| 193 | year: 'numeric', |
| 194 | month: 'short' |
| 195 | }); |
| 196 | var parts = formatter.formatToParts(new Date(1970, 0)); |
| 197 | var order = []; |
| 198 | parts.map(function (part) { |
| 199 | if (part.type === 'year' || part.type === 'month') { |
| 200 | order.push(part.type); |
| 201 | } |
| 202 | }); |
| 203 | that.i18nMessages.monthBeforeYear = order[0] === 'month'; |
| 204 | } catch (e) { |
| 205 | that.i18nMessages.monthBeforeYear = !( |