1(function(factory){ 2 if (typeof define === 'function' && define.amd) { 3 define(['jquery'], factory); 4 } else { 5 factory(window.jQuery || window.Zepto || window.$); 6 }; 7}(function($){ 8 if (typeof Zepto === 'function' || typeof Zepto === 'object') { 9 var ioDim = function(dimension, includeBorder) { 10 return function (includeMargin) { 11 var sides, size, elem; 12 if (this) { 13 elem = this; 14 size = elem[dimension](); 15 sides = { 16 width: ['left', 'right'], 17 height: ['top', 'bottom'] 18 }; 19 sides[dimension].forEach(function(side) { 20 if (!elem.css('box-sizing') || elem.css('box-sizing') === 'content-box') { 21 size += parseInt(elem.css('padding-' + side), 10); 22 if (includeBorder) { 23 size += parseInt(elem.css('border-' + side + '-width'), 10); 24 }; 25 }; 26 if (includeMargin) { 27 size += parseInt(elem.css('margin-' + side), 10); 28 }; 29 }); 30 return size; 31 } else { 32 return null; 33 }; 34 }; 35 }; 36 ['width', 'height'].forEach(function(dimension) { 37 var Dimension = dimension.substr(0,1).toUpperCase() + dimension.substr(1); 38 if (typeof Zepto.fn['inner' + Dimension] === 'undefined') { 39 Zepto.fn['inner' + Dimension] = ioDim(dimension, false); 40 }; 41 if (typeof Zepto.fn['outer' + Dimension] === 'undefined') { 42 Zepto.fn['outer' + Dimension] = ioDim(dimension, true); 43 }; 44 }); 45 }; 46 47 var dialog = { 48 dom: {}, 49 isElement: function(o){ 50 if (o && (typeof HTMLElement === 'function' || typeof HTMLElement === 'object') && o instanceof HTMLElement) { 51 return true; 52 } else { 53 return (o && o.nodeType && o.nodeType === 1) ? true : false; 54 }; 55 }, 56 isJquery: function(o){ 57 return (o && o.length && (typeof jQuery === 'function' || typeof jQuery === 'object') && o instanceof jQuery) ? true : false; 58 }, 59 isZepto: function(o){ 60 return (o && o.length && (typeof Zepto === 'function' || typeof Zepto === 'object') && Zepto.zepto.isZ(o)) ? true : false; 61 } 62 }; 63 64 dialog.init = function(opt, ok, no){ 65 var self = this; 66 67 self.dom.docHtml = $('html'); 68 self.dom.box = $('<div></div>', {'id': 'cxdialog', 'class': 'cxdialog'}); 69 self.dom.overlay = $('<div></div>', {'id': 'cxdialog_overlay', 'class': 'cxdialog_overlay'}); 70 self.dom.holder = $('<div></div>', {'id': 'cxdialog_holder', 'class': 'cxdialog_holder'}); 71 self.dom.title = $('<div></div>', {'class': 'cxdialog_title'}); 72 self.dom.info = $('<div></div>', {'class': 'cxdialog_info'}); 73 self.dom.btns = $('<div></div>', {'class': 'cxdialog_btns'}); 74 self.dom.closeBtn = $('<a></a>', {'rel': 'cxdialog', 'rev': 'close'}); 75 76 $(document).ready(function() { 77 self.dom.box.appendTo('body').after(self.dom.overlay); 78 }); 79 80 self.isIE6 = !!window.ActiveXObject && !window.XMLHttpRequest; 81 82 self.dom.box.on('click', 'a', function(){ 83 var _rel = this.rel; 84 var _rev = this.rev; 85 var _result; 86 87 if (_rel !== 'cxdialog') {return}; 88 89 if (_rev === 'close') { 90 self.exit(); 91 92 } else { 93 for (var i = 0, l = self.btnCache.length; i < l; i++) { 94 if (self.btnCache[i].name === _rev && typeof self.btnCache[i].callback === 'function') { 95 _result = self.btnCache[i].callback(); 96 break; 97 }; 98 }; 99 }; 100 101 if (_result !== false) { 102 self.exit(); 103 }; 104 105 return false; 106 }); 107 }; 108 109 dialog.format = function(opt, ok, no){ 110 var self = this; 111 self.exit(); 112 113 if (typeof opt === 'string' && !opt.length) {return}; 114 115 if (typeof opt === 'string' || self.isElement(opt) || self.isJquery(opt) || self.isZepto(opt)) { 116 opt = { 117 info: opt 118 }; 119 } else if (typeof opt !== 'object') { 120 return; 121 }; 122 123 if (typeof ok === 'function') {opt.ok = ok}; 124 if (typeof no === 'function') {opt.no = no}; 125 126 opt = $.extend({}, $.cxDialog.defaults, opt); 127
128 self.dom.box.attr('class', 'cxdialog'); 129 130 self.setContent(opt); 131 self.show(opt); 132 }; 133 134 dialog.setContent = function(opt){ 135 var self = this; 136 var _timeStamp = new Date().getTime(); 137 138 self.dom.box.empty(); 139 140 if (typeof opt.title === 'string' && opt.title.length) { 141 self.dom.title.html(opt.title).appendTo(self.dom.box); 142 }; 143 144 self.infoCache = undefined; 145 146 if (typeof opt.info === 'string' && opt.info.length) { 147 self.dom.info.html(opt.info).appendTo(self.dom.box); 148 149 } else if (self.isElement(opt.info) || self.isJquery(opt.info) || self.isZepto(opt.info)) { 150 var _cacheDom = self.isElement(opt.info) ? $(opt.info) : opt.info; 151 self.infoCache = { 152 dom: _cacheDom 153 }; 154 155 var _style = _cacheDom.attr('style'); 156 157 if (typeof _style === 'string' && _style.length) { 158 self.infoCache.styleText = _style; 159 }; 160 161 self.dom.holder.css({ 162 'float': _cacheDom.css('float'), 163 'display': _cacheDom.css('display'), 164 'visibility': _cacheDom.css('visibility'), 165 'position': _cacheDom.css('position'), 166 'width': _cacheDom.outerWidth(), 167 'height': _cacheDom.outerHeight() 168 }).insertAfter(_cacheDom); 169 170 _cacheDom.css('display', 'block').appendTo(self.dom.box); 171 172 } else { 173 opt.info = String(opt.info); 174 self.dom.info.html(opt.info).appendTo(self.dom.box); 175 }; 176 177 self.btnCache = []; 178 179 if (typeof opt.ok === 'function') { 180 self.btnCache.push({ 181 name: 'btn_ok', 182 className: 'btn_ok', 183 text: opt.okText, 184 callback: opt.ok 185 }); 186 }; 187 if (typeof opt.no === 'function') { 188 self.btnCache.push({ 189 name: 'btn_no', 190 className: 'btn_no', 191 text: opt.noText, 192 callback: opt.no 193 }); 194 }; 195 196 for (var i = 0, l = opt.buttons.length; i < l; i++) { 197 self.btnCache.push({ 198 name: 'btn_' + _timeStamp + '_' + i, 199 className: 'btn_' + i, 200 text: opt.buttons[i].text, 201 callback: opt.buttons[i].callback 202 }); 203 }; 204 205 if (self.btnCache.length) { 206 var _html = ''; 207 for (var i = 0, l = self.btnCache.length; i < l; i++) { 208 _html += '<a class="' + self.btnCache[i].className + '" rel="cxdialog" rev="' + self.btnCache[i].name + '">' + self.btnCache[i].text + '</a>'; 209 }; 210 self.dom.btns.html(_html).appendTo(self.dom.box); 211 }; 212 213 if (opt.closeBtn) { 214 self.dom.closeBtn.appendTo(self.dom.box); 215 }; 216 }; 217 218 dialog.show = function(opt){ 219 var self = this; 220 221 if (opt.lockScroll === true) { 222 self.dom.docHtml.addClass('cxdialog_lock'); 223 }; 224 225 if (typeof opt.background === 'string') { 226 self.dom.overlay.css('background', opt.background); 227 } else { 228 self.dom.overlay.css('display', 'none'); 229 }; 230 231 if (typeof opt.baseClass === 'string' && opt.baseClass.length) { 232 self.dom.box.addClass(opt.baseClass); 233 }; 234 235 self.dom.box.removeAttr('style'); 236 237 var _cssAttr = {}; 238 239 if (self.isIE6) { 240 _cssAttr.top = document.documentElement.scrollTop + window.screen.availHeight / 4; 241 }; 242 243 if (opt.width > 0) { 244 _cssAttr.width = opt.width; 245 _cssAttr.marginLeft = -(opt.width / 2); 246 } else { 247 _cssAttr.marginLeft = -(self.dom.box.outerWidth() / 2); 248 }; 249 250 if (opt.height > 0) { 251 _cssAttr.height = opt.height; 252 _cssAttr.marginTop = -(opt.height / 2); 253 } else { 254 _cssAttr.marginTop = -(self.dom.box.outerHeight() / 2); 255 }; 256 257 if (opt.zIndex > 0) { 258 _cssAttr.zIndex = opt.zIndex; 259 }; 260 261 self.dom.box.css(_cssAttr).addClass('in'); 262 }; 263 264 dialog.backDom = function(){ 265 var self = this; 266 267 if (self.infoCache && (self.isJquery(self.infoCache.dom) || self.isZepto(self.infoCache.dom))) { 268 if (typeof self.infoCache.styleText === 'string' && self.infoCache.styleText.length) { 269 self.infoCache.dom.attr('style', self.infoCache.styleText); 270 } else { 271 self.infoCache.dom.removeAttr('style'); 272 }; 273 274 self.infoCache.dom.insertAfter(self.dom.holder); 275 276 self.dom.holder.remove(); 277 }; 278 279 self.infoCache = undefined; 280 }; 281 282 dialog.exit = function(){ 283 var self = this; 284 285 self.backDom(); 286 287 self.btnCache = undefined; 288 289 self.dom.box.removeClass('in').addClass('out'); 290 if (typeof $.cxDialog.defaults.background !== 'string') { 291 self.dom.overlay.css('display', ''); 292 };
293 self.dom.docHtml.removeClass('cxdialog_lock'); 294 }; 295 296 $.cxDialog = function(){ 297 dialog.format.apply(dialog, arguments); 298 }; 299 300 $.cxDialog.close = function(){ 301 dialog.exit.apply(dialog); 302 }; 303 304 $.cxDialog.defaults = { 305 title: '', 306 info: '', 307 ok: null, 308 okText: 'ç¡® å®', 309 no: null, 310 noText: 'å æ¶', 311 buttons: [], 312 closeBtn: false, 313 lockScroll: false, 314 baseClass: '', 315 background: '', 316 width: 0, 317 height: 0 318 }; 319 320 dialog.init(); 321}));
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.