DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Coding
  3. Frameworks
  4. A better Slideshow App, using Angular

A better Slideshow App, using Angular

Paul Hammant user avatar by
Paul Hammant
·
Mar. 08, 13 · Interview
Like (0)
Save
Tweet
Share
4.82K Views

Join the DZone community and get the full member experience.

Join For Free

my colleague stephane bisson has a better app than the one thoughtworkers and friends made a month ago . the source for stephane’s project ‘prez’ is on github and the running app is here though you should hit the left or right arrow to get it working. it does not yet do mobile device swipe left/right. he says he’ll “accept pull requests” to get it that working.

trying to do the same with angular

what stephane did in html is invent a element ‘slide’ that he uses like a div. yes that’s a non-standard element – don’t try it on older browsers. indeed the modern browsers process this like a div, with css transparently adding styling. angular, via directive can be told to intercept the <slide> element and do the right thing with it – namely show one slide at a time.

whereas the app we made a month ago, has some repeat-yourself attributes per slide:

<!-- these two rows repeat per slide -->
<tr id="2" ng-show="currentslide == 2">
    <td>
        <img ngm-swiperight="nav(1)" ngm-swipeleft="nav(3)" 
              ng-style="imgstyle" src="angular_slide_2.svg"/>
    </td>
</tr>
<tr ng-show="currentslide == 2 && !istouchscreen" style="display:none;">
    <td>
        <div class="navitems">
            <a ng-click="nav(1)">back</a>
            <a class="right" ng-click="nav(3)">next</a>
        </div>
    </td>
</tr>

stephane’s slideshow does not have boiler-plate slide html that the above has. see here:

<slide>
    <h1>dsl</h1>
    <p>this slide shows the dsl. the deck and slide tags.</p>
</slide>

stephane’s handles left-arrow-key and right-arrow key without having to encode that per slide, and also the implicit show/hide logic per slide. all that is in the code behind the directive that underpins <slide> from angular’s point of view. much less html .

under the hood.

inside the main app.js script, there’s a directive:

angularmodule.directive('slide', function (deck) {
    return {
        restrict: 'e',
        link: function ($scope, $element) {
            $element.hide();
            deck.add($element);
        }
    };
})

there’s much more to the app’s javascript around ‘deck’ and next/back processing that is shown in that snippet. that makes for more javascript than our example from a month ago. but the result is much terser and more elegant html .

put another way, stephane’s example has less view logic, more controller logic and about the same amount of model properties (referring to mvc of course). with four slides it’s a wash as to while os more code. with 50 slides stephane’s wins by a wide margin.

i’m reminded of something.

sami lempinen coded a simple slideshow technology ‘xslies’ some 14 years ago using xml and xsl . all that was done on the server side, and the resulting multi-page html was shipped to the client side. it was cool stuff in it’s day, and the terse markup language was much the same. sadly sami has not been a good historian for his own urls, so here’s what’s left of it on a third-party site

making the older slideshow terser too.

andrew dean and a few at the dallas geeknight meetup went on to make some changes to make that version a bit more dry too. less boilerplate via a single navigation row that adapts to the ‘current’ slide:

<tr ng-show="!istouchscreen" style="display: none;">
    <td>
        <div class="navitems">
            <a ng-click="nav(currentslide - 1)" 
               ng-show="currentslide > 1">back</a>
            <a class="right" ng-click="nav(currentslide + 1)" 
               ng-show="currentslide < 4">next</a></div>
    </td>    
</tr>

here is their fork with their improvements.

how does google see it ?

specifically in the search results, and the preview-panel?

in the search results:

the preview bot’s screen shot:

not quite what we were hoping for :(



mobile app AngularJS

Published at DZone with permission of Paul Hammant, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Exploring the Benefits of Cloud Computing: From IaaS, PaaS, SaaS to Google Cloud, AWS, and Microsoft
  • A Beginner's Guide to Back-End Development
  • Debugging Threads and Asynchronous Code
  • Image Classification With DCNNs

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: