bricklayer
Advanced tools
Comparing version 0.4.0 to 0.4.1
{ | ||
"name": "bricklayer", | ||
"version": "0.4.0", | ||
"version": "0.4.1", | ||
"authors": [ | ||
@@ -5,0 +5,0 @@ "Adem İlter <ademilter@gmail.com>", |
@@ -94,5 +94,5 @@ var __extends = (this && this.__extends) || function (d, b) { | ||
}; | ||
Container.prototype.redraw = function (columnCount) { | ||
if (columnCount === void 0) { columnCount = this.columnCount; } | ||
this.reorderElements(columnCount); | ||
Container.prototype.redraw = function () { | ||
this.checkColumnCount(false); | ||
this.reorderElements(this.columnCount); | ||
}; | ||
@@ -131,6 +131,9 @@ Container.prototype.destroy = function () { | ||
}; | ||
Container.prototype.checkColumnCount = function () { | ||
Container.prototype.checkColumnCount = function (publish) { | ||
if (publish === void 0) { publish = true; } | ||
var columnCount = this.getColumnCount(); | ||
if (this.columnCount !== columnCount) { | ||
triggerEvent(this.element, "bricklayer.breakpoint", { columnCount: columnCount }); | ||
if (publish) { | ||
triggerEvent(this.element, "bricklayer.breakpoint", { columnCount: columnCount }); | ||
} | ||
this.columnCount = columnCount; | ||
@@ -137,0 +140,0 @@ } |
@@ -95,5 +95,5 @@ (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | ||
}; | ||
Container.prototype.redraw = function (columnCount) { | ||
if (columnCount === void 0) { columnCount = this.columnCount; } | ||
this.reorderElements(columnCount); | ||
Container.prototype.redraw = function () { | ||
this.checkColumnCount(false); | ||
this.reorderElements(this.columnCount); | ||
}; | ||
@@ -132,6 +132,9 @@ Container.prototype.destroy = function () { | ||
}; | ||
Container.prototype.checkColumnCount = function () { | ||
Container.prototype.checkColumnCount = function (publish) { | ||
if (publish === void 0) { publish = true; } | ||
var columnCount = this.getColumnCount(); | ||
if (this.columnCount !== columnCount) { | ||
triggerEvent(this.element, "bricklayer.breakpoint", { columnCount: columnCount }); | ||
if (publish) { | ||
triggerEvent(this.element, "bricklayer.breakpoint", { columnCount: columnCount }); | ||
} | ||
this.columnCount = columnCount; | ||
@@ -138,0 +141,0 @@ } |
@@ -1,1 +0,1 @@ | ||
!function t(e,n,r){function o(s,u){if(!n[s]){if(!e[s]){var l="function"==typeof require&&require;if(!u&&l)return l(s,!0);if(i)return i(s,!0);var p=new Error("Cannot find module '"+s+"'");throw p.code="MODULE_NOT_FOUND",p}var a=n[s]={exports:{}};e[s][0].call(a.exports,function(t){var n=e[s][1][t];return o(n?n:t)},a,a.exports,t,e,n,r)}return n[s].exports}for(var i="function"==typeof require&&require,s=0;s<r.length;s++)o(r[s]);return o}({1:[function(t,e,n){var r,o=this&&this.__extends||function(t,e){function n(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)};!function(t){function e(t){return[].slice.call(t)}function n(t,e,n){if(window.CustomEvent)var r=new CustomEvent(e,{detail:n});else{var r=document.createEvent("CustomEvent");r.initCustomEvent(e,!0,!0,n)}return t.dispatchEvent(r)}var r={rulerClassName:"bricklayer-column-sizer",columnClassName:"bricklayer-column"},i=function(){function t(t){this.element=document.createElement("div"),this.element.className=t}return t.prototype.destroy=function(){this.element.parentNode.removeChild(this.element)},t}(),s=function(t){function e(){t.apply(this,arguments)}return o(e,t),e.prototype.getWidth=function(){this.element.setAttribute("style","\n display: block;\n visibility: hidden !important;\n top: -1000px !important;\n ");var t=this.element.offsetWidth;return this.element.removeAttribute("style"),t},e}(i),u=function(t){function e(){t.apply(this,arguments)}return o(e,t),e}(i),l=function(){function t(t,e){void 0===e&&(e=r),this.element=t,this.options=e,this.build(),this.buildResponsive()}return t.prototype.append=function(t){var n=this;if(Array.isArray(t))return void t.forEach(function(t){return n.append(t)});var r=this.findMinHeightColumn();this.elements=e(this.elements).concat([t]),this.applyPosition("append",r,t)},t.prototype.prepend=function(t){var n=this;if(Array.isArray(t))return void t.forEach(function(t){return n.prepend(t)});var r=this.findMinHeightColumn();this.elements=[t].concat(e(this.elements)),this.applyPosition("prepend",r,t)},t.prototype.on=function(t,e){return this.element.addEventListener("bricklayer."+t,e),this},t.prototype.redraw=function(t){void 0===t&&(t=this.columnCount),this.reorderElements(t)},t.prototype.destroy=function(){var t=this;this.ruler.destroy(),e(this.elements).forEach(function(e){return t.element.appendChild(e)}),e(this.getColumns()).forEach(function(t){return t.parentNode.removeChild(t)})},t.prototype.build=function(){this.ruler=new s(this.options.rulerClassName),this.elements=this.getElementsInOrder(),this.element.insertBefore(this.ruler.element,this.element.firstChild)},t.prototype.buildResponsive=function(){var t=this;window.addEventListener("resize",function(e){return t.checkColumnCount()}),this.checkColumnCount(),this.on("breakpoint",function(e){return t.reorderElements(e.detail.columnCount)}),this.columnCount>=1&&this.reorderElements(this.columnCount)},t.prototype.getColumns=function(){return this.element.querySelectorAll(":scope > ."+this.options.columnClassName)},t.prototype.findMinHeightColumn=function(){var t=e(this.getColumns()),n=t.map(function(t){return t.offsetHeight}),r=Math.min.apply(null,n);return t[n.indexOf(r)]},t.prototype.getElementsInOrder=function(){return this.element.querySelectorAll(":scope > *:not(."+this.options.columnClassName+"):not(."+this.options.rulerClassName+")")},t.prototype.checkColumnCount=function(){var t=this.getColumnCount();this.columnCount!==t&&(n(this.element,"bricklayer.breakpoint",{columnCount:t}),this.columnCount=t)},t.prototype.reorderElements=function(t){var n=this;void 0===t&&(t=1),(t==1/0||1>t)&&(t=1);for(var r=e(this.elements).map(function(t){var e=t.parentNode?t.parentNode.removeChild(t):t;return e}),o=this.getColumns(),i=0;i<o.length;i++)o[i].parentNode.removeChild(o[i]);for(var i=0;t>i;i++){var s=new u(this.options.columnClassName).element;this.element.appendChild(s)}r.forEach(function(t){var e=n.findMinHeightColumn();e.appendChild(t)})},t.prototype.getColumnCount=function(){var t=this.element.offsetWidth,e=this.ruler.getWidth();return Math.round(t/e)},t.prototype.applyPosition=function(t,e,r){var o=this,i=function(i){var s=i+t.charAt(0).toUpperCase()+t.substr(1);n(o.element,"bricklayer."+s,{item:r,column:e})};switch(i("before"),t){case"append":e.appendChild(r);break;case"prepend":e.insertBefore(r,e.firstChild)}i("after")},t}();t.Container=l}(r||(r={})),function(t,n){"function"==typeof define&&define.amd?define(function(){return n()}):"undefined"!=typeof window&&t===window?t.Bricklayer=n():"object"==typeof e&&e.exports&&(e.exports=n())}("undefined"!=typeof window?window:this,function(){return r.Container})},{}]},{},[1]); | ||
!function t(e,n,o){function r(s,u){if(!n[s]){if(!e[s]){var l="function"==typeof require&&require;if(!u&&l)return l(s,!0);if(i)return i(s,!0);var p=new Error("Cannot find module '"+s+"'");throw p.code="MODULE_NOT_FOUND",p}var a=n[s]={exports:{}};e[s][0].call(a.exports,function(t){var n=e[s][1][t];return r(n?n:t)},a,a.exports,t,e,n,o)}return n[s].exports}for(var i="function"==typeof require&&require,s=0;s<o.length;s++)r(o[s]);return r}({1:[function(t,e,n){var o,r=this&&this.__extends||function(t,e){function n(){this.constructor=t}for(var o in e)e.hasOwnProperty(o)&&(t[o]=e[o]);t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)};!function(t){function e(t){return[].slice.call(t)}function n(t,e,n){if(window.CustomEvent)var o=new CustomEvent(e,{detail:n});else{var o=document.createEvent("CustomEvent");o.initCustomEvent(e,!0,!0,n)}return t.dispatchEvent(o)}var o={rulerClassName:"bricklayer-column-sizer",columnClassName:"bricklayer-column"},i=function(){function t(t){this.element=document.createElement("div"),this.element.className=t}return t.prototype.destroy=function(){this.element.parentNode.removeChild(this.element)},t}(),s=function(t){function e(){t.apply(this,arguments)}return r(e,t),e.prototype.getWidth=function(){this.element.setAttribute("style","\n display: block;\n visibility: hidden !important;\n top: -1000px !important;\n ");var t=this.element.offsetWidth;return this.element.removeAttribute("style"),t},e}(i),u=function(t){function e(){t.apply(this,arguments)}return r(e,t),e}(i),l=function(){function t(t,e){void 0===e&&(e=o),this.element=t,this.options=e,this.build(),this.buildResponsive()}return t.prototype.append=function(t){var n=this;if(Array.isArray(t))return void t.forEach(function(t){return n.append(t)});var o=this.findMinHeightColumn();this.elements=e(this.elements).concat([t]),this.applyPosition("append",o,t)},t.prototype.prepend=function(t){var n=this;if(Array.isArray(t))return void t.forEach(function(t){return n.prepend(t)});var o=this.findMinHeightColumn();this.elements=[t].concat(e(this.elements)),this.applyPosition("prepend",o,t)},t.prototype.on=function(t,e){return this.element.addEventListener("bricklayer."+t,e),this},t.prototype.redraw=function(){this.checkColumnCount(!1),this.reorderElements(this.columnCount)},t.prototype.destroy=function(){var t=this;this.ruler.destroy(),e(this.elements).forEach(function(e){return t.element.appendChild(e)}),e(this.getColumns()).forEach(function(t){return t.parentNode.removeChild(t)})},t.prototype.build=function(){this.ruler=new s(this.options.rulerClassName),this.elements=this.getElementsInOrder(),this.element.insertBefore(this.ruler.element,this.element.firstChild)},t.prototype.buildResponsive=function(){var t=this;window.addEventListener("resize",function(e){return t.checkColumnCount()}),this.checkColumnCount(),this.on("breakpoint",function(e){return t.reorderElements(e.detail.columnCount)}),this.columnCount>=1&&this.reorderElements(this.columnCount)},t.prototype.getColumns=function(){return this.element.querySelectorAll(":scope > ."+this.options.columnClassName)},t.prototype.findMinHeightColumn=function(){var t=e(this.getColumns()),n=t.map(function(t){return t.offsetHeight}),o=Math.min.apply(null,n);return t[n.indexOf(o)]},t.prototype.getElementsInOrder=function(){return this.element.querySelectorAll(":scope > *:not(."+this.options.columnClassName+"):not(."+this.options.rulerClassName+")")},t.prototype.checkColumnCount=function(t){void 0===t&&(t=!0);var e=this.getColumnCount();this.columnCount!==e&&(t&&n(this.element,"bricklayer.breakpoint",{columnCount:e}),this.columnCount=e)},t.prototype.reorderElements=function(t){var n=this;void 0===t&&(t=1),(t==1/0||1>t)&&(t=1);for(var o=e(this.elements).map(function(t){var e=t.parentNode?t.parentNode.removeChild(t):t;return e}),r=this.getColumns(),i=0;i<r.length;i++)r[i].parentNode.removeChild(r[i]);for(var i=0;t>i;i++){var s=new u(this.options.columnClassName).element;this.element.appendChild(s)}o.forEach(function(t){var e=n.findMinHeightColumn();e.appendChild(t)})},t.prototype.getColumnCount=function(){var t=this.element.offsetWidth,e=this.ruler.getWidth();return Math.round(t/e)},t.prototype.applyPosition=function(t,e,o){var r=this,i=function(i){var s=i+t.charAt(0).toUpperCase()+t.substr(1);n(r.element,"bricklayer."+s,{item:o,column:e})};switch(i("before"),t){case"append":e.appendChild(o);break;case"prepend":e.insertBefore(o,e.firstChild)}i("after")},t}();t.Container=l}(o||(o={})),function(t,n){"function"==typeof define&&define.amd?define(function(){return n()}):"undefined"!=typeof window&&t===window?t.Bricklayer=n():"object"==typeof e&&e.exports&&(e.exports=n())}("undefined"!=typeof window?window:this,function(){return o.Container})},{}]},{},[1]); |
{ | ||
"name": "bricklayer", | ||
"version": "0.4.0", | ||
"version": "0.4.1", | ||
"description": "Lightweight and strong Masonry alternative", | ||
@@ -5,0 +5,0 @@ "main": "dist/bricklayer-node.js", |
@@ -41,4 +41,4 @@ <img src="https://raw.githubusercontent.com/ademilter/bricklayer/master/logo.png" width="416"> | ||
```html | ||
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/bricklayer/0.4.0/bricklayer.min.css"> | ||
<script src="//cdnjs.cloudflare.com/ajax/libs/bricklayer/0.4.0/bricklayer.min.js"></script> | ||
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/bricklayer/0.4.1/bricklayer.min.css"> | ||
<script src="//cdnjs.cloudflare.com/ajax/libs/bricklayer/0.4.1/bricklayer.min.js"></script> | ||
``` | ||
@@ -69,3 +69,3 @@ | ||
## Usage | ||
## Overview | ||
@@ -109,7 +109,10 @@ ##### Create a simple list: | ||
--- | ||
### Methods | ||
- Add bricks dynamically: | ||
#### `append(element)` | ||
With Bricklayer, you can add new bricks (some elements with heights) using `append` and `prepend`. | ||
#### `append(element)` to add new element to bottom | ||
Allows you to append bricks. | ||
@@ -123,10 +126,16 @@ | ||
#### `prepend(element)` | ||
#### `prepend(element)` to add new element to top | ||
Allows you to prepend bricks. | ||
#### Appending/Prepending Multiple Elements at Once | ||
```js | ||
bricklayer.prepend( | ||
myAwesomeElement | ||
) | ||
``` | ||
You can also add multiple bricks at once: | ||
#### `append`/`prepend` multiple elements at once | ||
You can also add multiple bricks at once by giving an array of elements: | ||
```js | ||
@@ -137,5 +146,10 @@ bricklayer.append([ | ||
]) | ||
bricklayer.prepend([ | ||
myAwesomeElement, | ||
myAwesomeButVeryLongElement | ||
]) | ||
``` | ||
#### `destroy()` | ||
#### `destroy()` to destroy Bricklayer | ||
@@ -148,3 +162,3 @@ Destroys bricklayer and related auto-generated elements. | ||
To rebuild the Bricklayer for an element, you should rerun `Bricklayer`. | ||
To rebuild the Bricklayer for an element, you should rerun `Bricklayer`: | ||
@@ -155,11 +169,9 @@ ``` | ||
#### `redraw(columnCount)` | ||
#### `redraw()` to reload all the elements | ||
Redraws all columns with given `columnCount`. **If `columnCount` is `null`** it will be decided by | ||
media queries. **If browser size changes it will be recalculated.** | ||
Redraws all columns. Column counts will be recalculated and it rebuilds columns | ||
with elements. | ||
In this example you'll force layout to be `5` columns. | ||
```js | ||
bricklayer.on("breakpoint", function () { bricklayer.redraw(5) }) | ||
bricklayer.redraw() | ||
``` | ||
@@ -207,7 +219,7 @@ | ||
```html | ||
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/bricklayer/0.4.0/bricklayer.min.css"> | ||
<script src="//cdnjs.cloudflare.com/ajax/libs/bricklayer/0.4.0/bricklayer.min.js"></script> | ||
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/bricklayer/0.4.1/bricklayer.min.css"> | ||
<script src="//cdnjs.cloudflare.com/ajax/libs/bricklayer/0.4.1/bricklayer.min.js"></script> | ||
<!-- You should also add jquery.bricklayer.js --> | ||
<script src="//cdnjs.cloudflare.com/ajax/libs/bricklayer/0.4.0/jquery.bricklayer.min.js"></script> | ||
<script src="//cdnjs.cloudflare.com/ajax/libs/bricklayer/0.4.1/jquery.bricklayer.min.js"></script> | ||
``` | ||
@@ -214,0 +226,0 @@ |
@@ -96,4 +96,5 @@ interface IOptions { | ||
redraw(columnCount = this.columnCount) { | ||
this.reorderElements(columnCount) | ||
redraw() { | ||
this.checkColumnCount(false) | ||
this.reorderElements(this.columnCount) | ||
} | ||
@@ -137,6 +138,8 @@ | ||
private checkColumnCount() { | ||
private checkColumnCount(publish = true) { | ||
var columnCount = this.getColumnCount() | ||
if (this.columnCount !== columnCount) { | ||
triggerEvent(this.element, "bricklayer.breakpoint", {columnCount}) | ||
if (publish) { | ||
triggerEvent(this.element, "bricklayer.breakpoint", {columnCount}) | ||
} | ||
this.columnCount = columnCount | ||
@@ -143,0 +146,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3557409
958
288