From 2709796cf89377e263269a16d325e197c0d70799 Mon Sep 17 00:00:00 2001 From: Eddie Wen Date: Tue, 7 Feb 2017 22:01:20 +0800 Subject: [PATCH] Version 1.3.0 Rename initialize function --- dist/fallwall.min.js | 2 +- dist/fallwall.min.js.map | 2 +- package.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dist/fallwall.min.js b/dist/fallwall.min.js index 9e01946..5f807b3 100644 --- a/dist/fallwall.min.js +++ b/dist/fallwall.min.js @@ -4,5 +4,5 @@ * Copyright © 2017 Eddie Wen | MIT license * https://github.com/EddieWen-Taiwan/Fallwall.js */ -!function(r,e){"object"===("undefined"==typeof exports?"undefined":_typeof(exports))&&"undefined"!=typeof module?module.exports=e(require("jquery")):"function"==typeof define&&define.amd?define(["jquery"],e):r?r.Fallwall=e(jQuery):window.Fallwall=e(jQuery)}(void 0,function(r){var e={gridNumber:20,columnNumber:1,defaultClass:"",currentGrid:0,dataArray:[]},t=function(r,t){for(var o=0;o"+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"+r+"",dataArray:e},t);var f="
".repeat(o.columnNumber);this.append(f),this.find(n.COLUMN).css({"vertical-align":"top",display:"inline-block",width:Math.floor(1e3/o.columnNumber)/10+"%"}),i(e,a)},r.fn.loadMoreFw=function(r){if(0!==o.dataArray.length){if(o.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\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 +{"version":3,"sources":["fallwall.js"],"names":["root","factory","exports","_typeof","module","require","define","amd","Fallwall","jQuery","window","undefined","$","DOWN","UP","GRID","COLUMN","gridNumber","columnNumber","defaultClass","_setFirstRoundContent","dataArray","callbackFunction","i","defaults","_appendGrids","console","error","obj","thisCode","html_template","j","Object","keys","length","replace","targetColumn","className","eq","_getShortestColumn","creatingElement","direction","prepend","find","first","last","addClass","heightArray","each","index","element","push","offsetHeight","indexOf","Math","min","apply","fn","fallwall","template","options","Array","Error","isArray","colElements","repeat","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,SAAWP,EAAQQ,SAJ3BE,OAKS,SAACC,GAJT,GAAAC,GAAOX,OADRY,EAAA,KAOOD,GACNE,KAAMD,WAILE,OAAQ,cAARA,GAFDC,WAAA,GAOCC,aAAc,EAFfC,aAAe,GACdF,YAAY,EACZC,cAUKE,EAAwB,SAAEC,EAAWC,GAE1C,IAAK,GAAIC,GAAI,EAAGA,EAAIC,EAASP,YAFxBG,EAAAA,GAEoCG,IAEvCE,EAAcJ,EAAUE,GAAIV,GAF9BW,EAASD,YAAWC,CAQnBF,KAGgC,kBAArBA,GADZA,IACCI,QAGKC,MAAAL,EAHL,wBAcIG,EAAe,SAAAG,EAAfH,GAIL,IAAK,GAFDI,GAAWL,EAASM,cAEfC,EAAI,EAAGA,EAAIC,OAAOC,KAAKL,GAAKM,OAAQH,IAC5CF,EAAWA,EAASM,QAATN,cAAAE,EAA+BA,GAA/BH,EAAsCA,GAGlD,IAAMQ,GAAiBC,EAAAA,EAAUrB,QAAZsB,GAAwBC,KACzCC,EAAAA,MACAC,KAAc3B,GACjBsB,EAAaM,QAASb,GACtBW,EAAkBJ,EAAaO,KAAKN,EAAUtB,MAAM6B,SAGpDR,IAAqBP,IACrBW,EAAAA,OAAkBJ,GAClB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A,MAGDpD,KAED,kBAAAA,GAXIA,IAGAI,QAAQC,MAASL,EAAjB,uBAGK,YAuBV,MAAA,iBAQEI,EAAAA,GAAAA,UAAiBJ,SAAAA,EAAAA,GAElB,GAAA,YAAA,mBAAAqD,GAAA,YAAAxE,QAAAwE,IAhBF,KAAA,IAAAb,OAAA,mCAAAa,EAAA,kBAOClD,GAAckD,EAAM7D,GAEhBQ,IAC6B,kBAArBA,GACVA,IAGAI,QAAQC,MAASL,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\tconst DOWN = 'down';\n\tconst UP = 'up';\n\n\tconst className = {\n\t\tGRID: '.fw_grid',\n\t\tCOLUMN: '.fw_column',\n\t};\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 = $(className.COLUMN).eq( _getShortestColumn() );\n\t\tlet creatingElement;\n\t\tif( direction === UP ) {\n\t\t\ttargetColumn.prepend( thisCode );\n\t\t\tcreatingElement = targetColumn.find(className.GRID).first();\n\t\t}\n\t\telse if( direction === DOWN ) {\n\t\t\ttargetColumn.append( thisCode );\n\t\t\tcreatingElement = targetColumn.find(className.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($(className.COLUMN), (index, element) => {\n\t\t\theightArray.push( element.offsetHeight );\n\t\t});\n\n\t\treturn heightArray.indexOf( Math.min(...heightArray) );\n\n\t};\n\n\t/**\n\t * Fallwall construtcor\n\t * Setup template and data source\n\t */\n\t$.fn.fallwall = 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) || dataArray.length === 0 ) {\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 = '
'.repeat(defaults.columnNumber);\n\t\tthis.append( colElements );\n\n\t\t// Prepare CSS\n\t\tthis.find(className.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 1c9f59f..e489b04 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fallwall", - "version": "1.2.1", + "version": "1.3.0", "description": "Fallwall.js is a jQuery plugin to make Fall Styles like Pinterest.", "scripts": { "dist": "gulp",