diff --git a/dist/fallwall.min.js b/dist/fallwall.min.js index e7d5612..9e01946 100644 --- a/dist/fallwall.min.js +++ b/dist/fallwall.min.js @@ -1,8 +1,8 @@ -"use strict";var _extends=Object.assign||function(r){for(var e=1;e"+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"+r+"",dataArray:n},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+"%"}),t(n,i)},r.fn.loadMoreFw=function(r){if(0!==e.dataArray.length){if(e.currentGrid+1 {\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 +{"version":3,"sources":["fallwall.js"],"names":["root","factory","exports","_typeof","module","require","define","amd","Fallwall","jQuery","window","undefined","$","defaults","gridNumber","columnNumber","defaultClass","_setFirstRoundContent","dataArray","callbackFunction","i","_appendGrids","console","error","obj","thisCode","html_template","j","Object","keys","length","replace","targetColumn","eq","_getShortestColumn","creatingElement","direction","prepend","find","first","last","addClass","heightArray","each","index","element","push","offsetHeight","inArray","Math","min","apply","fn","fallwall_init","template","options","Array","Error","isArray","colElements","display","this","css","vertical-align","width","floor","loadMoreFw","currentGrid","limitNum","data"],"mappings":";;;;;;CAOA,SAAEA,EAAMC,GACY,YAAnB,mBAAOC,SAAP,YAAAC,QAAOD,WAA0C,mBAAXE,QAAyBA,OAAOF,QAAUD,EAAQI,QAAQ,WAC9E,kBAAXC,SAAyBA,OAAOC,IAAMD,QAAQ,UAAWL,GAChED,EAAOA,EAAKQ,SAAWP,EAAQQ,QAC/BC,OAAOF,SAAYP,EAAQQ,SAJ5BE,OAKS,SAACC,GAJT,GAAAC,IADDC,WAKS,GAIPC,aAAc,EAFfC,aAAe,GACdF,YAAY,EACZC,cAUKE,EAAwB,SAAEC,EAAWC,GAE1C,IAAK,GAAIC,GAAI,EAAGA,EAAIP,EAASC,YAFxBG,EAAAA,GAEoCG,IAEvCC,EAAcH,EAAUE,GAAI,QAF9BP,EAASO,YAAWP,CAQnBM,KAGgC,kBAArBA,GADZA,IACCG,QAGKC,M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J,EAA4BA,EAAAK,UAAAY,OAAA,CAE3BT,EAAAA,aAGA,KALD,GAGCR,GAASsD,EAATA,YAAAtD,EAAAC,WAGIM,EAAAP,EAAAsD,YAAA/C,EAAAgD,EAAAhD,IAAA,CANL,IAAIP,EAASK,UAAUE,GA2BpBD,MARFA,KARiC,kBAArBA,GAUbA,IAGAG,QAAU8C,MAAAA,EAAV,uBAGGjD,cAOF,IAxBAE,EAAIF,EAAmBD,UAAAE,GAAA,QACtBP,EAAIsD,YAAOhD,EAuBZC,IAAAgD,EAAA,EADA,MAGDjD,KAED,kBAAAA,GAXIA,IAGAG,QAAQC,MAASJ,EAAjB,uBAGK,YAuBV,MAAA,iBAQEG,EAAAA,GAAAA,UAAiBH,SAAAA,EAAAA,GAElB,GAAA,YAAA,mBAAAkD,GAAA,YAAAlE,QAAAkE,IAhBF,KAAA,IAAAZ,OAAA,mCAAAY,EAAA,kBAOChD,GAAcgD,EAAM,MAEhBlD,IAC6B,kBAArBA,GACVA,IAGAG,QAAQC,MAASJ,EAAjB","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\tdataArray: [],\n\t};\n\n\t/**\n\t * call after initializing Fallwall\n\t * append grids in the zfirst round\n\t */\n\tconst _setFirstRoundContent = ( dataArray, callbackFunction ) => {\n\n\t\tfor( let i = 0; i < defaults.gridNumber; i++ ) {\n\t\t\tif( dataArray[i] ) {\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( callbackFunction ) {\n\t\t\tif( typeof callbackFunction === 'function' ) {\n\t\t\t\tcallbackFunction();\n\t\t\t}\n\t\t\telse {\n\t\t\t\tconsole.error(`${callbackFunction} is not a function`);\n\t\t\t}\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\tconst _appendGrids = ( obj, direction ) => {\n\n\t\tlet thisCode = defaults.html_template;\n\n\t\tfor( let 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\tconst targetColumn = $('.fw_column').eq( _getShortestColumn() );\n\t\tlet 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\tconst _getShortestColumn = () => {\n\n\t\tlet heightArray = [];\n\n\t\t$.each($('.fw_column'), (index, element) => {\n\t\t\theightArray.push( element.offsetHeight );\n\t\t});\n\n\t\treturn $.inArray( Math.min.apply( null, heightArray ), 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 ) {\n\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 = ( callbackFunction ) => {\n\n\t\t/**\n\t\t * fallwall initialization is not yet completed\n\t\t */\n\t\tif( defaults.dataArray.length === 0 ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif( defaults.currentGrid + 1 < defaults.dataArray.length ) {\n\n\t\t\tdefaults.currentGrid++;\n\t\t\tconst limitNum = defaults.currentGrid + defaults.gridNumber;\n\t\t\tfor( let i = defaults.currentGrid; i < limitNum; i++ ) {\n\n\t\t\t\tif( defaults.dataArray[i] ) {\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/**\n\t\t\t\t\t * Data is exhausted before last run in loop\n\t\t\t\t\t */\n\t\t\t\t\tif( callbackFunction ) {\n\t\t\t\t\t\tif( typeof callbackFunction === 'function' ) {\n\t\t\t\t\t\t\tcallbackFunction();\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tconsole.error(`${callbackFunction} is not a function`);\n\t\t\t\t\t\t}\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/**\n\t\t\t\t * it is the last run of this loop\n\t\t\t\t */\n\t\t\t\tif( i === limitNum - 1 ) {\n\t\t\t\t\tif( callbackFunction ) {\n\t\t\t\t\t\tif( typeof callbackFunction === 'function' ) {\n\t\t\t\t\t\t\tcallbackFunction();\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tconsole.error(`${callbackFunction} is not a function`);\n\t\t\t\t\t\t}\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 */\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 = ( data, callbackFunction ) => {\n\n\t\tif( typeof data !== 'object' ) {\n\t\t\tthrow new Error(`First parameter of addFwGrid(): ${data} must be Object`);\n\t\t}\n\n\t\t// Add a new grid\n\t\t_appendGrids( data, 'up' );\n\n\t\tif( callbackFunction ) {\n\t\t\tif( typeof callbackFunction === 'function' ) {\n\t\t\t\tcallbackFunction();\n\t\t\t}\n\t\t\telse {\n\t\t\t\tconsole.error(`${callbackFunction} is not a function`);\n\t\t\t}\n\t\t}\n\n\t};\n\n});\n"]} \ No newline at end of file diff --git a/package.json b/package.json index ff20dde..1c9f59f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fallwall", - "version": "1.2.0", + "version": "1.2.1", "description": "Fallwall.js is a jQuery plugin to make Fall Styles like Pinterest.", "scripts": { "dist": "gulp",