createPanel: function(){ if(this.panelDiv){ this._fillYear(); return; } var oThis = this; this.panelDiv = makeDOM('<div class="u-date-panel" style="margin:0px;"></div>'); this.panelContentDiv = makeDOM('<div class="u-date-content"></div>'); this.panelDiv.appendChild(this.panelContentDiv); this.preBtn = makeDOM('<button class="u-date-pre-button u-button mini"><</button>'); this.nextBtn = makeDOM('<button class="u-date-next-button u-button mini">></button>'); on(this.preBtn, 'click', function(e){ oThis.startYear -= 10; oThis._fillYear(); }); on(this.nextBtn, 'click', function(e){ oThis.startYear += 10; oThis._fillYear(); }); this.panelContentDiv.appendChild(this.preBtn); this.panelContentDiv.appendChild(this.nextBtn); this._fillYear(); },
iframeDialogF.prototype.create = function() { var closeStr = '' ,footerStr =''; var oThis = this; if(this.hasCloseMenu) { var closeStr = '<div class="u-msg-close"> <span aria-hidden="true">×</span></div>'; } if (this.hasFooter) { var footerStr = '<div class="u-msg-footer"><button class="u-msg-ok u-button u-button-primary raised">确定</button><button class="u-msg-cancel u-button">取消</button></div>' + '</div>'; } var templateStr = this.template.replace('{close}', closeStr); templateStr = templateStr.replace('{url}',this.url); templateStr = templateStr.replace('{title}',this.title); templateStr = templateStr.replace('{footer}',footerStr); templateStr = templateStr.replace('{width}', this.width ? 'width:' + this.width + ';' : ''); templateStr = templateStr.replace('{height}', this.height ? 'height:' + this.height + ';' : ''); templateStr = templateStr.replace('{top}', this.top ? 'top:' + this.top + ';' : ''); this.templateDom = makeDOM(templateStr); this.overlayDiv = makeModal(this.templateDom); if (this.hasCloseMenu) { this.closeDiv = this.templateDom.querySelector('.u-msg-close'); on(this.closeDiv, 'click', function() { if(oThis.onClose() !== false) { oThis.close(); } }); } if (this.hasFooter) { var okBtn = this.templateDom.querySelector('.u-msg-ok'); var cancelBtn = this.templateDom.querySelector('.u-msg-cancel'); var closeBtn = new Button({ el: okBtn }); new Button({ el: cancelBtn }); on(okBtn, 'click', function() { if(oThis.onOk() !== false) { oThis.close(); } }) on(cancelBtn, 'click', function() { if(oThis.onCancel() !== false) { oThis.close(); } }) } document.body.appendChild(this.templateDom); this.isClosed = false; };
Refer.fn.create = function () { var self = this self.setVal = this.options.setVal; self.searchInput = this.options.searchInput; var prefixID = this.options.contentId.replace(/[^\w\s]/gi, '\\$&'); if (!this.options.isPOPMode) { //TODO 后续支持非弹窗模式 //if ($('#' + this.options.contentId).length === 0) { // $('body').append($('<div>').attr('id', this.options.contentId)); //} //this.$contentEle = $('#' + prefixID) //this.$okBtn = $('#' + prefixID + this.options.okId) //this.$cancelBtn = $('#' + prefixID + this.options.cancelId) } else { var dialog = document.querySelector('#' + prefixID); self.isDefaultDialog = true; if (dialog == null) { //var d = document.createElement('DIV') //d.innerHTML = '<div class="modal" id="' + prefixID + '"><div class="modal-dialog"><div class="modal-content">' + '<div class="modal-header"><h4 class="modal-title">Modal title</h4></div>' + '<div class="modal-body"></div><div class="modal-footer">' + '<button type="button" class="btn btn-primary okBtn">确定</button>' + '<button type="button" class="btn btn-default cancelBtn" data-dismiss="modal">取消</button></div></div></div></div>' dialog = makeDOM(' <div style="display:none;height:100%" id="' + prefixID + '">' + '<div class="u-msg-title"><h4 class="title">单据名称</h4></div>' + '<div class="u-msg-content">' + '<div class="content"></div>' + '</div>' + '<div class="u-msg-footer">' + '<button class="u-msg-ok u-button">'+ trans('public.confirm','确定') +'<span class="u-button-container"><span class="u-ripple"></span></span></button>' + '<button class="u-msg-cancel u-button">' + trans('public.cancel','取消') + '<span class="u-button-container"><span class="u-ripple"></span></span></button>' + '</div>' + '</div>'); document.body.appendChild(dialog) //dialog = document.body.querySelector('#' + prefixID); } //this.$contentEle = dialog.find('.modal-body'); this.titleDiv =dialog.querySelector('.title') this.contentDiv = dialog.querySelector('.content'); this.okBtn = dialog.querySelector('.u-msg-ok'); this.cancelBtn = dialog.querySelector('.u-msg-cancel'); this.dialog = dialog; //if (this.options.width) // dialog.find('.modal-content').css('width', this.options.width) //if (this.options.height) // this.$contentEle.css('height', this.options.height) //this.dialog.find('.modal-title').html(this.options.title) this.titleDiv.innerHTML = this.options.title; } on(this.okBtn, 'click', function(){ self.submit(); }) on(this.cancelBtn, 'click', function(){ self.cancel(); }) }
show: function (evt) { var self = this,width=this._input.offsetWidth; if(this.options.showFix){ document.body.appendChild(this._ul); this._ul.style.position = 'fixed'; showPanelByEle({ ele:this._input, panel:this._ul, position:"bottomLeft" }); }else{ // this.element.parentNode.appendChild(this._ul); // var left = this.element.offsetLeft, // inputHeight = this.element.offsetHeight, // top = this.element.offsetTop + inputHeight; // this._ul.style.left = left + 'px'; // this._ul.style.top = top + 'px'; var bodyWidth = document.body.clientWidth,bodyHeight = document.body.clientHeight, panelWidth = this._ul.offsetWidth,panelHeight = this._ul.offsetHeight; this.element.appendChild(this._ul); this.element.style.position = 'relative'; this.left = this._input.offsetLeft; var inputHeight = this._input.offsetHeight; this.top = this._input.offsetTop + inputHeight; if(this.left + panelWidth > bodyWidth){ this.left = bodyWidth - panelWidth; } if((this.top + panelHeight) > bodyHeight){ this.top = bodyHeight - panelHeight; } this._ul.style.left = this.left + 'px'; this._ul.style.top = this.top + 'px'; } this._ul.style.width = width + 'px'; $(this._ul).addClass('is-animating'); this._ul.style.zIndex = getZIndex(); $(this._ul).addClass('is-visible'); var callback = function (e) { if(e === evt || e.target === this._input || self._inputFocus == true) return; if(this.mutilSelect && (closest(e.target,'u-combo-ul') === self._ul || closest(e.target, 'u-combo-name-par') || closest(e.target, 'u-combo-name')) ) return; off(document,'click',callback); // document.removeEventListener('click', callback); this.hide(); }.bind(this); this.callback = callback; on(document,'click',callback); on(document.body,'touchend',callback) // document.addEventListener('click', callback); },
init: function() { if(hasClass(this.element, 'u-navmenu-horizontal')) { on(this.element, 'click', this._horNavlinkClickHander.bind(this)); } else { on(this.element, 'click', this._navlinkClickHander.bind(this)); } var items = this.element.querySelectorAll('.' + this._CssClasses.NAV_LINK); for(var i = 0; i < items.length; i++) { new Ripple(items[i]) } },
show: function(evt) { var oThis = this; if(this.value && this.value.indexOf('-') > -1){ var vA = this.value.split("-"); var month = vA[0]; this.month = month % 12; if(this.month == 0) this.month = 12; this.date = vA[1]; if(this.date>31) { this.date = 1; } } this.createPanel(); if(this.options.showFix){ document.body.appendChild(this.panelDiv); this.panelDiv.style.position = 'fixed'; showPanelByEle({ ele:this.input, panel:this.panelDiv, position:"bottomLeft" }); }else{ var bodyWidth = document.body.clientWidth,bodyHeight = document.body.clientHeight, panelWidth = this.panelDiv.offsetWidth,panelHeight = this.panelDiv.offsetHeight; this.element.appendChild(this.panelDiv); this.element.style.position = 'relative'; this.left = this.input.offsetLeft; var inputHeight = this.input.offsetHeight; this.top = this.input.offsetTop + inputHeight; if(this.left + panelWidth > bodyWidth){ this.left = bodyWidth - panelWidth; } if((this.top + panelHeight) > bodyHeight){ this.top = bodyHeight - panelHeight; } this.panelDiv.style.left = this.left + 'px'; this.panelDiv.style.top = this.top + 'px'; } this.panelDiv.style.zIndex = getZIndex(); addClass(this.panelDiv, 'is-visible'); var oThis = this; var callback = function (e) { if (e !== evt && e.target !== oThis.input && !oThis.clickPanel(e.target) && oThis._inputFocus != true) { // document.removeEventListener('click', callback); off(document,'click',callback); oThis.hide(); } }; on(document,'click',callback); // document.addEventListener('click', callback); },
focusEvent: function() { var self = this; on(this.input,'focus', function(e) { self._inputFocus = true; self.show(e); stopEvent(e); }); },
clickEvent: function() { var self = this; var caret = this.element.nextSibling on(caret,'click',function(e) { self.input.focus(); stopEvent(e); }) },
var iframeDialogF = function(options) { var defaultOptions = { hasCloseMenu: true, hasFooter: false, url: '', width: '', height: '', title: '标题', top: '10%', onClose: function (){}, onCancel: function (){}, onOk: function(){} } options = extend(defaultOptions, options); this.id = options['id']; this.template = iframeDialogTemplate; this.hasCloseMenu = options['hasCloseMenu']; this.hasFooter = options['hasFooter']; this.url = options['url']; this.top = options['top']; this.title = options['title']; this.width = options['width']; this.height = options['height']; this.onClose = options['onClose']; this.onOk = options['onOk']; this.onCancel = options['onCancel']; //是否有url,没有url直接跳出 if (!this.url) { return ; } this.create(); this.resizeFun = function() { // var cDom = this.contentDom.querySelector('.u-msg-content'); // cDom.style.height = ''; // var wholeHeight = this.templateDom.offsetHeight; // var contentHeight = this.contentDom.offsetHeight; // if(contentHeight > wholeHeight && cDom) // cDom.style.height = wholeHeight - (56 + 46) + 'px'; var wholeHeight = this.templateDom.offsetHeight; var cDom = this.templateDom.querySelector('.u-msg-content'); if (this.hasFooter) { cDom.style.height = wholeHeight - (56 + 52) + 'px'; }else { cDom.style.height = wholeHeight - 52 + 'px'; } }.bind(this); this.resizeFun(); on(window, 'resize', this.resizeFun); }
each(this.$ul.querySelectorAll('[role="page"] a'), function(i, node) { on(node, 'click', function() { var pz = (me.$element.querySelector(".page_z") && $(this).val()) || options.pageSize; me.page(parseInt(this.innerHTML), options.totalPages, pz); //me.$element.trigger('pageChange', parseInt($(this).html()) - 1) return false; }) })
var confirmDialogF = function(options) { if(typeof options === 'string') { options = { content: options }; } var defaultOptions = { id: '', msg: '', template: confirmDialogTemplate, width: '', height: '', top: '', hasFooter: true, onOk: function () {}, onCancel: function () {}, okText: trans('dialog.okText', '确定'), cancelText: trans('dialog.cancelText', '取消') } options = extend(defaultOptions, options); this.id = options['id']; this.hasFooter = options['hasFooter']; this.content = options['msg']; this.template = options['template']; this.width = options['width']; this.height = options['height']; this.height = options['top']; this.title = options['title']; this.titleIcon = options['titleIcon']; this.lazyShow = options['lazyShow']; this.onOk = options['onOk']; this.onCancel = options['onCancel']; this.okText = options['okText']; this.cancelText = options['cancelText']; this.create(); var msgDom = this.templateDom.querySelector('.u-msg-dialog'); if(this.height){ this.resizeFun = function() { var cDom = msgDom.querySelector('.u-msg-content'); if(!cDom) return; cDom.style.height = ''; var wholeHeight = msgDom.offsetHeight; var contentHeight = msgDom.scrollHeight; // if(contentHeight > wholeHeight && cDom) cDom.style.height = wholeHeight - (56 + 46) + 'px'; }.bind(this); this.resizeFun(); on(window, 'resize', this.resizeFun); } };
show: function(evt) { var oThis = this; this.createPanel(); this.width = this.element.offsetWidth; if(this.width < 300) this.width = 300; if(this.options.showFix){ document.body.appendChild(this.panelDiv); this.panelDiv.style.position = 'fixed'; showPanelByEle({ ele:this.input, panel:this.panelDiv, position:"bottomLeft" }); }else{ var bodyWidth = document.body.clientWidth,bodyHeight = document.body.clientHeight, panelWidth = this.panelDiv.offsetWidth,panelHeight = this.panelDiv.offsetHeight; this.element.appendChild(this.panelDiv); this.element.style.position = 'relative'; this.left = this.input.offsetLeft; var inputHeight = this.input.offsetHeight; this.top = this.input.offsetTop + inputHeight; if(this.left + panelWidth > bodyWidth){ this.left = bodyWidth - panelWidth; } if((this.top + panelHeight) > bodyHeight){ this.top = bodyHeight - panelHeight; } this.panelDiv.style.left = this.left + 'px'; this.panelDiv.style.top = this.top + 'px'; } this.panelDiv.style.width = 152 + 'px'; this.panelDiv.style.zIndex = getZIndex(); addClass(this.panelDiv, 'is-visible'); var callback = function (e) { if (e !== evt && e.target !== this.input && !oThis.clickPanel(e.target) && oThis._inputFocus != true) { off(document,'click',callback); // document.removeEventListener('click', callback); this.hide(); } }.bind(this); on(document,'click',callback); },
dataToDom2: function(items) { var ul = document.createElement("ul"); var num = items.length; var me = this; var showMoreMenu = false; // limited results to a max number if((this.options.maxItemsToShow > 0) && (this.options.maxItemsToShow < num)) { num = this.options.maxItemsToShow; if(this.options.moreMenuClick) { showMoreMenu = true; } } for(var i = 0; i < num; i++) { var item = items[i]; if(!item) continue; var li = document.createElement("li"); if(this.options.formatItem) li.innerHTML = this.options.formatItem(item, i, num); else li.innerHTML = item.label; li.selectValue = item.label; li._item = item; ul.appendChild(li); on(li, 'mouseenter', function() { var _li = ul.querySelector('li.ac_over'); if(_li) removeClass(_li, 'ac_over');; addClass(this, "ac_over"); me.active = indexOf(ul.querySelectorAll('li'), this); }); on(li, 'mouseleave', function() { removeClass(this, "ac_over"); }); on(li, 'mousedown', function(e) { stopEvent(e); me.selectItem(this); }); } if(showMoreMenu) { var li = document.createElement("li"); li.innerHTML = '更多'; ul.appendChild(li); on(li, 'mouseenter', function() { var _li = ul.querySelector('li.ac_over'); if(_li) removeClass(_li, 'ac_over');; addClass(this, "ac_over"); }); on(li, 'mouseleave', function() { removeClass(this, "ac_over"); }); on(li, 'mousedown', function(e) { stopEvent(e); me.options.moreMenuClick.call(me); }); } return ul; },
var messageDialogF = function(options) { if(typeof options === 'string') { options = { content: options }; } var defaultOptions = { id: '', msg: '', template: messageDialogTemplate, width: '', height: '', top: '', hasFooter: true, // title: '提示', // btnText: '确定', title: trans('dialog.title', '提示'), btnText: trans('dialog.okText', '确定'), closeFun: function (){} } options = extend(defaultOptions, options); this.id = options['id']; this.hasFooter = options['hasFooter']; this.content = options['msg']; this.title = options['title']; this.template = options['template']; this.width = options['width']; this.height = options['height']; this.top = options['top']; this.bthText = options['btnText']; this.lazyShow = options['lazyShow']; this.closeFun = options['closeFun']; this.create(); var msgDom = this.templateDom.querySelector('.u-msg-dialog'); if(this.height){ this.resizeFun = function() { var cDom = msgDom.querySelector('.u-msg-content'); if(!cDom) return; cDom.style.height = ''; var wholeHeight = msgDom.offsetHeight; var contentHeight = msgDom.scrollHeight; // if(contentHeight > wholeHeight && cDom) cDom.style.height = wholeHeight - (56 + 46) + 'px'; }.bind(this); this.resizeFun(); on(window, 'resize', this.resizeFun); } };
_fillMonth: function(){ var oldPanel,template,monthPage,_month,cells,i; oldPanel = this.panelContentDiv.querySelector('.u-date-content-page'); if(oldPanel) this.panelContentDiv.removeChild(oldPanel); _month = this.month; var _defaultMonth = _month + '月'; var monthIndex = udate._jsonLocale.defaultMonth.indexOf(_defaultMonth); template = ['<div class="u-date-content-page">', '<div class="u-date-content-title">'+ udate._jsonLocale.monthsShort[monthIndex] + '</div>', '<div class="u-date-content-panel">', '<div class="u-date-content-year-cell">'+ udate._jsonLocale.monthsShort[0] +'</div>', '<div class="u-date-content-year-cell">'+ udate._jsonLocale.monthsShort[1] +'</div>', '<div class="u-date-content-year-cell">'+ udate._jsonLocale.monthsShort[2] +'</div>', '<div class="u-date-content-year-cell">'+ udate._jsonLocale.monthsShort[3] +'</div>', '<div class="u-date-content-year-cell">'+ udate._jsonLocale.monthsShort[4] +'</div>', '<div class="u-date-content-year-cell">'+ udate._jsonLocale.monthsShort[5] +'</div>', '<div class="u-date-content-year-cell">'+ udate._jsonLocale.monthsShort[6] +'</div>', '<div class="u-date-content-year-cell">'+ udate._jsonLocale.monthsShort[7] +'</div>', '<div class="u-date-content-year-cell">'+ udate._jsonLocale.monthsShort[8] +'</div>', '<div class="u-date-content-year-cell">'+ udate._jsonLocale.monthsShort[9] +'</div>', '<div class="u-date-content-year-cell">'+ udate._jsonLocale.monthsShort[10] +'</div>', '<div class="u-date-content-year-cell">'+ udate._jsonLocale.monthsShort[11] +'</div>', '</div>', '</div>'].join(""); monthPage = makeDOM(template); cells =monthPage.querySelectorAll('.u-date-content-year-cell'); for (i = 0; i < cells.length; i++){ if (_month == i + 1){ addClass(cells[i],'current'); } cells[i]._value = i + 1; new URipple(cells[i]); } var oThis = this; on(monthPage, 'click', function(e){ var _m = e.target._value; if (_m) { oThis.month = _m; } monthPage.querySelector('.u-date-content-title').innerHTML = _m + '月'; oThis.setValue(oThis.year + '-' + oThis.month); oThis.hide(); }); this.preBtn.style.display = 'none'; this.nextBtn.style.display = 'none'; this._zoomIn(monthPage); this.currentPanel = 'month'; },
$(element).each(function(){ this.element = $(this)[0]; var triggers = oThis.options.trigger.split(' '); for (var i = triggers.length; i--;) { var trigger = triggers[i]; if (trigger == 'click') { on(this.element, 'click', this.toggle.bind(oThis,this.element)); } else if (trigger != 'manual') { var eventIn = trigger == 'hover' ? 'mouseenter' : 'focusin'; var eventOut = trigger == 'hover' ? 'mouseleave' : 'focusout'; on(this.element, eventIn, oThis.enter.bind(oThis,this.element)); on(this.element, eventOut, oThis.leave.bind(oThis,this.element)); } } oThis.options.title = oThis.options.title || this.element.getAttribute('title'); this.element.removeAttribute('title'); if (oThis.options.delay && typeof oThis.options.delay == 'number') { oThis.options.delay = { show: oThis.options.delay, hide: oThis.options.delay }; }; });
focusEvent: function() { var self = this; on(this.input,'focus', function(e) { self._inputFocus = true; self.show(e); if (e.stopPropagation) { e.stopPropagation(); } else { e.cancelBubble = true; } }); },
keydownEvent:function(){ var self = this; on(self.input, "keydown", function (e) { var code = e.keyCode ? e.keyCode : e.which ? e.which : e.charCode; if (!(code >= 48 && code <= 57||code==37||code==39||code==8 ||code==46)) { //阻止默认浏览器动作(W3C) if ( e && e.preventDefault ) e.preventDefault(); //IE中阻止函数器默认动作的方式 else window.event.returnValue = false; return false; } }); },
var dialogMode = function(options) { // 传入字符串的情况直接将字符串作为内容显示 if(typeof options === 'string') { options = { content: options }; } var defaultOptions = { id: '', content: '', hasCloseMenu: true, template: dialogTemplate, width: '', height: '' } options = extend(defaultOptions, options); this.id = options['id']; this.hasCloseMenu = options['hasCloseMenu']; this.content = options['content']; this.template = options['template']; this.width = options['width']; this.height = options['height']; this.lazyShow = options['lazyShow']; this.closeFun = options['closeFun']; this.create(); var msgDom = this.templateDom.querySelector('.u-msg-dialog'); if(this.height){ this.resizeFun = function() { var cDom = msgDom.querySelector('.u-msg-content'); if(!cDom) return; cDom.style.height = ''; var wholeHeight = msgDom.offsetHeight; var contentHeight = msgDom.scrollHeight; // if(contentHeight > wholeHeight && cDom) cDom.style.height = wholeHeight - (56 + 46) + 'px'; }.bind(this); this.resizeFun(); on(window, 'resize', this.resizeFun); } }
messageDialogF.prototype.create = function () { var self = this, closeStr = ''; if (this.hasFooter) { var footerStr = '<div class="u-msg-footer only-one-btn"><button class="u-msg-ok u-button u-button-primary raised">' + this.bthText + '</button></div>' + '</div>'; } var templateStr = this.template.replace('{id}', this.id).replace('{id}', this.id); templateStr = templateStr.replace('{width}', this.width ? 'width:' + this.width + ';' : ''); templateStr = templateStr.replace('{height}', this.height ? 'height:' + this.height + ';' : ''); templateStr = templateStr.replace('{top}', this.top ? 'top:' + this.top + ';' : ''); templateStr = templateStr.replace('{title}', this.title); templateStr = templateStr.replace('{footer}', footerStr); var htmlReg = /^(\s*)?<[a-zA-Z]+/ig; var selectReg = /^(\.|#)/; if(htmlReg.test(this.content)){ this.contentDom= makeDOM(this.content); this.contentDomParent = this.contentDom.parentNode; this.contentDom.style.display = 'block'; }else if(selectReg.test(this.content)){ this.contentDom = document.querySelector(this.content); this.contentDomParent = this.contentDom.parentNode; this.contentDom.style.display = 'block'; }else{ this.contentDom = makeDOM('<p>' + this.content + '</p>'); } this.templateDom = makeDOM(templateStr); this.templateDom.querySelector('.u-msg-content').appendChild(this.contentDom); this.overlayDiv = makeModal(this.templateDom); this.okDiv = this.templateDom.querySelector('.u-msg-ok'); on(this.okDiv, 'click', function() { self.close(); }); if(this.lazyShow) { this.templateDom.style.display = 'none'; this.overlayDiv.style.display = 'none'; } document.body.appendChild(this.templateDom); disable_mouseWheel(); this.isClosed = false; };
setComboData: function (datas, options) { var i, li, self = this; //统一指定datas格式为[{name:"",value:""}]. if (!options) this.comboDatas = datas; else{ this.comboDatas = []; for(var i = 0; i< datas.length; i++){ this.comboDatas.push({name:datas[i][options.name],value:datas[i][options.value]}); } } //将初始数据保留一份,以便input输入内容改变时自动提示的数据从全部数据里头筛选. if(!(this.initialComboData && this.initialComboData.length)){ this.initialComboData = this.comboDatas; } // isAutoTip 可以输入的情况下不清空内容,后续要清空内容需要重点考虑。 // this.value = ''; // this._input.value = ''; //若没有下拉的ul,新生成一个ul结构. if (!this._ul) { this._ul = makeDOM('<ul class="u-combo-ul"></ul>'); } this._ul.innerHTML = ''; //TODO 增加filter for (i = 0; i < this.comboDatas.length; i++) { li = makeDOM('<li class="u-combo-li">' + this.comboDatas[i].name + '</li>');//document.createElement('li'); li._index = i; on(li, 'click', function () { self.selectItem(this._index); }) var rippleContainer = document.createElement('span'); addClass(rippleContainer, 'u-ripple-container'); var _rippleElement = document.createElement('span'); addClass(_rippleElement, 'u-ripple'); rippleContainer.appendChild(_rippleElement); li.appendChild(rippleContainer); new URipple(li); this._ul.appendChild(li); } },
dialogMode.prototype.create = function() { var closeStr = '',oThis = this; if(this.hasCloseMenu) { var closeStr = '<div class="u-msg-close"> <span aria-hidden="true">×</span></div>'; } var templateStr = this.template.replace('{id}', this.id).replace('{id}', this.id); templateStr = templateStr.replace('{close}', closeStr); templateStr = templateStr.replace('{width}', this.width ? 'width:' + this.width + ';' : ''); templateStr = templateStr.replace('{height}', this.height ? 'height:' + this.height + ';' : ''); var htmlReg = /^(\s*)?<[a-zA-Z]+/ig; var selectReg = /^(\.|#)/; if(htmlReg.test(this.content)){ this.contentDom= makeDOM(this.content); this.contentDomParent = this.contentDom.parentNode; this.contentDom.style.display = 'block'; }else if(selectReg.test(this.content)){ this.contentDom = document.querySelector(this.content); this.contentDomParent = this.contentDom.parentNode; this.contentDom.style.display = 'block'; }else{ this.contentDom = makeDOM('<div><div class="u-msg-content"><p>' + this.content + '</p></div></div>'); } this.templateDom = makeDOM(templateStr); this.templateDom.querySelector('.u-msg-dialog-content').appendChild(this.contentDom); this.overlayDiv = makeModal(this.templateDom); if(this.hasCloseMenu) { this.closeDiv = this.templateDom.querySelector('.u-msg-close'); on(this.closeDiv, 'click', function() { oThis.close(); }); } if(this.lazyShow) { this.templateDom.style.display = 'none'; this.overlayDiv.style.display = 'none'; } document.body.appendChild(this.templateDom); disable_mouseWheel(); this.isClosed = false; };
init: function(){ var self = this; var element = this.element; this.options = extend({}, this.DEFAULTS, this.options); this.panelDiv = null; this.input = this.element.querySelector("input"); var d = new Date(); this.year = d.getFullYear(); this.month = d.getMonth() + 1; this.date = d.getDate(); on(this.input, 'blur',function(e){ self._inputFocus = false; self.setValue(self.input.value); }); // 添加focus事件 this.focusEvent(); // 添加右侧图标click事件 this.clickEvent(); },
init: function () { var self = this; this.element = this.element.nodeName === 'INPUT' ? this.element : this.element.querySelector('input'); PhoneNumberAdapter.superclass.init.apply(this); this.validType = 'phone'; this.masker = new PhoneNumberMasker(this.maskerMeta); on(this.element, 'keydown', function(e) { if (self.enable) { var code = e.keyCode ? e.keyCode : e.which ? e.which : e.charCode; if (!((code >= 48 && code <= 57) || (code >= 96 && code <= 105) || code == 37 || code == 39 || code == 8 || code == 46)) { //阻止默认浏览器动作(W3C) if (e && e.preventDefault) e.preventDefault(); //IE中阻止函数器默认动作的方式 else window.event.returnValue = false; return false; } } }); }
init:function(){ var self = this; var element = this.element; this.options = extend({}, this.DEFAULTS, this.options); this.panelDiv = null; this.input = this.element.querySelector("input"); var d = new Date(); this.month = d.getMonth() + 1; this.defaultMonth = this.month; on(this.input, 'blur',function(e){ self._inputFocus = false; this.setValue(this.input.value); }.bind(this)); // 添加focus事件 this.focusEvent(); // 添加右侧图标click事件 this.clickEvent(); // 添加keydown事件 this.keydownEvent(); },
_fillYear: function(type){ var oldPanel,year,template,yearPage,titleDiv,yearDiv, i,cell; oldPanel = this.panelContentDiv.querySelector('.u-date-content-page'); if(oldPanel) this.panelContentDiv.removeChild(oldPanel); template = ['<div class="u-date-content-page">', '<div class="u-date-content-title"></div>', '<div class="u-date-content-panel"></div>', '</div>'].join(""); yearPage = makeDOM(template); titleDiv = yearPage.querySelector('.u-date-content-title'); titleDiv.innerHTML = (this.startYear) + '-' + (this.startYear + 11); yearDiv = yearPage.querySelector('.u-date-content-panel'); for(i = 0; i < 12; i++){ cell = makeDOM('<div class="u-date-content-year-cell">'+ (this.startYear + i) +'</div>'); new URipple(cell); if (this.startYear + i == this.year){ addClass(cell, 'current'); } cell._value = this.startYear + i; yearDiv.appendChild(cell); } var oThis = this; on(yearDiv, 'click', function(e){ var _y = e.target._value; oThis.year = _y; oThis._fillMonth(); stopEvent(e); }); this.preBtn.style.display = 'block'; this.nextBtn.style.display = 'block'; // this._zoomIn(yearPage); this.panelContentDiv.appendChild(yearPage); this.contentPage = yearPage; this.currentPanel = 'year'; },
init:function(){ var self = this; var element = this.element; this.options = extend({}, this.DEFAULTS, this.options); this.panelDiv = null; this.input = this.element.querySelector("input"); var d = new Date(); this.year = d.getFullYear(); this.defaultYear = this.year; this.startYear = this.year - this.year % 10 - 1; on(this.input, 'blur',function(e){ self._inputFocus = false; self.setValue(self.input.value); }); // 添加focus事件 this.focusEvent(); // 添加右侧图标click事件 this.clickEvent(); // 添加keydown事件 this.keydownEvent(); },
init: function () { var self = this; this.element = this.element.nodeName === 'INPUT' ? this.element : this.element.querySelector('input'); if (!this.element){ throw new Error('not found INPUT element, u-meta:' + JSON.stringify(this.options)); }; this.maskerMeta = core.getMaskerMeta('float') || {}; this.validType = 'float'; this.maskerMeta.precision = this.getOption('precision') || this.maskerMeta.precision; this.max = this.getOption('max') ; this.min = this.getOption('min') ; //如果max为false并且不为0 if(!this.max && this.max !== 0) { this.max = "10000000000000000000"; } //如果min为false并且不为0 if(!this.min && this.min !== 0) { this.min = "-10000000000000000000"; } // this.max = this.getOption('max') || "10000000000000000000"; // this.min = this.getOption('min') || "-10000000000000000000"; this.maxNotEq = this.getOption('maxNotEq'); this.minNotEq = this.getOption('minNotEq'); //处理数据精度 this.dataModel.refRowMeta(this.field, "precision").subscribe(function(precision){ if(precision === undefined) return; self.setPrecision(precision) }); this.formater = new NumberFormater(this.maskerMeta.precision); this.masker = new NumberMasker(this.maskerMeta); on(this.element, 'focus', function(){ if(self.enable){ self.onFocusin() try{ var e = event.srcElement; var r = e.createTextRange(); r.moveStart('character',e.value.length); r.collapse(true); r.select(); }catch(e){ } } }) on(this.element, 'blur',function(){ if(self.enable){ if (!self.doValidate() && self._needClean()) { if (self.required && (self.element.value === null || self.element.value === undefined || self.element.value === '')) { // 因必输项清空导致检验没通过的情况 self.setValue('') } else { self.element.value = self.getShowValue() } } else self.setValue(self.element.value) } }); on(this.element,'keydown',function(e){ if(self.enable){ var code = e.keyCode ? e.keyCode : e.which ? e.which : e.charCode; if (!((code >= 48 && code <= 57)|| (code >= 96 && code <= 105)||code==37||code==102||code==39||code==8 ||code==46 || code == 110 || code == 190)) { //阻止默认浏览器动作(W3C) if ( e && e.preventDefault ) e.preventDefault(); //IE中阻止函数器默认动作的方式 else window.event.returnValue = false; return false; } } }) },
if(env.isIE8) sub.style.maxHeight = 0; } if(sub && !open) { addClass(item, this._CssClasses.NAV_LINK_OPEN); if(env.isIE8) sub.style.maxHeight = '999px'; } // sub && open && removeClass(item, this._CssClasses.NAV_LINK_OPEN); // sub && !open && addClass(item, this._CssClasses.NAV_LINK_OPEN); } } }); compMgr.regComp({ comp: NavMenu, compAsString: 'u.NavMenu', css: 'u-navmenu' }); if(document.readyState && document.readyState === 'complete') { compMgr.updateComp(); } else { on(window, 'load', function() { //扫描并生成控件 compMgr.updateComp(); }); } export {NavMenu};
pagination.prototype.render = function() { var a = (new Date()).valueOf(); var options = this.options; if(!options.totalPages) { this.$element.style.display = "none"; return; } else { this.$element.style.display = "block"; } var htmlArr = []; var currentPageProxy = new PageProxy(options, options.currentPage); //update pagination by pengyic@yonyou.com //预设显示页码数 var windows = 2; var total = options.totalPages - 0; var current = options.currentPage - 0; //预设显示页码数截断修正 var fix = 0; var pageProxy; if(current - 2 <= windows + 1) { for(var i = 1; i <= current; i++) { pageProxy = new PageProxy(options, i); htmlArr.push(View.page(this, options, pageProxy)); } fix = windows - (current - 1) < 0 ? 0 : windows - (current - 1); if(total - current - fix <= windows + 1) { for(var i = current + 1; i <= total; i++) { pageProxy = new PageProxy(options, i); htmlArr.push(View.page(this, options, pageProxy)); } } else { for(var i = current + 1; i <= current + windows + fix; i++) { pageProxy = new PageProxy(options, i); htmlArr.push(View.page(this, options, pageProxy)); } //添加分割'...' htmlArr.push(View.gap(this, options)); pageProxy = new PageProxy(options, total); htmlArr.push(View.page(this, options, pageProxy)); } } else { if(total - current <= windows + 1) { fix = windows - (total - current) < 0 ? 0 : windows - (total - current); for(var i = current - windows - fix; i <= total; i++) { pageProxy = new PageProxy(options, i); htmlArr.push(View.page(this, options, pageProxy)); } if(i >= 2) { //添加分割'...' htmlArr.unshift(View.gap(this, options)); pageProxy = new PageProxy(options, 1); htmlArr.unshift(View.page(this, options, pageProxy)); } } else { for(var i = current - windows; i <= current + windows; i++) { pageProxy = new PageProxy(options, i); htmlArr.push(View.page(this, options, pageProxy)); } //添加分割'...' htmlArr.push(View.gap(this, options)); pageProxy = new PageProxy(options, total); htmlArr.push(View.page(this, options, pageProxy)); //添加分割'...' htmlArr.unshift(View.gap(this, options)); pageProxy = new PageProxy(options, 1); htmlArr.unshift(View.page(this, options, pageProxy)); } } htmlArr.unshift(View.prevPage(this, options, currentPageProxy)); htmlArr.push(View.nextPage(this, options, currentPageProxy)); if(options.totalCount === undefined || options.totalCount <= 0) { options.totalCount = 0; } if(options.showState) { // 处理pageOption字符串 var pageOption = ''; options.pageList.forEach(function(item) { if(options.pageSize - 0 == item) { pageOption += '<option selected>' + item + '</option>' } else { pageOption += '<option>' + item + '</option>' } }); var htmlTmp = ''; //分别得到分页条后“共xxx条”、“显示xx条”、“到xx页 确定”三个html片段 if(options.showTotal){ htmlTmp += '<div class="pagination-state">' + options.totalText + ' ' + options.totalCount + ' '+options.listText +'</div>'; } if(options.showColumn){ if( hasClass(this.$ul, 'pagination-sm') ){ htmlTmp += '<div class="pagination-state">' + options.showText + '<select class="page_z page_z_sm">' + pageOption + '</select>'+options.listText +'</div>'; }else if( hasClass(this.$ul, 'pagination-lg')){ htmlTmp += '<div class="pagination-state">' + options.showText + '<select class="page_z page_z_lg">' + pageOption + '</select>'+options.listText +'</div>'; }else{ htmlTmp += '<div class="pagination-state">' + options.showText + '<select class="page_z">' + pageOption + '</select>'+options.listText +'</div>'; } } if(options.showJump){ if( hasClass(this.$ul, 'pagination-sm')){ htmlTmp += '<div class="pagination-state">' + options.toText + '<input class="page_j text-center page_j_sm padding-left-0" value=' + options.currentPage + '>' + options.pageText + '<input class="pagination-jump pagination-jump-sm" type="button" value="'+ options.okText +'"/></div>'; }else if( hasClass(this.$ul, 'pagination-lg')){ htmlTmp += '<div class="pagination-state">' + options.toText + '<input class="page_j text-center page_j_lg padding-left-0" value=' + options.currentPage + '>' + options.pageText + '<input class="pagination-jump pagination-jump-lg" type="button" value="'+ options.okText +'"/></div>'; }else{ htmlTmp += '<div class="pagination-state">' + options.toText + '<input class="page_j text-center padding-left-0" value=' + options.currentPage + '>' + options.pageText + '<input class="pagination-jump" type="button" value="'+ options.okText +'"/></div>'; } } htmlArr.push(htmlTmp); } //在将htmlArr插入到页面之前,对htmlArr进行处理 this.$ul.innerHTML = ""; this.$ul.insertAdjacentHTML('beforeEnd', htmlArr.join('')); var me = this; on(this.$ul.querySelector(".pagination-jump"), "click", function() { var jp, pz; jp = me.$ul.querySelector(".page_j").value || options.currentPage; pz = me.$ul.querySelector(".page_z").value || options.pageSize; if(isNaN(jp))return; //if (pz != options.pageSize){ // me.$element.trigger('sizeChange', [pz, jp - 1]) //}else{ // me.$element.trigger('pageChange', jp - 1) //} me.page(jp, options.totalPages, pz); //me.$element.trigger('pageChange', jp - 1) //me.$element.trigger('sizeChange', pz) return false; }) on(this.$ul.querySelector('[role="first"] a'), 'click', function() { if(options.currentPage <= 1) return; me.firstPage(); //me.$element.trigger('pageChange', 0) return false; }) on(this.$ul.querySelector('[role="prev"] a'), 'click', function() { if(options.currentPage <= 1) return; me.prevPage(); //me.$element.trigger('pageChange', options.currentPage - 1) return false; }) on(this.$ul.querySelector('[role="next"] a'), 'click', function() { if(parseInt(options.currentPage) + 1 > options.totalPages) return; me.nextPage(); //me.$element.trigger('pageChange', parseInt(options.currentPage) + 1) return false; }) on(this.$ul.querySelector('[role="last"] a'), 'click', function() { if(options.currentPage == options.totalPages) return; me.lastPage(); //me.$element.trigger('pageChange', options.totalPages - 1) return false; }) each(this.$ul.querySelectorAll('[role="page"] a'), function(i, node) { on(node, 'click', function() { var pz = (me.$element.querySelector(".page_z") && $(this).val()) || options.pageSize; me.page(parseInt(this.innerHTML), options.totalPages, pz); //me.$element.trigger('pageChange', parseInt($(this).html()) - 1) return false; }) }) on(this.$ul.querySelector('.page_z'), 'change', function() { var pz = (me.$element.querySelector(".page_z") && $(this).val()) || options.pageSize; me.trigger('sizeChange', pz) }) }