function renderData(data) { var self = this, start, children = [], val, matchVal, i, menu = self.get('menu'); data = self.normalizeData(data); menu.removeChildren(true); if (data && data.length) { start = util.now(); menu.addChildren(data); logger.info('render menu cost: ' + (util.now() - start) + ' ms'); children = menu.get('children'); // make menu item (which textContent is same as input) active val = self.getCurrentValue(); if (self.get('highlightMatchItem')) { for (i = 0; i < children.length; i++) { if (children[i].get('textContent') === val) { children[i].set('highlighted', true); matchVal = true; break; } } } // Whether or not the first row should be highlighted by default. if (!matchVal && self.get('autoHighlightFirst')) { for (i = 0; i < children.length; i++) { if (!children[i].get('disabled')) { children[i].set('highlighted', true); break; } } } self.set('collapsed', false); // after menu is rendered self.fire('afterRenderData'); } else { self.set('collapsed', true); } }
function chooseToday(e) { e.preventDefault(); this.set('clear', false); var today = this.get('value').clone(); today.setTime(util.now()); this.set('value', today); }
var util = require('util'); /** * @class KISSY.Event.Object * @private * KISSY 's base event object for custom and dom event. */ /** * @class KISSY.Event.Object * @private * KISSY 's base event object for custom and dom event. */ function EventObject() { var self = this; self.timeStamp = util.now(); /** * target * @property target * @member KISSY.Event.Object */ /** * target * @property target * @member KISSY.Event.Object */ self.target = undef; /** * currentTarget * @property currentTarget * @member KISSY.Event.Object */ /** * currentTarget * @property currentTarget * @member KISSY.Event.Object */ self.currentTarget = undef; /** * current event type * @property type * @type {String} * @member KISSY.Event.Object */ }
frame: function () { var self = this, prop, end = 1, fx, _propData, _propsData = self._propsData; for (prop in _propsData) { _propData = _propsData[prop]; fx = _propData.fx; fx.frame(); // in case call stop in frame if (self.isRejected() || self.isResolved()) { return; } end &= fx.pos === 1; } var currentTime = util.now(), duration = self.config.duration * 1000, remaining = Math.max(0, self.startTime + duration - currentTime), temp = remaining / duration || 0, percent = 1 - temp; self.defer.notify([self, percent, remaining]); if (end) { // complete 事件只在动画到达最后一帧时才触发 self.stop(end); } },
], function (o) { var key = util.guid('attaches_' + util.now() + '_'); Special[o.name] = { // 统一在 document 上 capture focus/blur 事件,然后模拟冒泡 fire 出来 // 达到和 focusin 一样的效果 focusin -> focus // refer: http://yiminghe.iteye.com/blog/813255 setup: function () { // this maybe document var doc = this.ownerDocument || this; if (!(key in doc)) { doc[key] = 0; } doc[key] += 1; if (doc[key] === 1) { doc.addEventListener(o.fix, handler, true); } }, tearDown: function () { var doc = this.ownerDocument || this; doc[key] -= 1; if (doc[key] === 0) { doc.removeEventListener(o.fix, handler, true); } } }; function handler(event) { var target = event.target; return DomEvent.fire(target, o.name); } }); /*
self.singleTapTimer = setTimeout(function () { DomEvent.fire(target, SINGLE_TAP, { pageX: lastXY.pageX, pageY: lastXY.pageY, which: 1, duration: (util.now() - self.startTime) / 1000 }); }, SINGLE_TAP_DELAY);
it("should cache the connected transport", function() { expect(JSON.parse(localStorage[usedKey])).toEqual({ timestamp: Util.now(), transport: "test", latency: 500 }); expect(localStorage[unusedKey]).toEqual("mock"); });
it("should try the substrategy immediately when cache is stale", function() { localStorage[usedKey] = JSON.stringify({ timestamp: Util.now() - 1801*1000 // default ttl is 1800s }); strategy.connect(0, callback); expect(substrategy.connect).toHaveBeenCalled(); });
getTodayTimeLabel: function () { var self = this; var locale = self.get('locale'); var value = self.get('value'); var dateLocale = value.getLocale(); var today = value.clone(); today.setTime(util.now()); return new DateTimeFormat(locale.dateFormat, dateLocale).format(today); },
beforeEach(function() { startTimestamp = Util.now(); spyOn(Util, "now").andReturn(startTimestamp); strategy.connect(0, callback); Util.now.andReturn(startTimestamp + 3000); jasmine.Clock.tick(3000); });
self.tapHoldTimer = setTimeout(function () { var eventObj = util.mix({ which: 1, duration: (util.now() - e.timeStamp) / 1000 }, self.lastXY); self.tapHoldTimer = 0; self.lastXY = 0; DomEvent.fire(currentTouch.target, HOLD, eventObj); }, TAP_HOLD_DELAY);
beforeEach(function() { startTimestamp = Util.now(); spyOn(Util, "now").andReturn(startTimestamp); runner = strategy.connect(0, callback); runner.forceMinPriority(666); Util.now.andReturn(startTimestamp + 2000); transports.test._callback("error"); Util.now.andReturn(startTimestamp + 2500); });
function getPos(anim, propData) { var t = util.now(), runTime, startTime = anim.startTime, delay = propData.delay, duration = propData.duration; runTime = t - startTime - delay; if (runTime <= 0) { return 0; } else if (runTime >= duration) { return 1; } else { return propData.easing(runTime / duration); } }
beforeEach(function() { startTimestamp = Util.now(); spyOn(Util, "now").andReturn(startTimestamp); strategy.connect(0, callback); Util.now.andReturn(startTimestamp + 1000); transport = Mocks.getTransport(true); transport.name = "test"; substrategy._callback(null, { transport: transport }); });
beforeEach(function() { startTimestamp = Util.now(); spyOn(Util, "now").andReturn(startTimestamp); strategy.connect(0, callback); Util.now.andReturn(startTimestamp + 2000); transport = Mocks.getTransport(true); transport.name = "test"; transport.options = { encrypted: false }; transports.test._callback(null, { transport: transport }); });
return function (anim, fx) { var now = util.now(), deltaTime, value; if (inertia) { deltaTime = now - anim.startTime; // Math.exp(-0.1) -> Math.exp(-999) // big -> small // 1 -> 0 // Math.exp(-0.1) -> Math.exp(-999) // big -> small // 1 -> 0 var frictionFactor = Math.exp(deltaTime * ALPHA); // 1 - e^-t // 1 - e^-t value = parseInt(startScroll + velocity * (1 - frictionFactor) / (0 - THETA), 10); if (value > minScroll && value < maxScroll) { // inertia if (fx.lastValue === value) { fx.pos = 1; return; } fx.lastValue = value; self.set(scrollAxis, value); return; } inertia = 0; velocity = velocity * frictionFactor; // S.log('before bounce value: ' + value); // S.log('before bounce startScroll: ' + value); // S.log('start bounce velocity: ' + velocity); // S.log('before bounce minScroll: ' + minScroll); // S.log('before bounce maxScroll: ' + maxScroll); // S.log('before bounce value: ' + value); // S.log('before bounce startScroll: ' + value); // S.log('start bounce velocity: ' + velocity); // S.log('before bounce minScroll: ' + minScroll); // S.log('before bounce maxScroll: ' + maxScroll); startScroll = value <= minScroll ? minScroll : maxScroll; // S.log('startScroll value: ' + startScroll); // S.log('startScroll value: ' + startScroll); bounceStartTime = now; } else { deltaTime = now - bounceStartTime; // bounce // bounce var theta = deltaTime / ACCELERATION, // long tail hump // t * e^-t powTime = theta * Math.exp(0 - SPRING_TENSION * theta); value = parseInt(velocity * powTime, 10); if (value === 0) { fx.pos = 1; } self.set(scrollAxis, startScroll + value); } };
function createView(self, config) { var view = getViewInstance(self, config); var fromCache = !!view; if (view) { view.set(config); } else { view = self.addChild(config); view.$el.on(ANIMATION_END_EVENT, onViewAnimEnd, view); } view.timeStamp = util.now(); return { view: view, fromCache: fromCache }; }
function setUpConfig(c) { // deep mix,exclude context! var context = c.context; delete c.context; c = util.mix(util.clone(defaultConfig), c, { deep: true }); c.context = context || c; var data, uri, type = c.type, dataType = c.dataType; uri = c.uri = url.parse(url.resolve(locationHref, c.url), true); // see method _getUrlForSend uri.query = {}; if (!('crossDomain' in c)) { c.crossDomain = !(uri.protocol === locationUrl.protocol && uri.host === locationUrl.host); } type = c.type = type.toUpperCase(); c.hasContent = !rnoContent.test(type); if (c.processData && (data = c.data) && typeof data !== 'string') { // normalize to string c.data = querystring.stringify(data, undefined, undefined, c.serializeArray); } // 数据类型处理链,一步步将前面的数据类型转化成最后一个 dataType = c.dataType = util.trim(dataType || '*').split(rspace); if (!('cache' in c) && util.inArray(dataType[0], ['script', 'jsonp'])) { c.cache = false; } if (!c.hasContent) { if (c.data) { util.mix(uri.query, querystring.parse(c.data)); } if (c.cache === false) { uri.query._ksTS = util.now() + '_' + util.guid(); } } return c; }
function setUpConfig(c) { // deep mix,exclude context! var context = c.context; delete c.context; c = util.mix(util.clone(defaultConfig), c, { deep: true }); c.context = context || c; var data, uri, type = c.type, dataType = c.dataType; uri = c.uri = simulatedLocation.resolve(c.url); // see method _getUrlForSend c.uri.setQuery(''); if (!('crossDomain' in c)) { c.crossDomain = !c.uri.isSameOriginAs(simulatedLocation); } type = c.type = type.toUpperCase(); c.hasContent = !rnoContent.test(type); if (c.processData && (data = c.data) && typeof data !== 'string') { // normalize to string c.data = util.param(data, undefined, undefined, c.serializeArray); } // 数据类型处理链,一步步将前面的数据类型转化成最后一个 dataType = c.dataType = util.trim(dataType || '*').split(rspace); if (!('cache' in c) && util.inArray(dataType[0], ['script', 'jsonp'])) { c.cache = false; } if (!c.hasContent) { if (c.data) { uri.query.add(util.unparam(c.data)); } if (c.cache === false) { uri.query.set('_ksTS', (util.now() + '_' + util.guid())); } } return c; }
pause: function () { var self = this; if (self.isRunning()) { // already run time self._runTime = util.now() - self.startTime; self.__totalTime -= self._runTime; Utils.removeRunningAnim(self); Utils.savePausedAnim(self); if (self.__waitTimeout) { clearTimeout(self.__waitTimeout); } else { self.doStop(); } } return self; },
resume: function () { var self = this; if (self.isPaused()) { // adjust time by run time caused by pause self.startTime = util.now() - self._runTime; Utils.removePausedAnim(self); Utils.saveRunningAnim(self); if (self.__waitTimeout) { self.__waitTimeout = setTimeout(function () { self.stop(true); }, self.__totalTime); } else { self.beforeResume(); self.doStart(); } } return self; },
fix: 'blur'}], function(o) { _$jscoverage['/focusin.js'].functionData[1]++; _$jscoverage['/focusin.js'].lineData[15]++; var key = util.guid('attaches_' + util.now() + '_'); _$jscoverage['/focusin.js'].lineData[16]++; Special[o.name] = { setup: function() { _$jscoverage['/focusin.js'].functionData[2]++; _$jscoverage['/focusin.js'].lineData[22]++; var doc = visit1_22_1(this.ownerDocument || this); _$jscoverage['/focusin.js'].lineData[23]++; if (visit2_23_1(!(key in doc))) { _$jscoverage['/focusin.js'].lineData[24]++; doc[key] = 0; } _$jscoverage['/focusin.js'].lineData[26]++; doc[key] += 1; _$jscoverage['/focusin.js'].lineData[27]++; if (visit3_27_1(doc[key] === 1)) { _$jscoverage['/focusin.js'].lineData[28]++; doc.addEventListener(o.fix, handler, true); } }, tearDown: function() { _$jscoverage['/focusin.js'].functionData[3]++; _$jscoverage['/focusin.js'].lineData[33]++; var doc = visit4_33_1(this.ownerDocument || this); _$jscoverage['/focusin.js'].lineData[34]++; doc[key] -= 1; _$jscoverage['/focusin.js'].lineData[35]++; if (visit5_35_1(doc[key] === 0)) { _$jscoverage['/focusin.js'].lineData[36]++; doc.removeEventListener(o.fix, handler, true); } }}; _$jscoverage['/focusin.js'].lineData[41]++; function handler(event) { _$jscoverage['/focusin.js'].functionData[4]++; _$jscoverage['/focusin.js'].lineData[42]++; var target = event.target; _$jscoverage['/focusin.js'].lineData[43]++; return DomEvent.fire(target, o.name); } });
function createView(self, config) { _$jscoverage['/navigation-view.js'].functionData[15]++; _$jscoverage['/navigation-view.js'].lineData[211]++; var view = getViewInstance(self, config); _$jscoverage['/navigation-view.js'].lineData[212]++; var fromCache = !!view; _$jscoverage['/navigation-view.js'].lineData[213]++; if (visit24_213_1(view)) { _$jscoverage['/navigation-view.js'].lineData[214]++; view.set(config); } else { _$jscoverage['/navigation-view.js'].lineData[216]++; view = self.addChild(config); _$jscoverage['/navigation-view.js'].lineData[217]++; view.$el.on(ANIMATION_END_EVENT, onViewAnimEnd, view); } _$jscoverage['/navigation-view.js'].lineData[219]++; view.timeStamp = util.now(); _$jscoverage['/navigation-view.js'].lineData[220]++; return { view: view, fromCache: fromCache}; }
], function (S, require) { var util = require('util'); var Node = require('node'), DD = require('dd'), Base = require('base'); var DDM = DD.DDM, win = S.Env.host, SCROLL_EVENT = '.-ks-dd-scroll' + util.now(), RATE = [ 10, 10 ], ADJUST_DELAY = 100, DIFF = [ 20, 20 ], isWin = util.isWindow; /** * @class KISSY.DD.Plugin.Scroll * @extends KISSY.Base * Scroll plugin to make parent node scroll while dragging. */ /** * @class KISSY.DD.Plugin.Scroll * @extends KISSY.Base * Scroll plugin to make parent node scroll while dragging. */ return Base.extend({ pluginId: 'dd/plugin/scroll', /** * Get container node region. * @private */ getRegion: function (node) { if (isWin(node[0])) { return { width: node.width(), height: node.height() }; } else { return { width: node.outerWidth(), height: node.outerHeight() }; } }, /** * Get container node offset. * @private */ getOffset: function (node) { if (isWin(node[0])) { return { left: node.scrollLeft(), top: node.scrollTop() }; } else { return node.offset(); } }, /** * Get container node scroll. * @private */ getScroll: function (node) { return { left: node.scrollLeft(), top: node.scrollTop() }; }, /** * scroll container node. * @private */ setScroll: function (node, r) { node.scrollLeft(r.left); node.scrollTop(r.top); }, /** * make node not to scroll while this drag object is dragging * @param {KISSY.DD.Draggable} drag * @private */ pluginDestructor: function (drag) { drag.detach(SCROLL_EVENT); }, /** * make node to scroll while this drag object is dragging * @param {KISSY.DD.Draggable} drag * @private */ pluginInitializer: function (drag) { var self = this, node = self.get('node'); var rate = self.get('rate'), diff = self.get('diff'), event, // 目前相对 container 的偏移,container 为 window 时,相对于 viewport dxy, timer = null; // fix https://github.com/kissyteam/kissy/issues/115 // dragDelegate 时 可能一个 dragDelegate对应多个 scroll // check container // fix https://github.com/kissyteam/kissy/issues/115 // dragDelegate 时 可能一个 dragDelegate对应多个 scroll // check container function checkContainer() { if (isWin(node[0])) { return 0; } // 判断 proxyNode,不对 dragNode 做大的改变 // 判断 proxyNode,不对 dragNode 做大的改变 var mousePos = drag.mousePos, r = DDM.region(node); if (!DDM.inRegion(r, mousePos)) { clearTimeout(timer); timer = 0; return 1; } return 0; } function dragging(ev) { // 给调用者的事件,框架不需要处理 // fake 也表示该事件不是因为 mouseover 产生的 if (ev.fake) { return; } if (checkContainer()) { return; } // 更新当前鼠标相对于拖节点的相对位置 // 更新当前鼠标相对于拖节点的相对位置 event = ev; dxy = util.clone(drag.mousePos); var offset = self.getOffset(node); dxy.left -= offset.left; dxy.top -= offset.top; if (!timer) { checkAndScroll(); } } function dragEnd() { clearTimeout(timer); timer = null; } drag.on('drag' + SCROLL_EVENT, dragging); drag.on('dragstart' + SCROLL_EVENT, function () { DDM.cacheWH(node); }); drag.on('dragend' + SCROLL_EVENT, dragEnd); function checkAndScroll() { if (checkContainer()) { return; } var r = self.getRegion(node), nw = r.width, nh = r.height, scroll = self.getScroll(node), origin = util.clone(scroll), diffY = dxy.top - nh, adjust = false; if (diffY >= -diff[1]) { scroll.top += rate[1]; adjust = true; } var diffY2 = dxy.top; if (diffY2 <= diff[1]) { scroll.top -= rate[1]; adjust = true; } var diffX = dxy.left - nw; if (diffX >= -diff[0]) { scroll.left += rate[0]; adjust = true; } var diffX2 = dxy.left; if (diffX2 <= diff[0]) { scroll.left -= rate[0]; adjust = true; } if (adjust) { self.setScroll(node, scroll); timer = setTimeout(checkAndScroll, ADJUST_DELAY); // 不希望更新相对值,特别对于相对 window 时,相对值如果不真正拖放触发的 drag,是不变的, // 不会因为程序 scroll 而改变相对值 // 调整事件,不需要 scroll 监控,达到预期结果:元素随容器的持续不断滚动而自动调整位置. // 不希望更新相对值,特别对于相对 window 时,相对值如果不真正拖放触发的 drag,是不变的, // 不会因为程序 scroll 而改变相对值 // 调整事件,不需要 scroll 监控,达到预期结果:元素随容器的持续不断滚动而自动调整位置. event.fake = true; if (isWin(node[0])) { // 当使 window 自动滚动时,也要使得拖放物体相对文档位置随 scroll 改变 // 而相对 node 容器时,只需 node 容器滚动,拖动物体相对文档位置不需要改变 scroll = self.getScroll(node); event.left += scroll.left - origin.left; event.top += scroll.top - origin.top; } // 容器滚动了,元素也要重新设置 left,top // 容器滚动了,元素也要重新设置 left,top if (drag.get('move')) { drag.get('node').offset(event); } drag.fire('drag', event); } else { timer = null; } } } }, { ATTRS: { /** * node to be scrolled while dragging * @cfg {Window|String|HTMLElement} node */ /** * @ignore */ node: { // value:window:不行,默认值一定是简单对象 valueFn: function () { return Node.one(win); }, setter: function (v) { return Node.one(v); } }, /** * adjust velocity, larger faster * default [10,10] * @cfg {Number[]} rate */ /** * @ignore */ rate: { value: RATE }, /** * the margin to make node scroll, easier to scroll for node if larger. * default [20,20] * @cfg {number[]} diff */ /** * @ignore */ diff: { value: DIFF } } }); });
KISSY.add(function(S, require, exports, module) { _$jscoverage['/constrain.js'].functionData[0]++; _$jscoverage['/constrain.js'].lineData[7]++; var Node = require('node'), Base = require('base'); _$jscoverage['/constrain.js'].lineData[9]++; var util = require('util'); _$jscoverage['/constrain.js'].lineData[10]++; var $ = Node.all, CONSTRAIN_EVENT = '.-ks-constrain' + util.now(), WIN = S.Env.host; _$jscoverage['/constrain.js'].lineData[14]++; function onDragStart(e) { _$jscoverage['/constrain.js'].functionData[1]++; _$jscoverage['/constrain.js'].lineData[15]++; var self = this, drag = e.drag, l, t, lt, dragNode = drag.get('dragNode'), constrain = self.get('constrain'); _$jscoverage['/constrain.js'].lineData[20]++; if (visit1_20_1(constrain)) { _$jscoverage['/constrain.js'].lineData[21]++; if (visit2_21_1(util.isWindow(constrain[0]))) { _$jscoverage['/constrain.js'].lineData[22]++; self.__constrainRegion = { left: l = constrain.scrollLeft(), top: t = constrain.scrollTop(), right: l + constrain.width(), bottom: t + constrain.height()}; } else { _$jscoverage['/constrain.js'].lineData[28]++; if (visit3_28_1(constrain.getDOMNode)) { _$jscoverage['/constrain.js'].lineData[29]++; lt = constrain.offset(); _$jscoverage['/constrain.js'].lineData[30]++; self.__constrainRegion = { left: lt.left, top: lt.top, right: lt.left + constrain.outerWidth(), bottom: lt.top + constrain.outerHeight()}; } else { _$jscoverage['/constrain.js'].lineData[36]++; if (visit4_36_1(util.isPlainObject(constrain))) { _$jscoverage['/constrain.js'].lineData[37]++; self.__constrainRegion = constrain; } } } _$jscoverage['/constrain.js'].lineData[39]++; if (visit5_39_1(self.__constrainRegion)) { _$jscoverage['/constrain.js'].lineData[40]++; self.__constrainRegion.right -= dragNode.outerWidth(); _$jscoverage['/constrain.js'].lineData[41]++; self.__constrainRegion.bottom -= dragNode.outerHeight(); } } } _$jscoverage['/constrain.js'].lineData[46]++; function onDragAlign(e) { _$jscoverage['/constrain.js'].functionData[2]++; _$jscoverage['/constrain.js'].lineData[47]++; var self = this, info = {}, l = e.left, t = e.top, constrain = self.__constrainRegion; _$jscoverage['/constrain.js'].lineData[52]++; if (visit6_52_1(constrain)) { _$jscoverage['/constrain.js'].lineData[53]++; info.left = Math.min(Math.max(constrain.left, l), constrain.right); _$jscoverage['/constrain.js'].lineData[54]++; info.top = Math.min(Math.max(constrain.top, t), constrain.bottom); _$jscoverage['/constrain.js'].lineData[55]++; e.drag.setInternal('actualPos', info); } } _$jscoverage['/constrain.js'].lineData[59]++; function onDragEnd() { _$jscoverage['/constrain.js'].functionData[3]++; _$jscoverage['/constrain.js'].lineData[60]++; this.__constrainRegion = null; } _$jscoverage['/constrain.js'].lineData[68]++; module.exports = Base.extend({ pluginId: 'dd/plugin/constrain', __constrainRegion: null, pluginInitializer: function(drag) { _$jscoverage['/constrain.js'].functionData[4]++; _$jscoverage['/constrain.js'].lineData[80]++; var self = this; _$jscoverage['/constrain.js'].lineData[83]++; drag.on('dragstart' + CONSTRAIN_EVENT, onDragStart, self).on('dragend' + CONSTRAIN_EVENT, onDragEnd, self).on('dragalign' + CONSTRAIN_EVENT, onDragAlign, self); }, pluginDestructor: function(drag) { _$jscoverage['/constrain.js'].functionData[5]++; _$jscoverage['/constrain.js'].lineData[92]++; drag.detach(CONSTRAIN_EVENT, { context: this}); }}, { ATTRS: { constrain: { value: $(WIN), setter: function(v) { _$jscoverage['/constrain.js'].functionData[6]++; _$jscoverage['/constrain.js'].lineData[116]++; if (visit7_116_1(v)) { _$jscoverage['/constrain.js'].lineData[117]++; if (visit8_117_1(v === true)) { _$jscoverage['/constrain.js'].lineData[118]++; return $(WIN); } else { _$jscoverage['/constrain.js'].lineData[119]++; if (visit9_119_1(v.nodeType || visit10_119_2(util.isWindow(v) || visit11_120_1(typeof v === 'string')))) { _$jscoverage['/constrain.js'].lineData[121]++; return $(v); } } } _$jscoverage['/constrain.js'].lineData[124]++; return v; }}}}); });
], function (S, require, exports, module) { /** * @ignore * plugin constrain region for drag and drop * @author yiminghe@gmail.com */ var Base = require('base'); var util = require('util'); var $ = require('node'), CONSTRAIN_EVENT = '.-ks-constrain' + util.now(), WIN = window; function onDragStart(e) { var self = this, drag = e.drag, l, t, lt, dragNode = drag.get('dragNode'), constrain = self.get('constrain'); if (constrain) { if (util.isWindow(constrain[0])) { self.__constrainRegion = { left: l = constrain.scrollLeft(), top: t = constrain.scrollTop(), right: l + constrain.width(), bottom: t + constrain.height() }; } else if (constrain.getDOMNode) { lt = constrain.offset(); self.__constrainRegion = { left: lt.left, top: lt.top, right: lt.left + constrain.outerWidth(), bottom: lt.top + constrain.outerHeight() }; } else if (util.isPlainObject(constrain)) { self.__constrainRegion = constrain; } if (self.__constrainRegion) { self.__constrainRegion.right -= dragNode.outerWidth(); self.__constrainRegion.bottom -= dragNode.outerHeight(); } } } function onDragAlign(e) { var self = this, info = {}, l = e.left, t = e.top, constrain = self.__constrainRegion; if (constrain) { info.left = Math.min(Math.max(constrain.left, l), constrain.right); info.top = Math.min(Math.max(constrain.top, t), constrain.bottom); e.drag.setInternal('actualPos', info); } } function onDragEnd() { this.__constrainRegion = null; } /** * @class KISSY.DD.Plugin.Constrain * @extends KISSY.Base * Constrain plugin to provide ability to constrain draggable to specified region */ /** * @class KISSY.DD.Plugin.Constrain * @extends KISSY.Base * Constrain plugin to provide ability to constrain draggable to specified region */ module.exports = Base.extend({ pluginId: 'dd/plugin/constrain', __constrainRegion: null, /** * start monitoring drag * @param {KISSY.DD.Draggable} drag * @private */ pluginInitializer: function (drag) { var self = this; drag.on('dragstart' + CONSTRAIN_EVENT, onDragStart, self).on('dragend' + CONSTRAIN_EVENT, onDragEnd, self).on('dragalign' + CONSTRAIN_EVENT, onDragAlign, self); }, /** * stop monitoring drag * @param {KISSY.DD.Draggable} drag * @private */ pluginDestructor: function (drag) { drag.detach(CONSTRAIN_EVENT, { context: this }); } }, { ATTRS: { /** * constrained container. * @type {Boolean|HTMLElement|String} * @property constrain */ /** * constrained container. true stands for viewport. * Defaults: true. * @cfg {Boolean|HTMLElement|String} constrain */ /** * @ignore */ constrain: { valueFn: function () { return $(WIN); }, setter: function (v) { if (v) { if (v === true) { return $(WIN); } else if (v.nodeType || util.isWindow(v) || typeof v === 'string') { return $(v); } } return v; } } } }); });
constructor: function (config) { var self = this; self.callSuper(config); var expressInstall = self.get('expressInstall'), swf, html, id, htmlMode = self.get('htmlMode'), flashVars, params = self.get('params'), attrs = self.get('attrs'), doc = self.get('document'), placeHolder = Dom.create('<span>', undefined, doc), elBefore = self.get('elBefore'), installedSrc = self.get('src'), version = self.get('version'); // https://github.com/kissyteam/kissy/issues/663 // must has a id // or else can not callSWF function in ie6-10 id = attrs.id = attrs.id || util.guid('ks-swf-' + (util.now()) + '-'); // 2. flash 插件没有安装 if (!fpv()) { self.set('status', SWF.Status.NOT_INSTALLED); return; } // 3. 已安装,但当前客户端版本低于指定版本时 if (version && !fpvGTE(version)) { self.set('status', SWF.Status.TOO_LOW); // 有 expressInstall 时,将 src 替换为快速安装 if (expressInstall) { installedSrc = expressInstall; // from swfobject if (!('width' in attrs) || (!/%$/.test(attrs.width) && parseInt(attrs.width, 10) < 310)) { attrs.width = '310'; } if (!('height' in attrs) || (!/%$/.test(attrs.height) && parseInt(attrs.height, 10) < 137)) { attrs.height = '137'; } flashVars = params.flashVars = params.flashVars || {}; // location.toString() crash ie6 util.mix(flashVars, { MMredirectURL: location.href, MMplayerType: OLD_IE ? 'ActiveX' : 'PlugIn', MMdoctitle: doc.title.slice(0, 47) + ' - Flash Player Installation' }); } } if (htmlMode === 'full') { html = _stringSWFFull(installedSrc, attrs, params); } else { html = _stringSWFDefault(installedSrc, attrs, params); } // ie 再取 target.innerHTML 属性大写,很多多与属性,等 self.set('html', html); if (elBefore) { Dom.insertBefore(placeHolder, elBefore); } else { Dom.append(placeHolder, self.get('render')); } if ('outerHTML' in placeHolder) { placeHolder.outerHTML = html; } else { placeHolder.parentNode.replaceChild(Dom.create(html), placeHolder); } swf = Dom.get('#' + id, doc); if (htmlMode === 'full') { if (OLD_IE) { self.set('swfObject', swf); } else { self.set('swfObject', swf.parentNode); } } else { self.set('swfObject', swf); } // bug fix: 重新获取对象,否则还是老对象. // 如 入口为 div 如果不重新获取则仍然是 div longzang | 2010/8/9 self.set('el', swf); if (!self.get('status')) { self.set('status', SWF.Status.SUCCESS); } },
function DomEventObject(originalEvent) { _$jscoverage['/base/object.js'].functionData[6]++; _$jscoverage['/base/object.js'].lineData[190]++; var self = this, type = originalEvent.type; _$jscoverage['/base/object.js'].lineData[395]++; DomEventObject.superclass.constructor.call(self); _$jscoverage['/base/object.js'].lineData[397]++; self.originalEvent = originalEvent; _$jscoverage['/base/object.js'].lineData[400]++; var isDefaultPrevented = retFalse; _$jscoverage['/base/object.js'].lineData[401]++; if (visit89_401_1('defaultPrevented' in originalEvent)) { _$jscoverage['/base/object.js'].lineData[402]++; isDefaultPrevented = originalEvent.defaultPrevented ? retTrue : retFalse; } else { _$jscoverage['/base/object.js'].lineData[403]++; if (visit90_403_1('getPreventDefault' in originalEvent)) { _$jscoverage['/base/object.js'].lineData[405]++; isDefaultPrevented = originalEvent.getPreventDefault() ? retTrue : retFalse; } else { _$jscoverage['/base/object.js'].lineData[406]++; if (visit91_406_1('returnValue' in originalEvent)) { _$jscoverage['/base/object.js'].lineData[407]++; isDefaultPrevented = visit92_407_1(originalEvent.returnValue === FALSE) ? retTrue : retFalse; } } } _$jscoverage['/base/object.js'].lineData[410]++; self.isDefaultPrevented = isDefaultPrevented; _$jscoverage['/base/object.js'].lineData[412]++; var fixFns = [], fixFn, l, prop, props = commonProps.concat(); _$jscoverage['/base/object.js'].lineData[418]++; util.each(eventNormalizers, function(normalizer) { _$jscoverage['/base/object.js'].functionData[7]++; _$jscoverage['/base/object.js'].lineData[419]++; if (visit93_419_1(type.match(normalizer.reg))) { _$jscoverage['/base/object.js'].lineData[420]++; props = props.concat(normalizer.props); _$jscoverage['/base/object.js'].lineData[421]++; if (visit94_421_1(normalizer.fix)) { _$jscoverage['/base/object.js'].lineData[422]++; fixFns.push(normalizer.fix); } } _$jscoverage['/base/object.js'].lineData[425]++; return undefined; }); _$jscoverage['/base/object.js'].lineData[428]++; l = props.length; _$jscoverage['/base/object.js'].lineData[431]++; while (l) { _$jscoverage['/base/object.js'].lineData[432]++; prop = props[--l]; _$jscoverage['/base/object.js'].lineData[433]++; self[prop] = originalEvent[prop]; } _$jscoverage['/base/object.js'].lineData[437]++; if (visit95_437_1(!self.target)) { _$jscoverage['/base/object.js'].lineData[438]++; self.target = visit96_438_1(originalEvent.srcElement || DOCUMENT); } _$jscoverage['/base/object.js'].lineData[442]++; if (visit97_442_1(self.target.nodeType === 3)) { _$jscoverage['/base/object.js'].lineData[443]++; self.target = self.target.parentNode; } _$jscoverage['/base/object.js'].lineData[446]++; l = fixFns.length; _$jscoverage['/base/object.js'].lineData[448]++; while (l) { _$jscoverage['/base/object.js'].lineData[449]++; fixFn = fixFns[--l]; _$jscoverage['/base/object.js'].lineData[450]++; fixFn(self, originalEvent); } _$jscoverage['/base/object.js'].lineData[453]++; self.timeStamp = visit98_453_1(originalEvent.timeStamp || util.now()); }
describe("with cached transport, encrypted=" + encrypted, function() { var t0 = Util.now(); beforeEach(function() { cachedStrategy = Mocks.getStrategy(true); localStorage[usedKey] = JSON.stringify({ timestamp: t0, transport: "test", latency: 1000 }); localStorage[unusedKey] = "mock"; }); it("should try the cached strategy first", function() { strategy.connect(0, callback); expect(transports.test.connect).toHaveBeenCalled(); }); it("should report to timeline when using cached strategy", function() { strategy.connect(0, callback); expect(timeline.info).toHaveBeenCalledWith({ cached: true, transport: "test", latency: 1000 }); }); it("should abort the cached transport and not call the substrategy", function() { var runner = strategy.connect(0, callback); runner.abort(); expect(transports.test._abort).toHaveBeenCalled(); expect(substrategy.connect).not.toHaveBeenCalled(); }); describe("on forceMinPriority", function() { it("should force the new priority on the cached strategy", function() { var runner = strategy.connect(0, callback); runner.forceMinPriority(1000); expect(transports.test._forceMinPriority).toHaveBeenCalledWith(1000); }); }); describe("after connecting successfully with the cached transport", function() { var transport; beforeEach(function() { startTimestamp = Util.now(); spyOn(Util, "now").andReturn(startTimestamp); strategy.connect(0, callback); Util.now.andReturn(startTimestamp + 2000); transport = Mocks.getTransport(true); transport.name = "test"; transport.options = { encrypted: false }; transports.test._callback(null, { transport: transport }); }); it("should call back with the transport", function() { expect(callback).toHaveBeenCalledWith(null, { transport: transport }); }); it("should not try the substrategy", function() { expect(substrategy.connect).not.toHaveBeenCalled(); }); it("should cache the connected transport", function() { expect(JSON.parse(localStorage[usedKey])).toEqual({ timestamp: Util.now(), transport: "test", latency: 2000 }); expect(localStorage[unusedKey]).toEqual("mock"); }); }); describe("after double the cached latency + 1s", function() { beforeEach(function() { startTimestamp = Util.now(); spyOn(Util, "now").andReturn(startTimestamp); strategy.connect(0, callback); Util.now.andReturn(startTimestamp + 3000); jasmine.Clock.tick(3000); }); it("should abort the cached strategy", function() { expect(transports.test._abort).toHaveBeenCalled(); }); it("should fall back to the substrategy", function() { expect(substrategy.connect).toHaveBeenCalled(); }); it("should flush the appropriate transport cache", function() { expect(localStorage[usedKey]).toBe(undefined); expect(localStorage[unusedKey]).toEqual("mock"); }); }); describe("after failing to connect with the cached transport", function() { var runner; beforeEach(function() { startTimestamp = Util.now(); spyOn(Util, "now").andReturn(startTimestamp); runner = strategy.connect(0, callback); runner.forceMinPriority(666); Util.now.andReturn(startTimestamp + 2000); transports.test._callback("error"); Util.now.andReturn(startTimestamp + 2500); }); it("should fall back to the substrategy", function() { expect(substrategy.connect).toHaveBeenCalled(); }); it("should flush the appropriate transport cache", function() { expect(localStorage[usedKey]).toBe(undefined); expect(localStorage[unusedKey]).toEqual("mock"); }); it("should abort the substrategy when requested", function() { runner.abort(); expect(cachedStrategy._abort).not.toHaveBeenCalled(); expect(substrategy._abort).toHaveBeenCalled(); }); describe("on forceMinPriority", function() { it("should force the previously set priority on the substrategy", function() { // priority is forced in beforeEach expect(substrategy.connect) .toHaveBeenCalledWith(666, jasmine.any(Function)); }); it("should force the new priority on the substrategy", function() { runner.forceMinPriority(3); expect(substrategy._forceMinPriority).toHaveBeenCalledWith(3); }); }); describe("and connecting successfully using the substrategy", function() { var transport; beforeEach(function() { connection = { name: "test", options: { encrypted: true, "hostEncrypted": "example.net" } }; transport = Mocks.getTransport(true); transport.name = "test"; substrategy._callback(null, { transport: transport }); }); it("should call back with the connection", function() { expect(callback).toHaveBeenCalledWith(null, { transport: transport }); }); it("should cache the connected transport", function() { expect(JSON.parse(localStorage[usedKey])).toEqual({ timestamp: Util.now(), transport: "test", latency: 500 }); expect(localStorage[unusedKey]).toEqual("mock"); }); }); describe("and failing to connect using the substrategy", function() { beforeEach(function() { substrategy._callback("error again"); }); it("should call back with the error", function() { expect(callback).toHaveBeenCalledWith("error again"); }); it("should flush the appropriate transport cache", function() { expect(localStorage[usedKey]).toBe(undefined); expect(localStorage[unusedKey]).toEqual("mock"); }); }); }); });
/** * @ignore * dom-data * @author lifesinger@gmail.com, yiminghe@gmail.com */ var util = require('util'); /*jshint eqeqeq:false*/ // cannot use === for window in ie8 var Dom = require('./api'); var win = window, EXPANDO = '_ks_data_' + util.now(), // 让每一份 kissy 的 expando 都不同 dataCache = {}, // 存储 node 节点的 data winDataCache = {}, // 避免污染全局 // The following elements throw uncatchable exceptions if you // attempt to add expando properties to them. noData = { applet: 1, object: 1, embed: 1 }; var commonOps = { hasData: function (cache, name) { if (cache) { if (name !== undefined) { if (name in cache) { return true; } } else if (!util.isEmptyObject(cache)) { return true; }