webyom / gulp-amd-bundler Goto Github PK
View Code? Open in Web Editor NEWMake an AMD moudle and its relative depended moudles into one file.
License: MIT License
Make an AMD moudle and its relative depended moudles into one file.
License: MIT License
比如有下面这样一个文件,没有写 module.exports
, bundle 的时候不会包上 define
。
这是 Bug 还是规范里要求必须向外提供接口?
'use strict';
var $ = require('jquery');
var UI = require('core');
var rAF = UI.utils.rAF;
/**
* Smooth Scroll
* @param position
* @via http://mir.aculo.us/2014/01/19/scrolling-dom-elements-to-the-top-a-zepto-plugin/
*/
// Usage: $(window).smoothScroll([options])
// only allow one scroll to top operation to be in progress at a time,
// which is probably what you want
var smoothScrollInProgress = false;
$.fn.smoothScroll = function(options) {
options = options || {};
var $this = this,
targetY = parseInt(options.position) || 0,
initialY = $this.scrollTop(),
lastY = initialY,
delta = targetY - initialY,
// duration in ms, make it a bit shorter for short distances
// this is not scientific and you might want to adjust this for
// your preferences
speed = options.speed ||
Math.min(750, Math.min(1500, Math.abs(initialY - targetY))),
// temp variables (t will be a position between 0 and 1, y is the calculated scrollTop)
start, t, y,
cancelScroll = function() {
abort();
};
// abort if already in progress or nothing to scroll
if (smoothScrollInProgress) {
return;
}
if (delta === 0) {
return;
}
// quint ease-in-out smoothing, from
// https://github.com/madrobby/scripty2/blob/master/src/effects/transitions/penner.js#L127-L136
function smooth(pos) {
if ((pos /= 0.5) < 1) {
return 0.5 * Math.pow(pos, 5);
}
return 0.5 * (Math.pow((pos - 2), 5) + 2);
}
function abort() {
$this.off('touchstart.smoothscroll.amui', cancelScroll);
smoothScrollInProgress = false;
}
// when there's a touch detected while scrolling is in progress, abort
// the scrolling (emulates native scrolling behavior)
$this.on('touchstart.smoothscroll.amui', cancelScroll);
smoothScrollInProgress = true;
// start rendering away! note the function given to frame
// is named "render" so we can reference it again further down
rAF(function render(now) {
if (!smoothScrollInProgress) {
return;
}
if (!start) {
start = now;
}
// calculate t, position of animation in [0..1]
t = Math.min(1, Math.max((now - start) / speed, 0));
// calculate the new scrollTop position (don't forget to smooth)
y = Math.round(initialY + delta * smooth(t));
// bracket scrollTop so we're never over-scrolling
if (delta > 0 && y > targetY) y = targetY;
if (delta < 0 && y < targetY) y = targetY;
// only actually set scrollTop if there was a change fromt he last frame
if (lastY != y) $this.scrollTop(y);
lastY = y;
// if we're not done yet, queue up an other frame to render,
// or clean up
if (y !== targetY) {
rAF(render);
} else {
abort();
}
});
};
// Init code
$(document).on('click.smoothScroll.amui', '[data-am-smooth-scroll]',
function(e) {
e.preventDefault();
var options = UI.utils.parseOptions($(this).attr('data-am-smooth-scroll'));
$(window).smoothScroll(options);
});
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.