From 87045a0d66660a533ad7bb5b0d925da6c81d979d Mon Sep 17 00:00:00 2001 From: EddieWen-Taiwan Date: Fri, 13 May 2016 20:52:13 +0800 Subject: [PATCH 01/13] copyrgiht and license --- src/fallwall.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/fallwall.js b/src/fallwall.js index d233548..ef0ab78 100644 --- a/src/fallwall.js +++ b/src/fallwall.js @@ -1,8 +1,11 @@ -(function($){ +/*! + * Fallwall.js + * + * Copyright © 2015 Eddie Wen | MIT license + * https://github.com/EddieWen-Taiwan/Fallwall.js + */ - /* ---------------------------- *\ - Fall Style - \* ---------------------------- */ +(function($){ var settings; From 60bc53f49e98b94a123b7612830a4695567f6cbb Mon Sep 17 00:00:00 2001 From: EddieWen-Taiwan Date: Sat, 14 May 2016 00:11:03 +0800 Subject: [PATCH 02/13] Module structure --- src/fallwall.js | 363 +++++++++++++++++++++++++----------------------- 1 file changed, 186 insertions(+), 177 deletions(-) diff --git a/src/fallwall.js b/src/fallwall.js index ef0ab78..1e9c640 100644 --- a/src/fallwall.js +++ b/src/fallwall.js @@ -5,180 +5,189 @@ * https://github.com/EddieWen-Taiwan/Fallwall.js */ -(function($){ - - var settings; - - $.fn.fallwall_init = function( template, dataArray, options, callback_func ) { - - // Required parameters - if( template == null || dataArray == null ) { - throw new Error('You missed some parameters while initializing') - } - - // Store data from user - settings = $.extend({ - gridNumber: 20, - columnNumber: 1, - defaultClass: '', - html_template: `
${template}
`, - dataArray: dataArray, - currentGrid: 0 - }, options); - - // Add columns - var colElements = ''; - for( var i = 0; i < settings.columnNumber; i++ ) { - colElements += '
'; - } - this.append( colElements ); - - // Prepare CSS - this.find('.fw_column').css({ - 'display': 'inline-block', - 'vertical-align': 'top', - 'width': `${100/settings.columnNumber}%` - }); - - // Add grids at first - _setContentAtFirst( dataArray, callback_func ); - - }; - - $.fn.loadMoreFw = function( callback_func ) { - - if( settings.currentGrid +1 < settings.dataArray.length ) { - - settings.currentGrid++; - const limitNum = settings.currentGrid + settings.gridNumber; - for( var i = settings.currentGrid; i < limitNum; i++ ) { - - if( typeof settings.dataArray[i] != "undefined" ) { - - _createGrid( settings.dataArray[i], 'down' ); - settings.currentGrid = i; - - } - else { - // Data is exhausted before last run in loop - if( callback_func ) { - if( typeof callback_func == 'function' ) - callback_func(); - else - console.error(`${callback_func} is not a function`); - } - return "NO_MORE_DATA"; - } - - // Last run in loop - if( i == limitNum-1 ) { - if( callback_func ) { - if( typeof callback_func == 'function' ) - callback_func(); - else - console.error(`${callback_func} is not a function`); - } - return "FINISHED"; - } - - } - - } - - /*** - * There is no more data. - * All is displayed. - ***/ - return "NO_MORE_DATA"; - - }; - - // Directly add a new grid at the top of any column - $.fn.addFwGrid = function( data, callback_func ) { - - if( typeof data == 'object' ) { - // Add a new grid - _createGrid( data, 'up' ); - - if( callback_func ) { - if( typeof callback_func == 'function' ) - callback_func(); - else - console.error(`${callback_func} is not a function`); - } - } - else { - throw new Error(`First parameter of addFwGrid(): ${data} must be Object`); - } - - }; - - function _setContentAtFirst( dataArray, callback_func ) { - - for( var i = 0; i < settings.gridNumber; i++ ) { - if( typeof dataArray[i] != "undefined" ) { - _createGrid( dataArray[i], 'down' ); - settings.currentGrid = i; - } - else { - break; - } - } - - if( callback_func ) { - if( typeof callback_func == 'function' ) - callback_func(); - else - console.error(`${callback_func} is not a function`); - } - - } - - /*** - * - * Add new grid - * direction: up/down => grid is added at the top/bottom - * But keep second parameter - data because of 'addFwGrid()' - * - ***/ - function _createGrid( obj, direction ) { - - var thisCode = settings.html_template; - - for( var j = 0; j < Object.keys(obj).length; j++ ) { - thisCode = thisCode.replace( `fallwall_#${j+1}`, obj[j] ); - } - - const targetColumn = $('.fw_column').eq( _getShortestCol() ); - var creatingElement; - if( direction == 'up' ) { - targetColumn.prepend( thisCode ); - creatingElement = targetColumn.find('.fw_grid').first(); - } - else { - targetColumn.append( thisCode ); - creatingElement = targetColumn.find('.fw_grid').last(); - } - - // Add animation class - if( settings.defaultClass != '' ) { - creatingElement.addClass( settings.defaultClass ); - } - - } - - // Return the shortest '.fw_column' to append a new grid - function _getShortestCol() { - - var heightArray = []; - - $.each( $('.fw_column'), function(index, element) { - heightArray.push( element.offsetHeight ); - }); - - const minColumn = Math.min.apply( null, heightArray ); - return $.inArray( minColumn, heightArray ); - - } - -}(jQuery)); +(function(root, factory) { + 'use strict'; + typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : + typeof define === 'function' && define.amd ? define(factory) : + root.Fallwall = factory() +}(this, function() { + 'use strict'; + +})); +// (function($){ + +// var settings; + +// $.fn.fallwall_init = function( template, dataArray, options, callback_func ) { + +// // Required parameters +// if( template == null || dataArray == null ) { +// throw new Error('You missed some parameters while initializing') +// } + +// // Store data from user +// settings = $.extend({ +// gridNumber: 20, +// columnNumber: 1, +// defaultClass: '', +// html_template: `
${template}
`, +// dataArray: dataArray, +// currentGrid: 0 +// }, options); + +// // Add columns +// var colElements = ''; +// for( var i = 0; i < settings.columnNumber; i++ ) { +// colElements += '
'; +// } +// this.append( colElements ); + +// // Prepare CSS +// this.find('.fw_column').css({ +// 'display': 'inline-block', +// 'vertical-align': 'top', +// 'width': `${100/settings.columnNumber}%` +// }); + +// // Add grids at first +// _setContentAtFirst( dataArray, callback_func ); + +// }; + +// $.fn.loadMoreFw = function( callback_func ) { + +// if( settings.currentGrid +1 < settings.dataArray.length ) { + +// settings.currentGrid++; +// const limitNum = settings.currentGrid + settings.gridNumber; +// for( var i = settings.currentGrid; i < limitNum; i++ ) { + +// if( typeof settings.dataArray[i] != "undefined" ) { + +// _createGrid( settings.dataArray[i], 'down' ); +// settings.currentGrid = i; + +// } +// else { +// // Data is exhausted before last run in loop +// if( callback_func ) { +// if( typeof callback_func == 'function' ) +// callback_func(); +// else +// console.error(`${callback_func} is not a function`); +// } +// return "NO_MORE_DATA"; +// } + +// // Last run in loop +// if( i == limitNum-1 ) { +// if( callback_func ) { +// if( typeof callback_func == 'function' ) +// callback_func(); +// else +// console.error(`${callback_func} is not a function`); +// } +// return "FINISHED"; +// } + +// } + +// } + +// /*** +// * There is no more data. +// * All is displayed. +// ***/ +// return "NO_MORE_DATA"; + +// }; + +// // Directly add a new grid at the top of any column +// $.fn.addFwGrid = function( data, callback_func ) { + +// if( typeof data == 'object' ) { +// // Add a new grid +// _createGrid( data, 'up' ); + +// if( callback_func ) { +// if( typeof callback_func == 'function' ) +// callback_func(); +// else +// console.error(`${callback_func} is not a function`); +// } +// } +// else { +// throw new Error(`First parameter of addFwGrid(): ${data} must be Object`); +// } + +// }; + +// function _setContentAtFirst( dataArray, callback_func ) { + +// for( var i = 0; i < settings.gridNumber; i++ ) { +// if( typeof dataArray[i] != "undefined" ) { +// _createGrid( dataArray[i], 'down' ); +// settings.currentGrid = i; +// } +// else { +// break; +// } +// } + +// if( callback_func ) { +// if( typeof callback_func == 'function' ) +// callback_func(); +// else +// console.error(`${callback_func} is not a function`); +// } + +// } + +// /*** +// * +// * Add new grid +// * direction: up/down => grid is added at the top/bottom +// * But keep second parameter - data because of 'addFwGrid()' +// * +// ***/ +// function _createGrid( obj, direction ) { + +// var thisCode = settings.html_template; + +// for( var j = 0; j < Object.keys(obj).length; j++ ) { +// thisCode = thisCode.replace( `fallwall_#${j+1}`, obj[j] ); +// } + +// const targetColumn = $('.fw_column').eq( _getShortestCol() ); +// var creatingElement; +// if( direction == 'up' ) { +// targetColumn.prepend( thisCode ); +// creatingElement = targetColumn.find('.fw_grid').first(); +// } +// else { +// targetColumn.append( thisCode ); +// creatingElement = targetColumn.find('.fw_grid').last(); +// } + +// // Add animation class +// if( settings.defaultClass != '' ) { +// creatingElement.addClass( settings.defaultClass ); +// } + +// } + +// // Return the shortest '.fw_column' to append a new grid +// function _getShortestCol() { + +// var heightArray = []; + +// $.each( $('.fw_column'), function(index, element) { +// heightArray.push( element.offsetHeight ); +// }); + +// const minColumn = Math.min.apply( null, heightArray ); +// return $.inArray( minColumn, heightArray ); + +// } + +// }(jQuery)); From 12dc01234c401ac74a9f64d52160eaccba8104a9 Mon Sep 17 00:00:00 2001 From: EddieWen-Taiwan Date: Sat, 14 May 2016 00:35:51 +0800 Subject: [PATCH 03/13] Import jQuery --- src/fallwall.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/fallwall.js b/src/fallwall.js index 1e9c640..fe7fa43 100644 --- a/src/fallwall.js +++ b/src/fallwall.js @@ -7,12 +7,16 @@ (function(root, factory) { 'use strict'; - typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : - typeof define === 'function' && define.amd ? define(factory) : - root.Fallwall = factory() -}(this, function() { + typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('jquery')) : + typeof define === 'function' && define.amd ? define(['jquery'], factory) : + root.Fallwall = factory(jQuery) +}(this, function($) { 'use strict'; + $.fn.fallwall_init = function( template, dataArray, options, callback_func ) { + + } + })); // (function($){ From 694d0a5581a4dc1925fe92a52a6237faa2240204 Mon Sep 17 00:00:00 2001 From: EddieWen-Taiwan Date: Sat, 14 May 2016 01:15:20 +0800 Subject: [PATCH 04/13] Move private functions --- src/fallwall.js | 165 ++++++++++++++++++++++++++++-------------------- 1 file changed, 96 insertions(+), 69 deletions(-) diff --git a/src/fallwall.js b/src/fallwall.js index fe7fa43..15000ff 100644 --- a/src/fallwall.js +++ b/src/fallwall.js @@ -13,11 +13,106 @@ }(this, function($) { 'use strict'; + var defaults = { + gridNumber: 20, + columnNumber: 1, + defaultClass: '', + // html_template: `
${template}
`, + // dataArray: dataArray, + currentGrid: 0 + }, + + _setContentAtFirst = function( dataArray, callback_func ) { + + for( var i = 0; i < settings.gridNumber; i++ ) { + if( typeof dataArray[i] != "undefined" ) { + _createGrid( dataArray[i], 'down' ); + settings.currentGrid = i; + } + else { + break; + } + } + + if( callback_func ) { + if( typeof callback_func == 'function' ) + callback_func(); + else + console.error(`${callback_func} is not a function`); + } + + }, + + /** + * Add new grid + * direction: up/down => grid is added at the top/bottom + */ + _createGrid = function( obj, direction ) { + + var thisCode = settings.html_template; + + for( var j = 0; j < Object.keys(obj).length; j++ ) { + thisCode = thisCode.replace( `fallwall_#${j+1}`, obj[j] ); + } + + var targetColumn = $('.fw_column').eq( _getShortestCol() ); + var creatingElement; + if( direction == 'up' ) { + targetColumn.prepend( thisCode ); + creatingElement = targetColumn.find('.fw_grid').first(); + } + else { + targetColumn.append( thisCode ); + creatingElement = targetColumn.find('.fw_grid').last(); + } + + // Add animation class + if( settings.defaultClass != '' ) { + creatingElement.addClass( settings.defaultClass ); + } + + }, + + /** + * Return the shortest fw_column to append a new grid + */ + _getShortestCol = function() { + + var heightArray = []; + + $.each( $('.fw_column'), function(index, element) { + heightArray.push( element.offsetHeight ); + }); + + var minColumn = Math.min.apply( null, heightArray ); + return $.inArray( minColumn, heightArray ); + + }; + + /** + * Fallwall construtcor + * Setup template and data source + */ $.fn.fallwall_init = function( template, dataArray, options, callback_func ) { - } + }; + + /** + * load more data and append them + */ + $.fn.loadMoreFw = function( callback_func ) { + + }; + + /** + * directly append a new grid at the top of one column + */ + $.fn.addFwGrid = function( data, callback_func ) { + + }; })); + // (function($){ // var settings; @@ -126,72 +221,4 @@ // }; -// function _setContentAtFirst( dataArray, callback_func ) { - -// for( var i = 0; i < settings.gridNumber; i++ ) { -// if( typeof dataArray[i] != "undefined" ) { -// _createGrid( dataArray[i], 'down' ); -// settings.currentGrid = i; -// } -// else { -// break; -// } -// } - -// if( callback_func ) { -// if( typeof callback_func == 'function' ) -// callback_func(); -// else -// console.error(`${callback_func} is not a function`); -// } - -// } - -// /*** -// * -// * Add new grid -// * direction: up/down => grid is added at the top/bottom -// * But keep second parameter - data because of 'addFwGrid()' -// * -// ***/ -// function _createGrid( obj, direction ) { - -// var thisCode = settings.html_template; - -// for( var j = 0; j < Object.keys(obj).length; j++ ) { -// thisCode = thisCode.replace( `fallwall_#${j+1}`, obj[j] ); -// } - -// const targetColumn = $('.fw_column').eq( _getShortestCol() ); -// var creatingElement; -// if( direction == 'up' ) { -// targetColumn.prepend( thisCode ); -// creatingElement = targetColumn.find('.fw_grid').first(); -// } -// else { -// targetColumn.append( thisCode ); -// creatingElement = targetColumn.find('.fw_grid').last(); -// } - -// // Add animation class -// if( settings.defaultClass != '' ) { -// creatingElement.addClass( settings.defaultClass ); -// } - -// } - -// // Return the shortest '.fw_column' to append a new grid -// function _getShortestCol() { - -// var heightArray = []; - -// $.each( $('.fw_column'), function(index, element) { -// heightArray.push( element.offsetHeight ); -// }); - -// const minColumn = Math.min.apply( null, heightArray ); -// return $.inArray( minColumn, heightArray ); - -// } - // }(jQuery)); From 935931f4581b15c10b4d16669ec61fe543f3ccc4 Mon Sep 17 00:00:00 2001 From: EddieWen-Taiwan Date: Sat, 14 May 2016 01:36:45 +0800 Subject: [PATCH 05/13] Rename setting variable and rewrite comment --- src/fallwall.js | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/fallwall.js b/src/fallwall.js index 15000ff..bee0f74 100644 --- a/src/fallwall.js +++ b/src/fallwall.js @@ -24,10 +24,10 @@ _setContentAtFirst = function( dataArray, callback_func ) { - for( var i = 0; i < settings.gridNumber; i++ ) { + for( var i = 0; i < defaults.gridNumber; i++ ) { if( typeof dataArray[i] != "undefined" ) { _createGrid( dataArray[i], 'down' ); - settings.currentGrid = i; + defaults.currentGrid = i; } else { break; @@ -38,7 +38,7 @@ if( typeof callback_func == 'function' ) callback_func(); else - console.error(`${callback_func} is not a function`); + console.error(callback_func+' is not a function'); } }, @@ -49,10 +49,10 @@ */ _createGrid = function( obj, direction ) { - var thisCode = settings.html_template; + var thisCode = defaults.html_template; for( var j = 0; j < Object.keys(obj).length; j++ ) { - thisCode = thisCode.replace( `fallwall_#${j+1}`, obj[j] ); + thisCode = thisCode.replace( 'fallwall_#'+(j+1), obj[j] ); } var targetColumn = $('.fw_column').eq( _getShortestCol() ); @@ -66,9 +66,12 @@ creatingElement = targetColumn.find('.fw_grid').last(); } - // Add animation class - if( settings.defaultClass != '' ) { - creatingElement.addClass( settings.defaultClass ); + /** + * Add extra class + * like animation class + */ + if( defaults.defaultClass != '' ) { + creatingElement.addClass( defaults.defaultClass ); } }, @@ -115,8 +118,6 @@ // (function($){ -// var settings; - // $.fn.fallwall_init = function( template, dataArray, options, callback_func ) { // // Required parameters From c273ee3499eaefac1f8148dac79502829fb0022d Mon Sep 17 00:00:00 2001 From: EddieWen-Taiwan Date: Sat, 14 May 2016 01:38:27 +0800 Subject: [PATCH 06/13] Move function : addFwGrid() --- src/fallwall.js | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/src/fallwall.js b/src/fallwall.js index bee0f74..b603678 100644 --- a/src/fallwall.js +++ b/src/fallwall.js @@ -112,6 +112,21 @@ */ $.fn.addFwGrid = function( data, callback_func ) { + if( typeof data == 'object' ) { + // Add a new grid + _createGrid( data, 'up' ); + + if( callback_func ) { + if( typeof callback_func == 'function' ) + callback_func(); + else + console.error(callback_func+' is not a function'); + } + } + else { + throw new Error('First parameter of addFwGrid(): '+data+' must be Object'); + } + }; })); @@ -202,24 +217,4 @@ // }; -// // Directly add a new grid at the top of any column -// $.fn.addFwGrid = function( data, callback_func ) { - -// if( typeof data == 'object' ) { -// // Add a new grid -// _createGrid( data, 'up' ); - -// if( callback_func ) { -// if( typeof callback_func == 'function' ) -// callback_func(); -// else -// console.error(`${callback_func} is not a function`); -// } -// } -// else { -// throw new Error(`First parameter of addFwGrid(): ${data} must be Object`); -// } - -// }; - // }(jQuery)); From d1e56f6814e4143bb2d549c268f3afc32c83ee11 Mon Sep 17 00:00:00 2001 From: EddieWen-Taiwan Date: Sat, 14 May 2016 01:40:12 +0800 Subject: [PATCH 07/13] Move function : loadMoreFw() --- src/fallwall.js | 92 +++++++++++++++++++++++-------------------------- 1 file changed, 44 insertions(+), 48 deletions(-) diff --git a/src/fallwall.js b/src/fallwall.js index b603678..6784724 100644 --- a/src/fallwall.js +++ b/src/fallwall.js @@ -105,6 +105,50 @@ */ $.fn.loadMoreFw = function( callback_func ) { + if( defaults.currentGrid +1 < defaults.dataArray.length ) { + + defaults.currentGrid++; + var limitNum = defaults.currentGrid + defaults.gridNumber; + for( var i = defaults.currentGrid; i < limitNum; i++ ) { + + if( typeof defaults.dataArray[i] != "undefined" ) { + + _createGrid( defaults.dataArray[i], 'down' ); + defaults.currentGrid = i; + + } + else { + // Data is exhausted before last run in loop + if( callback_func ) { + if( typeof callback_func == 'function' ) + callback_func(); + else + console.error(callback_func+' is not a function'); + } + return "NO_MORE_DATA"; + } + + // Last run in loop + if( i == limitNum-1 ) { + if( callback_func ) { + if( typeof callback_func == 'function' ) + callback_func(); + else + console.error(callback_func+' is not a function'); + } + return "FINISHED"; + } + + } + + } + + /*** + * There is no more data. + * All is displayed. + ***/ + return "NO_MORE_DATA"; + }; /** @@ -169,52 +213,4 @@ // }; -// $.fn.loadMoreFw = function( callback_func ) { - -// if( settings.currentGrid +1 < settings.dataArray.length ) { - -// settings.currentGrid++; -// const limitNum = settings.currentGrid + settings.gridNumber; -// for( var i = settings.currentGrid; i < limitNum; i++ ) { - -// if( typeof settings.dataArray[i] != "undefined" ) { - -// _createGrid( settings.dataArray[i], 'down' ); -// settings.currentGrid = i; - -// } -// else { -// // Data is exhausted before last run in loop -// if( callback_func ) { -// if( typeof callback_func == 'function' ) -// callback_func(); -// else -// console.error(`${callback_func} is not a function`); -// } -// return "NO_MORE_DATA"; -// } - -// // Last run in loop -// if( i == limitNum-1 ) { -// if( callback_func ) { -// if( typeof callback_func == 'function' ) -// callback_func(); -// else -// console.error(`${callback_func} is not a function`); -// } -// return "FINISHED"; -// } - -// } - -// } - -// /*** -// * There is no more data. -// * All is displayed. -// ***/ -// return "NO_MORE_DATA"; - -// }; - // }(jQuery)); From 6e5342c93daec9ed4cee62b9f87d1d79c755cee5 Mon Sep 17 00:00:00 2001 From: EddieWen-Taiwan Date: Sat, 14 May 2016 02:01:00 +0800 Subject: [PATCH 08/13] Move function : fallwall_init() --- src/fallwall.js | 78 +++++++++++++++++++++++-------------------------- 1 file changed, 36 insertions(+), 42 deletions(-) diff --git a/src/fallwall.js b/src/fallwall.js index 6784724..2f87496 100644 --- a/src/fallwall.js +++ b/src/fallwall.js @@ -17,8 +17,8 @@ gridNumber: 20, columnNumber: 1, defaultClass: '', - // html_template: `
${template}
`, - // dataArray: dataArray, + html_template: '', + dataArray: null, currentGrid: 0 }, @@ -98,6 +98,40 @@ */ $.fn.fallwall_init = function( template, dataArray, options, callback_func ) { + /** + * check required parameters + */ + if( template == null || dataArray == null ) { + throw new Error('You missed some parameters while initializing'); + } + + // Store data from user + defaults = $.extend({ + gridNumber: 20, + columnNumber: 1, + defaultClass: '', + html_template: '
'+template+'
', + dataArray: dataArray, + currentGrid: 0 + }, options); + + // Add columns + var colElements = ''; + for( var i = 0; i < defaults.columnNumber; i++ ) { + colElements += '
'; + } + this.append( colElements ); + + // Prepare CSS + this.find('.fw_column').css({ + 'display': 'inline-block', + 'vertical-align': 'top', + 'width': (100/defaults.columnNumber)+'%' + }); + + // Add grids at first + _setContentAtFirst( dataArray, callback_func ); + }; /** @@ -174,43 +208,3 @@ }; })); - -// (function($){ - -// $.fn.fallwall_init = function( template, dataArray, options, callback_func ) { - -// // Required parameters -// if( template == null || dataArray == null ) { -// throw new Error('You missed some parameters while initializing') -// } - -// // Store data from user -// settings = $.extend({ -// gridNumber: 20, -// columnNumber: 1, -// defaultClass: '', -// html_template: `
${template}
`, -// dataArray: dataArray, -// currentGrid: 0 -// }, options); - -// // Add columns -// var colElements = ''; -// for( var i = 0; i < settings.columnNumber; i++ ) { -// colElements += '
'; -// } -// this.append( colElements ); - -// // Prepare CSS -// this.find('.fw_column').css({ -// 'display': 'inline-block', -// 'vertical-align': 'top', -// 'width': `${100/settings.columnNumber}%` -// }); - -// // Add grids at first -// _setContentAtFirst( dataArray, callback_func ); - -// }; - -// }(jQuery)); From d50a73c7b3569cabd7f63de1846c5bd460a61a21 Mon Sep 17 00:00:00 2001 From: EddieWen-Taiwan Date: Sat, 14 May 2016 21:21:10 +0800 Subject: [PATCH 09/13] Rename private functions --- src/fallwall.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/fallwall.js b/src/fallwall.js index 2f87496..12c89f3 100644 --- a/src/fallwall.js +++ b/src/fallwall.js @@ -22,11 +22,15 @@ currentGrid: 0 }, - _setContentAtFirst = function( dataArray, callback_func ) { + /** + * call after initializing Fallwall + * append grids in the zfirst round + */ + _setFirstRoundContent = function( dataArray, callback_func ) { for( var i = 0; i < defaults.gridNumber; i++ ) { if( typeof dataArray[i] != "undefined" ) { - _createGrid( dataArray[i], 'down' ); + _appendGrids( dataArray[i], 'down' ); defaults.currentGrid = i; } else { @@ -47,7 +51,7 @@ * Add new grid * direction: up/down => grid is added at the top/bottom */ - _createGrid = function( obj, direction ) { + _appendGrids = function( obj, direction ) { var thisCode = defaults.html_template; @@ -55,7 +59,7 @@ thisCode = thisCode.replace( 'fallwall_#'+(j+1), obj[j] ); } - var targetColumn = $('.fw_column').eq( _getShortestCol() ); + var targetColumn = $('.fw_column').eq( _getShortestColumn() ); var creatingElement; if( direction == 'up' ) { targetColumn.prepend( thisCode ); @@ -79,7 +83,7 @@ /** * Return the shortest fw_column to append a new grid */ - _getShortestCol = function() { + _getShortestColumn = function() { var heightArray = []; @@ -130,7 +134,7 @@ }); // Add grids at first - _setContentAtFirst( dataArray, callback_func ); + _setFirstRoundContent( dataArray, callback_func ); }; @@ -147,7 +151,7 @@ if( typeof defaults.dataArray[i] != "undefined" ) { - _createGrid( defaults.dataArray[i], 'down' ); + _appendGrids( defaults.dataArray[i], 'down' ); defaults.currentGrid = i; } @@ -192,7 +196,7 @@ if( typeof data == 'object' ) { // Add a new grid - _createGrid( data, 'up' ); + _appendGrids( data, 'up' ); if( callback_func ) { if( typeof callback_func == 'function' ) From 508a8dc7dfcb83f4fd65fbfccb38012cc1d58372 Mon Sep 17 00:00:00 2001 From: EddieWen-Taiwan Date: Sat, 14 May 2016 22:46:12 +0800 Subject: [PATCH 10/13] Don't declare default value at first --- src/fallwall.js | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/fallwall.js b/src/fallwall.js index 12c89f3..afe123a 100644 --- a/src/fallwall.js +++ b/src/fallwall.js @@ -13,14 +13,7 @@ }(this, function($) { 'use strict'; - var defaults = { - gridNumber: 20, - columnNumber: 1, - defaultClass: '', - html_template: '', - dataArray: null, - currentGrid: 0 - }, + var defaults = {}, /** * call after initializing Fallwall From cd53e82dd43bc1e4c9a0b2f42897606f9462648b Mon Sep 17 00:00:00 2001 From: EddieWen-Taiwan Date: Sat, 14 May 2016 23:04:38 +0800 Subject: [PATCH 11/13] Minify .js --- build/fallwall.min.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/build/fallwall.min.js b/build/fallwall.min.js index b94de27..83a3f13 100644 --- a/build/fallwall.min.js +++ b/build/fallwall.min.js @@ -1 +1,7 @@ -"use strict";var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(r){return typeof r}:function(r){return r&&"function"==typeof Symbol&&r.constructor===Symbol?"symbol":typeof r};!function(r){function n(r,n){for(var e=0;e"+t+"",dataArray:e,currentGrid:0},i);for(var u="",a=0;a";this.append(u),this.find(".fw_column").css({display:"inline-block","vertical-align":"top",width:100/o.columnNumber+"%"}),n(e,f)},r.fn.loadMoreFw=function(r){if(o.currentGrid+1e;e++){if("undefined"==typeof o.dataArray[e])return r&&("function"==typeof r?r():console.error(r+" is not a function")),"NO_MORE_DATA";if(t(o.dataArray[e],"down"),o.currentGrid=e,e==n-1)return r&&("function"==typeof r?r():console.error(r+" is not a function")),"FINISHED"}}return"NO_MORE_DATA"},r.fn.addFwGrid=function(r,n){if("object"!=("undefined"==typeof r?"undefined":_typeof(r)))throw new Error("First parameter of addFwGrid(): "+r+" must be Object");t(r,"up"),n&&("function"==typeof n?n():console.error(n+" is not a function"))}}(jQuery); \ No newline at end of file +/*! + * Fallwall.js + * + * Copyright © 2015 Eddie Wen | MIT license + * https://github.com/EddieWen-Taiwan/Fallwall.js + */ +!function(r,n){"use strict";"object"==typeof exports&&"undefined"!=typeof module?module.exports=n(require("jquery")):"function"==typeof define&&define.amd?define(["jquery"],n):r.Fallwall=n(jQuery)}(this,function(r){"use strict";var n={},e=function(r,e){for(var i=0;i"+t+"",dataArray:i,currentGrid:0},o);for(var u="",a=0;a";this.append(u),this.find(".fw_column").css({display:"inline-block","vertical-align":"top",width:100/n.columnNumber+"%"}),e(i,f)},r.fn.loadMoreFw=function(r){if(n.currentGrid+1i;i++){if("undefined"==typeof n.dataArray[i])return r&&("function"==typeof r?r():console.error(r+" is not a function")),"NO_MORE_DATA";if(t(n.dataArray[i],"down"),n.currentGrid=i,i==e-1)return r&&("function"==typeof r?r():console.error(r+" is not a function")),"FINISHED"}}return"NO_MORE_DATA"},r.fn.addFwGrid=function(r,n){if("object"!=typeof r)throw new Error("First parameter of addFwGrid(): "+r+" must be Object");t(r,"up"),n&&("function"==typeof n?n():console.error(n+" is not a function"))}}); \ No newline at end of file From a06defd4e469ad18b3e0eaf73ea0a28d93860096 Mon Sep 17 00:00:00 2001 From: EddieWen-Taiwan Date: Sun, 15 May 2016 13:47:13 +0800 Subject: [PATCH 12/13] Update version info --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 217204a..fdfae95 100644 --- a/package.json +++ b/package.json @@ -1,11 +1,12 @@ { "name": "fallwall", - "version": "1.1.4", + "version": "1.2.0", "description": "Fallwall.js is a jQuery plugin to make Fall Styles like Pinterest.", "repository": { "type": "git", "url": "git+https://github.com/EddieWen-Taiwan/Fallwall.js.git" }, + "main": "build/fallwall.min.js", "keywords": [ "fall", "fallwall", From ffd4559a578796650f5b1fbbe0e75c1978e3cdc4 Mon Sep 17 00:00:00 2001 From: EddieWen-Taiwan Date: Sun, 15 May 2016 13:50:13 +0800 Subject: [PATCH 13/13] Add javscript example --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index ef280fd..cb18704 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,13 @@ npm install --save fallwall ~~~ +or + +~~~javascript +// import in your .js file +import 'fallwall'; +~~~ + ---- ### How to