From 457b6cb079905a5802356b7da00711fc223b079e Mon Sep 17 00:00:00 2001 From: Ruochen Date: Thu, 18 Jun 2015 16:55:29 +0800 Subject: [PATCH] fix umd bug --- Gruntfile.coffee | 2 +- lib/stack.js | 39 ++++++++++++++------------------------- src/stack.coffee | 4 ++-- styles/stack.css | 13 ++++--------- styles/stack.scss | 14 ++++---------- umd.hbs | 16 +++++++--------- 6 files changed, 32 insertions(+), 56 deletions(-) diff --git a/Gruntfile.coffee b/Gruntfile.coffee index b8a9670..ee6a066 100644 --- a/Gruntfile.coffee +++ b/Gruntfile.coffee @@ -49,7 +49,7 @@ module.exports = (grunt) -> watch: scripts: files: ['src/*.coffee', 'demo/**/*.coffee'] - tasks: ['coffee'] + tasks: ['coffee', 'umd'] style: files: ['styles/*.scss', 'demo/**/*.scss'] tasks: ['sass'] diff --git a/lib/stack.js b/lib/stack.js index ab610bf..68405c0 100644 --- a/lib/stack.js +++ b/lib/stack.js @@ -1,35 +1,26 @@ (function (root, factory) { if (typeof define === 'function' && define.amd) { - // AMD. Register as an anonymous module. - define('simple-stack', ["jquery", - "simple-module", - "simple-pjax", - "simple-url"], function ($, SimpleModule, simplePjax, simpleUrl) { - return (root.returnExportsGlobal = factory($, SimpleModule, simplePjax, simpleUrl)); + // AMD. Register as an anonymous module unless amdModuleId is set + define('simple-stack', ["jquery","simple-module","simple-pjax","simple-url"], function (a0,b1,c2,d3) { + return (root['stack'] = factory(a0,b1,c2,d3)); }); } else if (typeof exports === 'object') { // Node. Does not work with strict CommonJS, but - // only CommonJS-like enviroments that support module.exports, + // only CommonJS-like environments that support module.exports, // like Node. - module.exports = factory(require("jquery"), - require("simple-module"), - require("simple-pjax"), - require("simple-url")); + module.exports = factory(require("jquery"),require("simple-module"),require("simple-pjax"),require("simple-url")); } else { root.simple = root.simple || {}; - root.simple['stack'] = factory(jQuery, - SimpleModule, - simple.pjax, - simple.url); + root.simple['stack'] = factory(jQuery,SimpleModule,simple.pjax,simple.url); } }(this, function ($, SimpleModule, simplePjax, simpleUrl) { var Stack, stack, - __hasProp = {}.hasOwnProperty, - __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; + extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, + hasProp = {}.hasOwnProperty; -Stack = (function(_super) { - __extends(Stack, _super); +Stack = (function(superClass) { + extend(Stack, superClass); function Stack() { return Stack.__super__.constructor.apply(this, arguments); @@ -225,7 +216,7 @@ Stack = (function(_super) { }; Stack.prototype.load = function(url, opts) { - var $link, $page, $parent, $prevPage, i, page, pageUrl, pjax, prevPage, prevPageName, _i, _len, _ref; + var $link, $page, $parent, $prevPage, i, j, len, page, pageUrl, pjax, prevPage, prevPageName, ref; if (opts == null) { opts = {}; } @@ -261,9 +252,9 @@ Stack = (function(_super) { if (this.currentPage.unload() === false) { return false; } - _ref = this.stack; - for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) { - page = _ref[i]; + ref = this.stack; + for (i = j = 0, len = ref.length; j < len; i = ++j) { + page = ref[i]; if (page === this.currentPage) { continue; } @@ -331,5 +322,3 @@ stack.clearCache = Stack.clearCache; return stack; })); - - diff --git a/src/stack.coffee b/src/stack.coffee index 1eb8e2a..ab2b6ac 100644 --- a/src/stack.coffee +++ b/src/stack.coffee @@ -81,7 +81,7 @@ class Stack extends SimpleModule state = e.originalEvent.state return unless state - if @currentPage + if @currentPage if @triggerHandler('pageunload', [@currentPage.el.children().first(), @currentPage.getCache()]) == false return @@ -208,7 +208,7 @@ class Stack extends SimpleModule return false if @currentPage.unload() == false - $link = $('', + $link = $('', 'class': 'link-page-behind' 'data-stack': '' href: simpleUrl().toString('relative') diff --git a/styles/stack.css b/styles/stack.css index 7977672..e034a37 100644 --- a/styles/stack.css +++ b/styles/stack.css @@ -9,7 +9,7 @@ clear: both; } .simple-stack .page { - width: 960px; + width: 100%; min-height: 600px; border: 1px solid #dbdfd6; box-shadow: 0 0 5px rgba(0, 0, 0, 0.15); @@ -46,11 +46,6 @@ .simple-stack .page > a.link-page-behind:hover { background: #ffffff; } -.simple-stack .page.transition-start { - /*opacity: 0;*/ - /*transform: scale(1.05);*/ - /*-webkit-transform: scale(1.05);*/ -} .simple-stack .page.page-root.page-behind { top: 2px; } @@ -144,8 +139,8 @@ background: none; } .simple-stack.simple-stack-transition .page { - transition-property: top, margin-top, opacity, transform, box-shadow, border-color; - transition-duration: 200ms; - -webkit-transition-property: top, margin-top, opacity, -webkit-transform, box-shadow, border-color; + -webkit-transition-property: top, margin-top, opacity, -webkit-transform, box-shadow; -webkit-transition-duration: 200ms; + transition-property: top, margin-top, opacity, transform, box-shadow; + transition-duration: 200ms; } diff --git a/styles/stack.scss b/styles/stack.scss index 963962e..baed07a 100644 --- a/styles/stack.scss +++ b/styles/stack.scss @@ -15,7 +15,7 @@ $stack-header-height: 46px; } .page { - width: 960px; + width: 100%; min-height: 600px; border: 1px solid #dbdfd6; box-shadow: 0 0 5px rgba(0,0,0,0.15); @@ -56,12 +56,6 @@ $stack-header-height: 46px; } } - &.transition-start { - /*opacity: 0;*/ - /*transform: scale(1.05);*/ - /*-webkit-transform: scale(1.05);*/ - } - &.page-root.page-behind { top: 2px; } @@ -91,10 +85,10 @@ $stack-header-height: 46px; } &.simple-stack-transition .page { - transition-property: top, margin-top, opacity, transform, box-shadow, border-color; - transition-duration: 200ms; - -webkit-transition-property: top, margin-top, opacity, -webkit-transform, box-shadow, border-color; + -webkit-transition-property: top, margin-top, opacity, -webkit-transform, box-shadow; -webkit-transition-duration: 200ms; + transition-property: top, margin-top, opacity, transform, box-shadow; + transition-duration: 200ms; } } diff --git a/umd.hbs b/umd.hbs index d59bee5..1cf155d 100644 --- a/umd.hbs +++ b/umd.hbs @@ -1,25 +1,23 @@ (function (root, factory) { if (typeof define === 'function' && define.amd) { - // AMD. Register as an anonymous module. - define({{#if amdModuleId}}'{{amdModuleId}}', {{/if}}[{{{amdDependencies}}}], function ({{dependencies}}) { - return (root.returnExportsGlobal = factory({{dependencies}})); + // AMD. Register as an anonymous module unless amdModuleId is set + define({{#if amdModuleId}}'{{amdModuleId}}', {{/if}}[{{{amdDependencies.wrapped}}}], function ({{{amdDependencies.params}}}) { + return ({{#if objectToExport}}root['{{{objectToExport}}}'] = {{/if}}factory({{{amdDependencies.params}}})); }); } else if (typeof exports === 'object') { // Node. Does not work with strict CommonJS, but - // only CommonJS-like enviroments that support module.exports, + // only CommonJS-like environments that support module.exports, // like Node. - module.exports = factory({{{cjsDependencies}}}); + module.exports = factory({{{cjsDependencies.wrapped}}}); } else { root.simple = root.simple || {}; - {{#if globalAlias}}root.simple['{{{globalAlias}}}'] = {{else}}{{#if objectToExport}}root['{{{objectToExport}}}'] = {{/if}}{{/if}}factory({{{globalDependencies}}}); + {{#if globalAlias}}root.simple['{{{globalAlias}}}'] = {{else}}{{#if objectToExport}}root['{{{objectToExport}}}'] = {{/if}}{{/if}}factory({{{globalDependencies.normal}}}); } }(this, function ({{dependencies}}) { {{{code}}} {{#if objectToExport}} -{{indent}}return {{{objectToExport}}}; +return {{{objectToExport}}}; {{/if}} })); - -