Skip to content

Commit

Permalink
move require-js examples
Browse files Browse the repository at this point in the history
fix requirejs module definition
  • Loading branch information
desandro committed Apr 7, 2015
1 parent 04f83ce commit 2dfc5ab
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ components/
bower_components/
node_modules/
npm-debug.log
**/browserify/bundle.js
examples/**/bundle.js
47 changes: 21 additions & 26 deletions examples/cells-by-row.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,29 @@
* CellsByRow example
*/

( function( window ) {
( function( window, factory ) {
'use strict';

if ( typeof define == 'function' && define.amd ) {
// AMD
define( [
'../outlayer'
],
factory );
} else if ( typeof exports === 'object' ) {
module.exports = factory(
require('../outlayer')
);
} else {
// browser global
window.CellsByRow = factory(
window.Outlayer
);
}

}( window, function factory( Outlayer) {
'use strict';

function cellsByRowDefinition( Outlayer ) {

var CellsByRow = Outlayer.create( 'cellsByRow', {
columnWidth: 100,
rowHeight: 100
Expand Down Expand Up @@ -63,26 +80,4 @@ CellsByRow.prototype._getContainerSize = function() {

return CellsByRow;

}

// -------------------------- transport -------------------------- //


if ( typeof define === 'function' && define.amd ) {
// AMD
define( [
'../outlayer'
],
cellsByRowDefinition );
} else if ( typeof exports === 'object' ) {
module.exports = cellsByRowDefinition(
require('../outlayer')
);
} else {
// browser global
window.CellsByRow = cellsByRowDefinition(
window.Outlayer
);
}

})( window );
}));
6 changes: 2 additions & 4 deletions examples/require-js.js → examples/requirejs/main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
requirejs.config({
baseUrl: '../bower_components'
baseUrl: '../../bower_components'
// OR
// paths: {
// eventie: 'bower_components/eventie',
Expand All @@ -11,8 +11,6 @@ requirejs.config({
// }
});

requirejs( [ '../outlayer', '../examples/cells-by-row' ], function( Outlayer, CellsByRow ) {

requirejs( [ '../examples/cells-by-row' ], function( CellsByRow ) {
new CellsByRow( document.querySelector('#basic') );

});
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

<title>require js</title>

<link rel="stylesheet" href="examples.css" />
<script data-main="require-js" src="//cdnjs.cloudflare.com/ajax/libs/require.js/2.1.5/require.js"></script>
<link rel="stylesheet" href="../examples.css" />
<script data-main="main" src="//cdnjs.cloudflare.com/ajax/libs/require.js/2.1.5/require.js"></script>

</head>
<body>
Expand Down
2 changes: 1 addition & 1 deletion item.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
'fizzy-ui-utils/utils'
],
function( EventEmitter, getSize, getStyleProperty, utils ) {
factory( window, EventEmitter, getSize, getStyleProperty, utils );
return factory( window, EventEmitter, getSize, getStyleProperty, utils );
}
);
} else if (typeof exports === 'object') {
Expand Down
7 changes: 3 additions & 4 deletions outlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,20 @@
'use strict';
// universal module definition

if ( typeof define === 'function' && define.amd ) {
if ( typeof define == 'function' && define.amd ) {
// AMD
define( [
window,
'eventie/eventie',
'eventEmitter/EventEmitter',
'get-size/get-size',
'fizzy-ui-utils/utils',
'./item'
],
function( eventie, EventEmitter, getSize, utils, Item ) {
factory( window, eventie, EventEmitter, getSize, utils, Item);
return factory( window, eventie, EventEmitter, getSize, utils, Item);
}
);
} else if ( typeof exports === 'object' ) {
} else if ( typeof exports == 'object' ) {
// CommonJS
module.exports = factory(
window,
Expand Down

0 comments on commit 2dfc5ab

Please sign in to comment.