Skip to content

Commit

Permalink
chore: fix build standalone bug
Browse files Browse the repository at this point in the history
  • Loading branch information
06wj committed Jul 18, 2017
1 parent c64c340 commit b9176d6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 99 deletions.
19 changes: 9 additions & 10 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,24 +91,23 @@ var createBuildFormatTask = function(type){

var moduleTypes = ['standalone', 'amd', 'commonjs', 'kissy', 'cmd'];
transformModule.add('standalone', function(metadata){
var head = '(function(window){\n';
var head = '(function(window){\nif(!window.Hilo) window.Hilo = {};\n';
var tail = '\n})(window);';

var module = metadata.moduleName;
var requireModules = metadata.requireClasses;

requireModules.forEach(function(requireModule){
if(requireModule !== 'Hilo'){
head += 'var ' + requireModule + ' = window.Hilo.' + requireModule + ';\n';
}
});

if(module === 'Hilo'){
tail = '\nwindow.Hilo = Hilo;' + tail;
tail = '\nfor(var i in Hilo){window.Hilo[i] = Hilo[i]};' + tail;
}
else{
tail = '\nHilo.' + module + ' = ' + module + ';' + tail;

head += 'var Hilo = window.Hilo;\n';
requireModules.forEach(function(requireModule){
if(requireModule !== 'Hilo'){
head += 'var ' + requireModule + ' = Hilo.' + requireModule + ';\n';
}
});
tail = '\nwindow.Hilo.' + module + ' = ' + module + ';' + tail;
}

return {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@
"sources": {
"dir": "src",
"files": [
"util/browser.js",
"util/util.js",
"core/Hilo.js",
"core/Class.js",
"util/util.js",
"util/browser.js",
"geom/Matrix.js",
"event/EventMixin.js",
"view/Drawable.js",
Expand Down
102 changes: 15 additions & 87 deletions src/core/Hilo.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,28 @@
* Licensed under the MIT License
*/

var win = window, doc = document, docElem = doc.documentElement,
uid = 0;

var hasWarnedDict = {};

/**
* @language=en
* @namespace Hilo The underlying core set of methods.
* @static
* @module hilo/core/Hilo
* @requires hilo/util/browser
* @requires hilo/util/util
*/
/**
* @language=zh
* @namespace Hilo的基础核心方法集合。
* @static
* @module hilo/core/Hilo
* @requires hilo/util/browser
* @requires hilo/util/util
*/
var Hilo = (function(){

var win = window, doc = document, docElem = doc.documentElement,
uid = 0;

var hasWarnedDict = {};
return {
var Hilo = {
/**
* Hilo version
* @type String
Expand Down Expand Up @@ -91,11 +93,7 @@ return {
* @returns {Object} 复制后的对象。
*/
copy: function(target, source, strict){
for(var key in source){
if(!strict || target.hasOwnProperty(key) || target[key] !== undefined){
target[key] = source[key];
}
}
util.copy(target, source, strict);
if(!hasWarnedDict.copy){
hasWarnedDict.copy = true;
console.warn('Hilo.copy has been Deprecated! Use Hilo.util.copy instead.');
Expand All @@ -106,82 +104,14 @@ return {
/**
* @language=en
* Browser feature set includes:
* <ul>
* <li><b>jsVendor</b> - Browser vendors js value CSS prefix. For example: webkit.</li>
* <li><b>cssVendor</b> - Browser vendors css value CSS prefix.</li>
* <li><b>supportTransform</b> - Whether to support CSS Transform transformation.</li>
* <li><b>supportTransform3D</b> - Whether to support CSS Transform 3D transformation.</li>
* <li><b>supportStorage</b> - Whether to support local stores like localStorage.</li>
* <li><b>supportTouch</b> - Whether to support the touch event.</li>
* <li><b>supportCanvas</b> - Whether to support the canvas element.</li>
* </ul>
* @see browser
*/
/**
* @language=zh
* 浏览器特性集合。包括:
* <ul>
* <li><b>jsVendor</b> - 浏览器厂商CSS前缀的js值。比如:webkit。</li>
* <li><b>cssVendor</b> - 浏览器厂商CSS前缀的css值。比如:-webkit-。</li>
* <li><b>supportTransform</b> - 是否支持CSS Transform变换。</li>
* <li><b>supportTransform3D</b> - 是否支持CSS Transform 3D变换。</li>
* <li><b>supportStorage</b> - 是否支持本地存储localStorage。</li>
* <li><b>supportTouch</b> - 是否支持触碰事件。</li>
* <li><b>supportCanvas</b> - 是否支持canvas元素。</li>
* </ul>
* 浏览器特性集合。
* @see browser
*/
browser: (function(){
var ua = navigator.userAgent;
var data = {
iphone: /iphone/i.test(ua),
ipad: /ipad/i.test(ua),
ipod: /ipod/i.test(ua),
ios: /iphone|ipad|ipod/i.test(ua),
android: /android/i.test(ua),
webkit: /webkit/i.test(ua),
chrome: /chrome/i.test(ua),
safari: /safari/i.test(ua),
firefox: /firefox/i.test(ua),
ie: /msie/i.test(ua),
opera: /opera/i.test(ua),
supportTouch: 'ontouchstart' in win,
supportCanvas: doc.createElement('canvas').getContext != null,
supportStorage: false,
supportOrientation: 'orientation' in win,
supportDeviceMotion: 'ondevicemotion' in win
};

//`localStorage` is null or `localStorage.setItem` throws error in some cases (e.g. localStorage is disabled)
try{
var value = 'hilo';
localStorage.setItem(value, value);
localStorage.removeItem(value);
data.supportStorage = true;
}catch(e){}

//vendor prefix
var jsVendor = data.jsVendor = data.webkit ? 'webkit' : data.firefox ? 'webkit' : data.opera ? 'o' : data.ie ? 'ms' : '';
var cssVendor = data.cssVendor = '-' + jsVendor + '-';

//css transform/3d feature dectection
var testElem = doc.createElement('div'), style = testElem.style;
var supportTransform = style[jsVendor + 'Transform'] != undefined;
var supportTransform3D = style[jsVendor + 'Perspective'] != undefined;
if(supportTransform3D){
testElem.id = 'test3d';
style = doc.createElement('style');
style.textContent = '@media ('+ cssVendor +'transform-3d){#test3d{height:3px}}';
doc.head.appendChild(style);

docElem.appendChild(testElem);
supportTransform3D = testElem.offsetHeight == 3;
doc.head.removeChild(style);
docElem.removeChild(testElem);
}
data.supportTransform = supportTransform;
data.supportTransform3D = supportTransform3D;

return data;
})(),
browser: browser,

/**
* @language=en
Expand Down Expand Up @@ -465,6 +395,4 @@ return {
+ 'rotate' + str3d + (use3d ? '(0, 0, 1, ' : '(') + obj.rotation + 'deg)'
+ 'scale' + str3d + '(' + obj.scaleX + ', ' + obj.scaleY + (use3d ? ', 1)' : ')');
}
};

})();
};

0 comments on commit b9176d6

Please sign in to comment.