Investigation on PhotoSwipe - 02
2012-06-13 15:13
169 查看
And now, use Firefox console to inspect all the classes structure:
PhotoSwipe structure:
Util structure:
We can easily figure out the design pattern of the classes, for certain entry, it has a specific class name, and it serves as a data structure, it has CssClass, EventTypes and a class definition in general, and action types perhaps:
EntryName
|
| - - - CssClass
| - - - EventTypes
| - - - EntryNameClass
| - - - XXXAction (optional)
| - - - other functions (optional)
| - - - other variables (optional)
And even PhotoSwipe it uses this pattern. The EntryNameClass embody the operating logic of that entry, and others serve as static member variables, such as EventTypes defines what event types that entry may dispatch.
Now is time to inspect it from top to down, use WinHTTrack to download the files from the demo, and solve some little problems. Then we set up the demo kit locally, and the HTML:
According to jQueryMobile official docs: http://jquerymobile.com/demos/1.1.0/docs/pages/page-anatomy.html
The structure of the HTML is formed to follow jQueryMobile framework, and the navigation among pages is handled by jQM. So let's focus on its script part:
This script tell browser to do that after DOM loaded: bind anonymous function on pageShow event to 'gallery-page' class
DIV tag. And what the handler function does is to create a photoSwipe instance, passing all the a tags within the showed page.
photoSwipe() seems to be declared as a jQuery wrapper method now.
PhotoSwipe structure:
Util structure:
We can easily figure out the design pattern of the classes, for certain entry, it has a specific class name, and it serves as a data structure, it has CssClass, EventTypes and a class definition in general, and action types perhaps:
EntryName
|
| - - - CssClass
| - - - EventTypes
| - - - EntryNameClass
| - - - XXXAction (optional)
| - - - other functions (optional)
| - - - other variables (optional)
And even PhotoSwipe it uses this pattern. The EntryNameClass embody the operating logic of that entry, and others serve as static member variables, such as EventTypes defines what event types that entry may dispatch.
Now is time to inspect it from top to down, use WinHTTrack to download the files from the demo, and solve some little problems. Then we set up the demo kit locally, and the HTML:
<body> <div data-role="page" id="Home"> <div data-role="header"> <h1>PhotoSwipe</h1> </div> <div data-role="content" > <p>These examples show PhotoSwipe integrated with jQuery Mobile:</p> <ul data-role="listview" data-inset="true"> <li><a href="#Gallery1">First Gallery</a></li> <li><a href="#Gallery2">Second Gallery</a></li> </ul> <p>PhotoSwipe has also been designed to run stand-alone and can be easily integrated into your non jQuery / jQuery mobile websites:</p> <ul data-role="listview" data-inset="true"> <li><a href="01-default.html" target="_blank">Code Computerlove</a></li> </ul> </div> <div data-role="footer"> <h4>© 2011 Code Computerlove</h4> </div> </div> <div data-role="page" data-add-back-btn="true" id="Gallery1" class="gallery-page"> <div data-role="header"> <h1>First Gallery</h1> </div> <div data-role="content"> <ul class="gallery"> <li><a href="images/full/001.jpg" rel="external"><img src="images/thumb/001.jpg" alt="Image 001" /></a></li> <li><a href="images/full/002.jpg" rel="external"><img src="images/thumb/002.jpg" alt="Image 002" /></a></li> <li><a href="images/full/003.jpg" rel="external"><img src="images/thumb/003.jpg" alt="Image 003" /></a></li> <li><a href="images/full/004.jpg" rel="external"><img src="images/thumb/004.jpg" alt="Image 004" /></a></li> <li><a href="images/full/005.jpg" rel="external"><img src="images/thumb/005.jpg" alt="Image 005" /></a></li> <li><a href="images/full/006.jpg" rel="external"><img src="images/thumb/006.jpg" alt="Image 006" /></a></li> <li><a href="images/full/007.jpg" rel="external"><img src="images/thumb/007.jpg" alt="Image 007" /></a></li> <li><a href="images/full/008.jpg" rel="external"><img src="images/thumb/008.jpg" alt="Image 008" /></a></li> <li><a href="images/full/009.jpg" rel="external"><img src="images/thumb/009.jpg" alt="Image 009" /></a></li> </ul> </div> <div data-role="footer"> <h4>© 2011 Code Computerlove</h4> </div> </div> <div data-role="page" data-add-back-btn="true" id="Gallery2" class="gallery-page"> <div data-role="header"> <h1>Second Gallery</h1> </div> <div data-role="content"> <ul class="gallery"> <li><a href="images/full/010.jpg" rel="external"><img src="images/thumb/010.jpg" alt="Image 010" /></a></li> <li><a href="images/full/011.jpg" rel="external"><img src="images/thumb/011.jpg" alt="Image 011" /></a></li> <li><a href="images/full/012.jpg" rel="external"><img src="images/thumb/012.jpg" alt="Image 012" /></a></li> <li><a href="images/full/013.jpg" rel="external"><img src="images/thumb/013.jpg" alt="Image 013" /></a></li> <li><a href="images/full/014.jpg" rel="external"><img src="images/thumb/014.jpg" alt="Image 014" /></a></li> <li><a href="images/full/015.jpg" rel="external"><img src="images/thumb/015.jpg" alt="Image 015" /></a></li> <li><a href="images/full/016.jpg" rel="external"><img src="images/thumb/016.jpg" alt="Image 016" /></a></li> <li><a href="images/full/017.jpg" rel="external"><img src="images/thumb/017.jpg" alt="Image 017" /></a></li> <li><a href="images/full/018.jpg" rel="external"><img src="images/thumb/018.jpg" alt="Image 018" /></a></li> </ul> </div> <div data-role="footer"> <h4>© 2011 Code Computerlove</h4> </div> </div> </body>
According to jQueryMobile official docs: http://jquerymobile.com/demos/1.1.0/docs/pages/page-anatomy.html
The structure of the HTML is formed to follow jQueryMobile framework, and the navigation among pages is handled by jQM. So let's focus on its script part:
<script type="text/javascript"> (function(window, $, PhotoSwipe){ $(document).ready(function(){ $('div.gallery-page') .live('pageshow', function(e){ var currentPage = $(e.target), options = {}, photoSwipeInstance = $("ul.gallery a", e.target).photoSwipe(options, currentPage.attr('id')); return true; }) .live('pagehide', function(e){ var currentPage = $(e.target), photoSwipeInstance = PhotoSwipe.getInstance(currentPage.attr('id')); if (typeof photoSwipeInstance != "undefined" && photoSwipeInstance != null) { PhotoSwipe.detatch(photoSwipeInstance); } return true; }); }); }(window, window.jQuery, window.Code.PhotoSwipe)); </script>
This script tell browser to do that after DOM loaded: bind anonymous function on pageShow event to 'gallery-page' class
DIV tag. And what the handler function does is to create a photoSwipe instance, passing all the a tags within the showed page.
photoSwipeInstance = $("ul.gallery a", e.target).photoSwipe(options, currentPage.attr('id'));
photoSwipe() seems to be declared as a jQuery wrapper method now.
相关文章推荐
- Investigation on PhotoSwipe - 01
- PhotoSwipe源码解读系列(二)
- 发现看图好插件photoswipe,收藏备用
- Get list of photo galleries on Android
- SDL2入门教程(02_Getting an Image on the Screen)
- PhotoSwipe源码解读系列(二)
- 使用iScroll和photoswipe写手机浏览图片的插件的几点经验
- 数字图像处理实验(1):PROJECT 02-01, Image Printing Program Based on Halftoning
- [JS插件] PhotoSwipe 图片浏览插件使用方法
- Note on <Beginning Microsoft SQL Server 2012 Programming> - 02
- PhotoSwipe源码解读系列(二)
- PhotoSwipe 图片浏览,可放大缩小,左右滑动
- Huge Bear Surprises Samsung Crew on EcoBubble washing machine Photo Shoot
- [eShopOnContainers 学习系列] - 02 - vs 2017 开发环境配置
- 使用photoswipe展示图片
- js PhotoSwipe库开源的手机版相册产品的Code.PhotoSwipe.attach方法使用
- 使用iScroll和photoswipe写手机浏览图片的插件的几点经验
- PhotoSwipe简介
- Note 07/08/02 some question about js on Asp.Net : Vss 6.0
- PhotoSwipe 图片浏览插件使用方法 - 简单