Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated "readme.md" and added "open()" Method #2

Merged
merged 1 commit into from
Jun 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
[![Published on webcomponents.org](https://img.shields.io/badge/webcomponents.org-published-blue.svg?style=flat-square)](https://beta.webcomponents.org/element/oscarsolas/paper-lightbox)

# Paper-lightbox

### Description

Polymer element for launch a popup with a image, iframe, inline or ajax content.

### Install

First you need bower, [see their site](http://bower.io/) for details

```sh
bower install --save oscarsolas/paper-lightbox
```

### Examples

A simple example of its use:
Expand All @@ -30,6 +40,10 @@ A simple example of its use:

<!-- LAUNCH IFRAME POPUP -->
<paper-lightbox src="https://www.youtube.com/watch?v=assSM3rlvZ8" type="iframe">launch iframe popup</paper-lightbox>

<div style="display: none;">
<div class="inline-content">inline content example</div>
</div>
```

### Attributes
Expand Down
2 changes: 1 addition & 1 deletion paper-lightbox.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
<content></content>
</button>
</template>
<script>(function(){Polymer({is:"paper-lightbox",behaviors:[Polymer.IronResizableBehavior],listeners:{"iron-resize":"_onResize"},_createPopup:function(){var e,t,i,n;return i=this,t=document.createElement("div"),t.classList.add("paper-lightbox-popup"),e=document.createElement("iron-icon"),e.classList.add("paper-lightbox-popup_close"),e.setAttribute("icon","icons:close"),i.window=document.createElement("div"),i.window.classList.add("paper-lightbox-popup_window"),i.window.appendChild(e),t.appendChild(i.window),n=document.createElement("div"),n.classList.add("paper-lightbox-popup_overlay"),t.appendChild(n),i.appendChild(t)},_getImageRatio:function(e,t){var i;return i=this,e>t?i.window.classList.add("landscape"):i.window.classList.add("portrait")},_isAjax:function(){var e;if(e=this,"ajax"===this._getType())return!0},_parseAjax:function(e){var t,i;return i=this,t=document.createElement("div"),t.innerHTML=e,[].forEach.call(t.children,function(e,t){return i.window.appendChild(e)})},_ajaxResponse:function(e){var t;return t=this,t.ajaxResponse=e.target.lastResponse},_createAjax:function(){var e;return e=this,this._createPopup(),this._parseAjax(e.ajaxResponse),e.window.classList.add("paper-lightbox-popup_window-ajax"),this._closePopup()},_createImage:function(){var e,t;return t=this,e=new Image,e.onload=function(){return t._createPopup(),t._getImageRatio(e.naturalWidth,e.naturalHeight),t.window.classList.add("paper-lightbox-popup_window-image"),t.window.appendChild(e),t._onResize(),t._closePopup()},e.src=t.getAttribute("src")},_createIframe:function(){var e,t,i,n,a;return i=this,a=i.getAttribute("src"),e=document.createElement("iframe"),n=a.replace("/watch?v=","/embed/"),e.setAttribute("frameborder","0"),e.setAttribute("allowfullscreen",""),t=document.createElement("div"),t.classList.add("paper-lightbox_iframeWrapper"),a.indexOf("youtube.com/watch?v=")>-1?e.setAttribute("src",n):e.setAttribute("src",a),this._createPopup(),i.window.classList.add("paper-lightbox-popup_window-iframe"),t.appendChild(e),i.window.appendChild(t),this._closePopup()},_createInline:function(){var e,t;return t=this,e=document.querySelector(t.getAttribute("src")),this._createPopup(),t.window.classList.add("paper-lightbox-popup_window-inline"),t.window.appendChild(e.cloneNode(!0)),this._closePopup()},_getType:function(){var e;return e=this,e.getAttribute("type")},_launchPopup:function(){var e;switch(e=this,this._getType()){case"ajax":return e.listen(e.$$("button"),"tap","_createAjax");case"image":return e.listen(e.$$("button"),"tap","_createImage");case"inline":return e.listen(e.$$("button"),"tap","_createInline");case"iframe":return e.listen(e.$$("button"),"tap","_createIframe")}},_removePopup:function(){var e,t;return e=this,t=e.querySelector(".paper-lightbox-popup"),this.window=void 0,t.remove()},_closePopup:function(){var e,t,i;return t=this,i=t.querySelector(".paper-lightbox-popup_overlay"),e=t.querySelector(".paper-lightbox-popup_close"),t.listen(i,"tap","_removePopup"),t.listen(e,"tap","_removePopup")},_onResize:function(){var e;if(this.window&&this.window.classList.contains("portrait"))return e=this.window.querySelector("img"),e.style.maxHeight=.8*window.innerHeight+"px"},ready:function(){return this._launchPopup()},onAjaxContentLoaded:function(){},onImageLoaded:function(){}})}).call(this);</script>
<script>(function(){Polymer({is:"paper-lightbox",behaviors:[Polymer.IronResizableBehavior],listeners:{"iron-resize":"_onResize"},_createPopup:function(){var e,t,i,a;return i=this,t=document.createElement("div"),t.classList.add("paper-lightbox-popup"),e=document.createElement("iron-icon"),e.classList.add("paper-lightbox-popup_close"),e.setAttribute("icon","icons:close"),i.window=document.createElement("div"),i.window.classList.add("paper-lightbox-popup_window"),i.window.appendChild(e),t.appendChild(i.window),a=document.createElement("div"),a.classList.add("paper-lightbox-popup_overlay"),t.appendChild(a),i.appendChild(t)},_getImageRatio:function(e,t){var i;return i=this,e>t?i.window.classList.add("landscape"):i.window.classList.add("portrait")},_isAjax:function(){var e;if(e=this,"ajax"===this._getType())return!0},_parseAjax:function(e){var t,i;return i=this,t=document.createElement("div"),t.innerHTML=e,[].forEach.call(t.children,function(e,t){return i.window.appendChild(e)})},_ajaxResponse:function(e){var t;return t=this,t.ajaxResponse=e.target.lastResponse},_createAjax:function(){var e;return e=this,this._createPopup(),this._parseAjax(e.ajaxResponse),e.window.classList.add("paper-lightbox-popup_window-ajax"),this._closePopup()},_createImage:function(){var e,t;return t=this,e=new Image,e.onload=function(){return t._createPopup(),t._getImageRatio(e.naturalWidth,e.naturalHeight),t.window.classList.add("paper-lightbox-popup_window-image"),t.window.appendChild(e),t._onResize(),t._closePopup()},e.src=t.getAttribute("src")},_createIframe:function(){var e,t,i,a,n;return i=this,n=i.getAttribute("src"),e=document.createElement("iframe"),a=n.replace("/watch?v=","/embed/"),e.setAttribute("frameborder","0"),e.setAttribute("allowfullscreen",""),t=document.createElement("div"),t.classList.add("paper-lightbox_iframeWrapper"),n.indexOf("youtube.com/watch?v=")>-1?e.setAttribute("src",a):e.setAttribute("src",n),this._createPopup(),i.window.classList.add("paper-lightbox-popup_window-iframe"),t.appendChild(e),i.window.appendChild(t),this._closePopup()},_createInline:function(){var e,t;return t=this,e=document.querySelector(t.getAttribute("src")),this._createPopup(),t.window.classList.add("paper-lightbox-popup_window-inline"),t.window.appendChild(e.cloneNode(!0)),this._closePopup()},_getType:function(){var e;return e=this,e.getAttribute("type")},_launchPopup:function(){var e;switch(e=this,this._getType()){case"ajax":return e.listen(e.$$("button"),"tap","_createAjax");case"image":return e.listen(e.$$("button"),"tap","_createImage");case"inline":return e.listen(e.$$("button"),"tap","_createInline");case"iframe":return e.listen(e.$$("button"),"tap","_createIframe")}},_removePopup:function(){var e,t;return e=this,t=e.querySelector(".paper-lightbox-popup"),this.window=void 0,t.remove()},_closePopup:function(){var e,t,i;return t=this,i=t.querySelector(".paper-lightbox-popup_overlay"),e=t.querySelector(".paper-lightbox-popup_close"),t.listen(i,"tap","_removePopup"),t.listen(e,"tap","_removePopup")},_onResize:function(){var e;if(this.window&&this.window.classList.contains("portrait"))return e=this.window.querySelector("img"),e.style.maxHeight=.8*window.innerHeight+"px"},ready:function(){return this._launchPopup()},onAjaxContentLoaded:function(){},onImageLoaded:function(){},open:function(){var e;switch(e=this,this._getType()){case"ajax":return this._createAjax();case"image":return this._createImage();case"inline":return this._createInline();case"iframe":return this._createIframe()}}})}).call(this);</script>
</dom-module>
13 changes: 13 additions & 0 deletions source/paper-lightbox.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,16 @@ Polymer
onAjaxContentLoaded: ->

onImageLoaded: ->

open: ->
module = @

switch @_getType()
when 'ajax'
@_createAjax()
when 'image'
@_createImage()
when 'inline'
@_createInline()
when 'iframe'
@_createIframe()