diff --git a/dist/fallwall.min.js b/dist/fallwall.min.js index 426130e..e7d5612 100644 --- a/dist/fallwall.min.js +++ b/dist/fallwall.min.js @@ -1,8 +1,8 @@ -"use strict";var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};/*! +"use strict";var _extends=Object.assign||function(r){for(var e=1;e"+t+"",dataArray:o,currentGrid:0},i);for(var u="",d=0;d";this.append(u),this.find(".fw_column").css({display:"inline-block","vertical-align":"top",width:100/n.columnNumber+"%"}),r(o,f)},e.fn.loadMoreFw=function(e){if(n.currentGrid+1"+r+"",dataArray:t},o);for(var f="",a=0;a";this.append(f),this.find(".fw_column").css({"vertical-align":"top",display:"inline-block",width:Math.floor(1e3/e.columnNumber)/10+"%"}),n(t,i)},r.fn.loadMoreFw=function(r){if(e.currentGrid+1 grid is added at the top/bottom\n\t */\n\t_appendGrids = function( obj, direction ) {\n\n\t\tvar thisCode = defaults.html_template;\n\n\t\tfor( var j = 0; j < Object.keys(obj).length; j++ ) {\n\t\t\tthisCode = thisCode.replace( 'fallwall_#'+(j+1), obj[j] );\n\t\t}\n\n\t\tvar targetColumn = $('.fw_column').eq( _getShortestColumn() );\n\t\tvar creatingElement;\n\t\tif( direction == 'up' ) {\n\t\t\ttargetColumn.prepend( thisCode );\n\t\t\tcreatingElement = targetColumn.find('.fw_grid').first();\n\t\t}\n\t\telse {\n\t\t\ttargetColumn.append( thisCode );\n\t\t\tcreatingElement = targetColumn.find('.fw_grid').last();\n\t\t}\n\n\t\t/**\n\t\t * Add extra class\n\t\t * like animation class\n\t\t */\n\t\tif( defaults.defaultClass != '' ) {\n\t\t\tcreatingElement.addClass( defaults.defaultClass );\n\t\t}\n\n\t},\n\n\t/**\n\t * Return the shortest fw_column to append a new grid\n\t */\n\t_getShortestColumn = function() {\n\n\t\tvar heightArray = [];\n\n\t\t$.each( $('.fw_column'), function(index, element) {\n\t\t\theightArray.push( element.offsetHeight );\n\t\t});\n\n\t\tvar minColumn = Math.min.apply( null, heightArray );\n\t\treturn $.inArray( minColumn, heightArray );\n\n\t};\n\n\t/**\n\t * Fallwall construtcor\n\t * Setup template and data source\n\t */\n\t$.fn.fallwall_init = function( template, dataArray, options, callback_func ) {\n\n\t\t/**\n\t\t * check required parameters\n\t\t */\n\t\tif( template == null || dataArray == null ) {\n\t\t\tthrow new Error('You missed some parameters while initializing');\n\t\t}\n\n\t\t// Store data from user\n\t\tdefaults = $.extend({\n\t\t\tgridNumber: 20,\n\t\t\tcolumnNumber: 1,\n\t\t\tdefaultClass: '',\n\t\t\thtml_template: '
'+template+'
',\n\t\t\tdataArray: dataArray,\n\t\t\tcurrentGrid: 0\n\t\t}, options);\n\n\t\t// Add columns\n\t\tvar colElements = '';\n\t\tfor( var i = 0; i < defaults.columnNumber; i++ ) {\n\t\t\tcolElements += '
';\n\t\t}\n\t\tthis.append( colElements );\n\n\t\t// Prepare CSS\n\t\tthis.find('.fw_column').css({\n\t\t\t'display': 'inline-block',\n\t\t\t'vertical-align': 'top',\n\t\t\t'width': (100/defaults.columnNumber)+'%'\n\t\t});\n\n\t\t// Add grids at first\n\t\t_setFirstRoundContent( dataArray, callback_func );\n\n\t};\n\n\t/**\n\t * load more data and append them\n\t */\n\t$.fn.loadMoreFw = function( callback_func ) {\n\n\t\tif( defaults.currentGrid +1 < defaults.dataArray.length ) {\n\n\t\t\tdefaults.currentGrid++;\n\t\t\tvar limitNum = defaults.currentGrid + defaults.gridNumber;\n\t\t\tfor( var i = defaults.currentGrid; i < limitNum; i++ ) {\n\n\t\t\t\tif( typeof defaults.dataArray[i] != \"undefined\" ) {\n\n\t\t\t\t\t_appendGrids( defaults.dataArray[i], 'down' );\n\t\t\t\t\tdefaults.currentGrid = i;\n\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\t// Data is exhausted before last run in loop\n\t\t\t\t\tif( callback_func ) {\n\t\t\t\t\t\tif( typeof callback_func == 'function' )\n\t\t\t\t\t\t\tcallback_func();\n\t\t\t\t\t\telse\n\t\t\t\t\t\t\tconsole.error(callback_func+' is not a function');\n\t\t\t\t\t}\n\t\t\t\t\treturn \"NO_MORE_DATA\";\n\t\t\t\t}\n\n\t\t\t\t// Last run in loop\n\t\t\t\tif( i == limitNum-1 ) {\n\t\t\t\t\tif( callback_func ) {\n\t\t\t\t\t\tif( typeof callback_func == 'function' )\n\t\t\t\t\t\t\tcallback_func();\n\t\t\t\t\t\telse\n\t\t\t\t\t\t\tconsole.error(callback_func+' is not a function');\n\t\t\t\t\t}\n\t\t\t\t\treturn \"FINISHED\";\n\t\t\t\t}\n\n\t\t\t}\n\n\t\t}\n\n\t\t/***\n\t\t * There is no more data.\n\t\t * All is displayed.\n\t\t***/\n\t\treturn \"NO_MORE_DATA\";\n\n\t};\n\n\t/**\n\t * directly append a new grid at the top of one column\n\t */\n\t$.fn.addFwGrid = function( data, callback_func ) {\n\n\t\tif( typeof data == 'object' ) {\n\t\t\t// Add a new grid\n\t\t\t_appendGrids( data, 'up' );\n\n\t\t\tif( callback_func ) {\n\t\t\t\tif( typeof callback_func == 'function' )\n\t\t\t\t\tcallback_func();\n\t\t\t\telse\n\t\t\t\t\tconsole.error(callback_func+' is not a function');\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tthrow new Error('First parameter of addFwGrid(): '+data+' must be Object');\n\t\t}\n\n\t};\n\n}));\n"]} \ No newline at end of file +{"version":3,"sources":["fallwall.js"],"names":["root","factory","exports","_typeof","module","require","define","amd","Fallwall","jQuery","window","undefined","$","defaults","gridNumber","columnNumber","defaultClass","_setFirstRoundContent","dataArray","callback_func","i","_appendGrids","console","error","obj","direction","thisCode","html_template","replace","length","j","creatingElement","eq","_getShortestColumn","prepend","targetColumn","find","first","append","last","addClass","each","index","element","heightArray","push","offsetHeight","minColumn","Math","min","apply","inArray","fn","fallwall_init","template","options","callbackFunction","log","this","Array","Error","isArray","colElements","display","css","vertical-align","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QC,MAAMJ,EAAc","file":"fallwall.min.js","sourcesContent":["/*!\n * Fallwall.js\n *\n * Copyright © 2017 Eddie Wen | MIT license\n * https://github.com/EddieWen-Taiwan/Fallwall.js\n */\n\n((root, factory) => {\n\ttypeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('jquery')) :\n\ttypeof define === 'function' && define.amd ? define(['jquery'], factory) :\n\troot ? root.Fallwall = factory(jQuery) :\n\twindow.Fallwall = factory(jQuery)\n})(this, ($) => {\n\n\tlet defaults = {\n\t\tgridNumber: 20,\n\t\tcolumnNumber: 1,\n\t\tdefaultClass: '',\n\t\tcurrentGrid: 0,\n\t};\n\n\t/**\n\t * call after initializing Fallwall\n\t * append grids in the zfirst round\n\t */\n\tconst _setFirstRoundContent = function( dataArray, callback_func ) {\n\n\t\tfor( var i = 0; i < defaults.gridNumber; i++ ) {\n\t\t\tif( typeof dataArray[i] != \"undefined\" ) {\n\t\t\t\t_appendGrids( dataArray[i], 'down' );\n\t\t\t\tdefaults.currentGrid = i;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\tif( callback_func ) {\n\t\t\tif( typeof callback_func == 'function' )\n\t\t\t\tcallback_func();\n\t\t\telse\n\t\t\t\tconsole.error(callback_func+' is not a function');\n\t\t}\n\n\t},\n\n\t/**\n\t * Add new grid\n\t * direction: up/down => grid is added at the top/bottom\n\t */\n\t_appendGrids = function( obj, direction ) {\n\n\t\tvar thisCode = defaults.html_template;\n\n\t\tfor( var j = 0; j < Object.keys(obj).length; j++ ) {\n\t\t\tthisCode = thisCode.replace( 'fallwall_#'+(j+1), obj[j] );\n\t\t}\n\n\t\tvar targetColumn = $('.fw_column').eq( _getShortestColumn() );\n\t\tvar creatingElement;\n\t\tif( direction == 'up' ) {\n\t\t\ttargetColumn.prepend( thisCode );\n\t\t\tcreatingElement = targetColumn.find('.fw_grid').first();\n\t\t}\n\t\telse {\n\t\t\ttargetColumn.append( thisCode );\n\t\t\tcreatingElement = targetColumn.find('.fw_grid').last();\n\t\t}\n\n\t\t/**\n\t\t * Add extra class\n\t\t * like animation class\n\t\t */\n\t\tif( defaults.defaultClass != '' ) {\n\t\t\tcreatingElement.addClass( defaults.defaultClass );\n\t\t}\n\n\t},\n\n\t/**\n\t * Return the shortest fw_column to append a new grid\n\t */\n\t_getShortestColumn = function() {\n\n\t\tvar heightArray = [];\n\n\t\t$.each( $('.fw_column'), function(index, element) {\n\t\t\theightArray.push( element.offsetHeight );\n\t\t});\n\n\t\tvar minColumn = Math.min.apply( null, heightArray );\n\t\treturn $.inArray( minColumn, heightArray );\n\n\t};\n\n\t/**\n\t * Fallwall construtcor\n\t * Setup template and data source\n\t */\n\t$.fn.fallwall_init = function( template, dataArray, options, callbackFunction ) {\nconsole.log(this);\n\t\t/**\n\t\t * check required parameters\n\t\t */\n\t\tif( !template ) {\n\t\t\tthrow new Error('missed HTML template');\n\t\t}\n\n\t\tif( !dataArray ) {\n\t\t\tthrow new Error('missed data source');\n\t\t}\n\t\tif( !Array.isArray(dataArray) ) {\n\t\t\tthrow new Error('typeof dataArray is not correct');\n\t\t}\n\n\t\t// Store data from user\n\t\tdefaults = {\n\t\t\t...defaults,\n\t\t\thtml_template: `
${template}
`,\n\t\t\tdataArray: dataArray,\n\t\t\t...options,\n\t\t};\n\n\t\t// Add columns\n\t\tlet colElements = '';\n\t\tfor( let i = 0; i < defaults.columnNumber; i++ ) {\n\t\t\tcolElements += '
';\n\t\t}\n\t\tthis.append( colElements );\n\n\t\t// Prepare CSS\n\t\tthis.find('.fw_column').css({\n\t\t\t'vertical-align': 'top',\n\t\t\tdisplay: 'inline-block',\n\t\t\twidth: `${Math.floor(1000/defaults.columnNumber)/10}%`,\n\t\t});\n\n\t\t// Add grids at first\n\t\t_setFirstRoundContent( dataArray, callbackFunction );\n\n\t};\n\n\t/**\n\t * load more data and append them\n\t */\n\t$.fn.loadMoreFw = function( callback_func ) {\n\n\t\tif( defaults.currentGrid +1 < defaults.dataArray.length ) {\n\n\t\t\tdefaults.currentGrid++;\n\t\t\tvar limitNum = defaults.currentGrid + defaults.gridNumber;\n\t\t\tfor( var i = defaults.currentGrid; i < limitNum; i++ ) {\n\n\t\t\t\tif( typeof defaults.dataArray[i] != \"undefined\" ) {\n\n\t\t\t\t\t_appendGrids( defaults.dataArray[i], 'down' );\n\t\t\t\t\tdefaults.currentGrid = i;\n\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\t// Data is exhausted before last run in loop\n\t\t\t\t\tif( callback_func ) {\n\t\t\t\t\t\tif( typeof callback_func == 'function' )\n\t\t\t\t\t\t\tcallback_func();\n\t\t\t\t\t\telse\n\t\t\t\t\t\t\tconsole.error(callback_func+' is not a function');\n\t\t\t\t\t}\n\t\t\t\t\treturn \"NO_MORE_DATA\";\n\t\t\t\t}\n\n\t\t\t\t// Last run in loop\n\t\t\t\tif( i == limitNum-1 ) {\n\t\t\t\t\tif( callback_func ) {\n\t\t\t\t\t\tif( typeof callback_func == 'function' )\n\t\t\t\t\t\t\tcallback_func();\n\t\t\t\t\t\telse\n\t\t\t\t\t\t\tconsole.error(callback_func+' is not a function');\n\t\t\t\t\t}\n\t\t\t\t\treturn \"FINISHED\";\n\t\t\t\t}\n\n\t\t\t}\n\n\t\t}\n\n\t\t/***\n\t\t * There is no more data.\n\t\t * All is displayed.\n\t\t***/\n\t\treturn \"NO_MORE_DATA\";\n\n\t};\n\n\t/**\n\t * directly append a new grid at the top of one column\n\t */\n\t$.fn.addFwGrid = function( data, callback_func ) {\n\n\t\tif( typeof data == 'object' ) {\n\t\t\t// Add a new grid\n\t\t\t_appendGrids( data, 'up' );\n\n\t\t\tif( callback_func ) {\n\t\t\t\tif( typeof callback_func == 'function' )\n\t\t\t\t\tcallback_func();\n\t\t\t\telse\n\t\t\t\t\tconsole.error(callback_func+' is not a function');\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tthrow new Error('First parameter of addFwGrid(): '+data+' must be Object');\n\t\t}\n\n\t};\n\n});\n"]} \ No newline at end of file diff --git a/src/fallwall.js b/src/fallwall.js index 3f4b4f8..7f2037f 100644 --- a/src/fallwall.js +++ b/src/fallwall.js @@ -97,7 +97,7 @@ * Fallwall construtcor * Setup template and data source */ - $.fn.fallwall_init = ( template, dataArray, options, callbackFunction ) => { + $.fn.fallwall_init = function( template, dataArray, options, callbackFunction ) { /** * check required parameters