SlideShare ist ein Scribd-Unternehmen logo
1 von 54
Downloaden Sie, um offline zu lesen
Drupal Recipes:
Building Image Galleries
     Covering Flickr, jQuery, and
       Drupal best practices


    Presented by Benjamin Shell from WorkHabit
Start with a plan, and make
   Drupal work for you.
(don’t limit your imagination to what Drupal
  and existing modules do out of the box)
Planning

Remember that most*
people don’t think like a
relational database



  *Disclaimer: I recently used database concepts
    in an unrelated discussion with my wife...
My Plan
User Experience:
  • Show random image thumbnails on the
    sidebar
  • Show a sliding image viewer on the right

Technical Requirements:
  • Download images from Flickr
  • Store images as nodes
  • Use Views to build queries
Looking for Modules
• drupal.org
• drupalmodules.com
• CVS checkout of all contributions
  (grep search for keywords)
• Asking around (drupal.org, IRC,
  co-workers, conferences, etc.)
Implementation

There are essentially two types of Drupal
modules:
1. Reusable “ingredients”
2. Complete solutions
(there’s some overlap of course)
My Approach
Use complete solutions if appropriate, BUT:
• DON’T spend too long finding them
• DON’T spend too long forcing them to
  work for you
• DON’T load 2000 lines of code if you’re only
  using 50
My Approach
Use common “ingredients” to build what you need.
Building the site

              start here



Input    Storage           Retrieval   Output
Storage
Preferred: CCK + Imagefield
Not-recommended:
  • Attach multiple image files directly to a node
  • Use a non-CCK node type
Storage
New content type: Image
Data Input

      • Millions of people
        already use it
      • Easy to upload
        photos
Why import to Drupal?

         • Theming flexibility
         • Integration
         • Security
Flickr Import
Plan:
•  Automatically download new photos from
   Flickr
•  Create Drupal nodes with attached images
•  Import Flickr tags to taxonomy terms

Problem: I couldn’t find a module to do this
The closest I could find...

• Activity Stream
• FlickrRippr
• Emfield/Emfield Import
• Flickr module
LE
      U
     D
     O
    M
EW




         Flickr API Module
N




     • Loads phpFlickr
     • Stores the Flickr API key
     • Can be used by other Flickr modules
Flickr API Module
LE
      U
     D
     O
    M
EW




         Flickr Sync Module
N




     Downloads new Flickr photos
     to new Drupal nodes
Flickr Sync Module
Settings page:
 • Configure the
   content fields to use
 • Specify batch
   importing settings
Flickr Sync Module

Every user has
Flickr sync settings
in their account
settings
Flickr Sync Module
      Performing an import manually
(cron will keep things up-to-date, but the manual
   process is nice for the impatient among us)
Thumbnails with a lightbox
Lightboxes

• Popular replacement for popup windows
• Comparison of “lightbox” type modules:
  http://www.drupal.org/node/266126
• I used jLightbox for it’s simplicity, but
  Lightbox 2 is another great module
Lightboxes

Lightboxes typically work using the “rel”
attribute of a link:

<a href=quot;images/image-1.jpgquot;
rel=quot;lightboxquot;>image #1</a>
Using the Views UI

     Create a block

     Filter for image nodes
Lightboxes
                         Theming the view

function phptemplate_views_view_imagelist($view, $type, $nodes) {
  foreach ($nodes as $n) {
    $node = node_load($n->nid);
    $original_file = $node->field_image[0]['filepath'];
    $lightbox_file = imagecache_create_url('lightbox', $file);
    $img_tag = theme('imagecache', 'sidebar', $original_file);
    $link = l($img_tag, $lightbox_file, array(
            'rel' => quot;lightbox[sidebar]quot;), NULL, NULL, FALSE, TRUE);
    $output .= '<div>' . $link . quot;</div>nquot;;
  }
  return $output;
}
No more hunting for a module to
 do exactly what you want -- with
just a little view theming code the
      possibilities are endless!
Building an image slider
LE
      U
     D
     O
    M
EW
N




        Image Slider Module
         Concept based on jQuery slideViewer 1.1
Building a new module can
 be easier than building a
      complex theme
Building the image slider

• Setup a new View (just like before)
• Call the View from your module:
  $view = views_get_view('imageslider');


• Render the View from your module:
  $output = views_build_view('block', $view, array(), false);


• Theme the View (just like before)
Theming output
<div class=quot;imagesliderquot; style=quot;width:   500px; height: 300pxquot;>
  <ul style=quot;width: 1500pxquot;>
    <li><img src=quot;...quot; alt=quot;quot; title=quot;quot;   /></li>
    <li><img src=quot;...quot; alt=quot;quot; title=quot;quot;   /></li>
    <li><img src=quot;...quot; alt=quot;quot; title=quot;quot;   /></li>
  </ul>
</div>
Image slider CSS
div.imageslider {
  overflow: hidden;
  position: relative;
}

div.imageslider ul {        Change left
  list-style-type: none;
  position: relative;      value to move
  left: 0;                   the slider
  top: 0;
}

div.imageslider ul li {
  float: left;
}
Image slider JavaScript
• Get the image slider container
• Find out how many images there are
• Get the width of the images
• For each button click, move the slider to
  the proper position:
  (current image number) x (width of images)
Add module settings

            Easy to add,
            easy to change
Tips for using CSS and
JavaScript with Drupal
CSS and JavaScript


  Load only where needed
Adding JavaScript


JavaScript should be unobtrusive
“Auto Attach”
      Runs your JavaScript if JavaScript is
      available and when everything is ready.


// Global Killswitch

if (Drupal.jsEnabled) {

    $(document).ready(Drupal.imageslider.autoAttach);

}
Use Drupal.settings
          Drupal can output settings that can
           be easily read in your JavaScript:
In PHP:
drupal_add_js(array(
    'imageslider' => array(
      'easeFunc' => variable_get('imageslider_ease_func', ''),
      'easeTime' => variable_get('imageslider_ease_time', 750)
    )
  ), 'setting');


In JavaScript:
var easeTime = Drupal.settings.imageslider.eastTime;
Adding JavaScript


Follow good naming conventions
Naming Conventions
Typically lower/upper , but just be consistent
with Drupal and jQuery, or whatever JS
libraries you work with.

  var box = getBox();

  var newBoxHeight = 20;

  box.setHeight(newBoxHeight);
Adding JavaScript


  Use proper namespacing
JavaScript Namespacing

What’s wrong with this?


for (i = 0; i < 5; i++) {

    // do something

}
JavaScript Namespacing

Using undefined
variables clutters
the global
namespace!
JavaScript Namespacing

Define every variable!


for (var i = 0; i < 5; i++) {

    // do something

}
JavaScript Namespacing
Namespace everything. Even JavaScript
functions will overwrite each other:

function test() {
  alert('foo');
}
                     overwritten!
function test() {
  alert('bar');
}

test();
JavaScript Namespacing

An example of proper namespacing:


  var Drupal = Drupal || {};

  Drupal.extend = function(obj) { ... }

  Drupal.dimensions = function (el) { ... }
Adding JavaScript


 Learn to understand scope
Understanding Scope
       Simple Example of jQuery scope:

function autoAttach() {
  var settings = {
     foo: 'bar'
  };

    jQuery(quot;aquot;).mouseover(function() {
      alert(settings.foo);
    });
}
Understanding Scope
    Using a separate function for handlers
function autoAttach() {
  var settings = {
     foo: 'bar'
  };

    jQuery(quot;aquot;).mouseover(function() {
      onOver.call(settings);
    });
}

function onOver() {
  // 'this' is the settings object
  alert(this.foo);
}
Understanding Scope
     Passing additional variables with ‘call’
function autoAttach() {
  var settings = {
     foo: 'bar'
  };

    jQuery(quot;aquot;).mouseover(function(evt) {
      onOver.call(settings, evt);
    });
}

function onOver(evt) {
  // 'this' is the settings object
  alert(this.foo);
}
Tools
• Firefox with Firebug
• Aptana Studio
• Opera Developer Tools
• IE Developer Toolbar
• Windows (for testing)
New Drupal.org Releases

 • http://drupal.org/project/flickrapi
 • http://drupal.org/project/flickrsync
 • http://drupal.org/project/imageslider

Weitere ähnliche Inhalte

Was ist angesagt?

Taking your module from Drupal 6 to Drupal 7
Taking your module from Drupal 6 to Drupal 7Taking your module from Drupal 6 to Drupal 7
Taking your module from Drupal 6 to Drupal 7Phase2
 
Drupal 8 Theme System: The Backend of Frontend
Drupal 8 Theme System: The Backend of FrontendDrupal 8 Theme System: The Backend of Frontend
Drupal 8 Theme System: The Backend of FrontendAcquia
 
Room with a Vue - Introduction to Vue.js
Room with a Vue - Introduction to Vue.jsRoom with a Vue - Introduction to Vue.js
Room with a Vue - Introduction to Vue.jsZachary Klein
 
Single Page Apps with Drupal 8
Single Page Apps with Drupal 8Single Page Apps with Drupal 8
Single Page Apps with Drupal 8Chris Tankersley
 
Introduction to modern front-end with Vue.js
Introduction to modern front-end with Vue.jsIntroduction to modern front-end with Vue.js
Introduction to modern front-end with Vue.jsmonterail
 
Getting Started with DrupalGap
Getting Started with DrupalGapGetting Started with DrupalGap
Getting Started with DrupalGapAlex S
 
Drupal and diversity of Single sign-on systems
Drupal and diversity of Single sign-on systemsDrupal and diversity of Single sign-on systems
Drupal and diversity of Single sign-on systemsAlex S
 
An introduction to Vue.js
An introduction to Vue.jsAn introduction to Vue.js
An introduction to Vue.jsPagepro
 
Nuxt.JS Introdruction
Nuxt.JS IntrodructionNuxt.JS Introdruction
Nuxt.JS IntrodructionDavid Ličen
 
Build your application in seconds and optimize workflow as much as you can us...
Build your application in seconds and optimize workflow as much as you can us...Build your application in seconds and optimize workflow as much as you can us...
Build your application in seconds and optimize workflow as much as you can us...Alex S
 
Features everywhere
Features everywhere Features everywhere
Features everywhere Mediacurrent
 
The Complementarity of React and Web Components
The Complementarity of React and Web ComponentsThe Complementarity of React and Web Components
The Complementarity of React and Web ComponentsAndrew Rota
 
Build Amazing Add-ons for Atlassian JIRA and Confluence
Build Amazing Add-ons for Atlassian JIRA and ConfluenceBuild Amazing Add-ons for Atlassian JIRA and Confluence
Build Amazing Add-ons for Atlassian JIRA and ConfluenceK15t
 
Solution to capture webpage screenshot with html2 canvas.js for backend devel...
Solution to capture webpage screenshot with html2 canvas.js for backend devel...Solution to capture webpage screenshot with html2 canvas.js for backend devel...
Solution to capture webpage screenshot with html2 canvas.js for backend devel...eLuminous Technologies Pvt. Ltd.
 
Take your drupal sites offline
Take your drupal sites offlineTake your drupal sites offline
Take your drupal sites offlineChris Ward
 
Building Angular Component Libraries
Building Angular Component LibrariesBuilding Angular Component Libraries
Building Angular Component LibrariesIsatu Conteh
 

Was ist angesagt? (20)

Taking your module from Drupal 6 to Drupal 7
Taking your module from Drupal 6 to Drupal 7Taking your module from Drupal 6 to Drupal 7
Taking your module from Drupal 6 to Drupal 7
 
Vue presentation
Vue presentationVue presentation
Vue presentation
 
Drupal 8 Theme System: The Backend of Frontend
Drupal 8 Theme System: The Backend of FrontendDrupal 8 Theme System: The Backend of Frontend
Drupal 8 Theme System: The Backend of Frontend
 
Room with a Vue - Introduction to Vue.js
Room with a Vue - Introduction to Vue.jsRoom with a Vue - Introduction to Vue.js
Room with a Vue - Introduction to Vue.js
 
Single Page Apps with Drupal 8
Single Page Apps with Drupal 8Single Page Apps with Drupal 8
Single Page Apps with Drupal 8
 
Introduction to modern front-end with Vue.js
Introduction to modern front-end with Vue.jsIntroduction to modern front-end with Vue.js
Introduction to modern front-end with Vue.js
 
Getting Started with DrupalGap
Getting Started with DrupalGapGetting Started with DrupalGap
Getting Started with DrupalGap
 
Drupal and diversity of Single sign-on systems
Drupal and diversity of Single sign-on systemsDrupal and diversity of Single sign-on systems
Drupal and diversity of Single sign-on systems
 
An introduction to Vue.js
An introduction to Vue.jsAn introduction to Vue.js
An introduction to Vue.js
 
Nuxt.JS Introdruction
Nuxt.JS IntrodructionNuxt.JS Introdruction
Nuxt.JS Introdruction
 
Build your application in seconds and optimize workflow as much as you can us...
Build your application in seconds and optimize workflow as much as you can us...Build your application in seconds and optimize workflow as much as you can us...
Build your application in seconds and optimize workflow as much as you can us...
 
Features everywhere
Features everywhere Features everywhere
Features everywhere
 
The Complementarity of React and Web Components
The Complementarity of React and Web ComponentsThe Complementarity of React and Web Components
The Complementarity of React and Web Components
 
Build Amazing Add-ons for Atlassian JIRA and Confluence
Build Amazing Add-ons for Atlassian JIRA and ConfluenceBuild Amazing Add-ons for Atlassian JIRA and Confluence
Build Amazing Add-ons for Atlassian JIRA and Confluence
 
Solution to capture webpage screenshot with html2 canvas.js for backend devel...
Solution to capture webpage screenshot with html2 canvas.js for backend devel...Solution to capture webpage screenshot with html2 canvas.js for backend devel...
Solution to capture webpage screenshot with html2 canvas.js for backend devel...
 
An introduction to Vue.js
An introduction to Vue.jsAn introduction to Vue.js
An introduction to Vue.js
 
Backbone
BackboneBackbone
Backbone
 
Take your drupal sites offline
Take your drupal sites offlineTake your drupal sites offline
Take your drupal sites offline
 
Building Angular Component Libraries
Building Angular Component LibrariesBuilding Angular Component Libraries
Building Angular Component Libraries
 
Vue business first
Vue business firstVue business first
Vue business first
 

Andere mochten auch

Building a product's personality
Building a product's personalityBuilding a product's personality
Building a product's personalityEmma Butin
 
LMI - Tools for a positive change in your personality, 6 steps for leadership...
LMI - Tools for a positive change in your personality, 6 steps for leadership...LMI - Tools for a positive change in your personality, 6 steps for leadership...
LMI - Tools for a positive change in your personality, 6 steps for leadership...LMI-India
 
Rami hamad al khalid (cpt )
Rami hamad al khalid (cpt )Rami hamad al khalid (cpt )
Rami hamad al khalid (cpt )Rami Al Shemari
 
Me Myself and I and the Others
Me Myself and I and the OthersMe Myself and I and the Others
Me Myself and I and the Otherskarinka2
 
Brand Image Building
Brand Image BuildingBrand Image Building
Brand Image BuildingJasravee
 

Andere mochten auch (6)

Building a product's personality
Building a product's personalityBuilding a product's personality
Building a product's personality
 
LMI - Tools for a positive change in your personality, 6 steps for leadership...
LMI - Tools for a positive change in your personality, 6 steps for leadership...LMI - Tools for a positive change in your personality, 6 steps for leadership...
LMI - Tools for a positive change in your personality, 6 steps for leadership...
 
Rami hamad al khalid (cpt )
Rami hamad al khalid (cpt )Rami hamad al khalid (cpt )
Rami hamad al khalid (cpt )
 
Me Myself and I and the Others
Me Myself and I and the OthersMe Myself and I and the Others
Me Myself and I and the Others
 
Brand Image Building
Brand Image BuildingBrand Image Building
Brand Image Building
 
PERSONALITY DEVELOPMENT
PERSONALITY DEVELOPMENTPERSONALITY DEVELOPMENT
PERSONALITY DEVELOPMENT
 

Ähnlich wie Drupal Recipes: Building Image Galleries with jQuery and Flickr

Drupal Development
Drupal DevelopmentDrupal Development
Drupal DevelopmentJeff Eaton
 
#D8CX: Upgrade your modules to Drupal 8 (Part 1 and 2)
#D8CX: Upgrade your modules to Drupal 8 (Part 1 and 2)#D8CX: Upgrade your modules to Drupal 8 (Part 1 and 2)
#D8CX: Upgrade your modules to Drupal 8 (Part 1 and 2)Konstantin Komelin
 
Drupal 8, Where Did the Code Go? From Info Hook to Plugin
Drupal 8, Where Did the Code Go? From Info Hook to PluginDrupal 8, Where Did the Code Go? From Info Hook to Plugin
Drupal 8, Where Did the Code Go? From Info Hook to PluginAcquia
 
JQuery In Drupal
JQuery In DrupalJQuery In Drupal
JQuery In Drupalkatbailey
 
Extracting Plugins And Gems From Rails Apps
Extracting Plugins And Gems From Rails AppsExtracting Plugins And Gems From Rails Apps
Extracting Plugins And Gems From Rails AppsJosh Nichols
 
Reactive Type-safe WebComponents
Reactive Type-safe WebComponentsReactive Type-safe WebComponents
Reactive Type-safe WebComponentsMartin Hochel
 
20130528 solution linux_frousseau_nopain_webdev
20130528 solution linux_frousseau_nopain_webdev20130528 solution linux_frousseau_nopain_webdev
20130528 solution linux_frousseau_nopain_webdevFrank Rousseau
 
Drupal Javascript for developers
Drupal Javascript for developersDrupal Javascript for developers
Drupal Javascript for developersDream Production AG
 
Refresh Austin - Intro to Dexy
Refresh Austin - Intro to DexyRefresh Austin - Intro to Dexy
Refresh Austin - Intro to Dexyananelson
 
Drupal Best Practices
Drupal Best PracticesDrupal Best Practices
Drupal Best Practicesmanugoel2003
 
Artdm170 Week4 Java Script Effects
Artdm170 Week4 Java Script EffectsArtdm170 Week4 Java Script Effects
Artdm170 Week4 Java Script EffectsGilbert Guerrero
 
Reactive Type safe Webcomponents with skateJS
Reactive Type safe Webcomponents with skateJSReactive Type safe Webcomponents with skateJS
Reactive Type safe Webcomponents with skateJSMartin Hochel
 
Image manipulation in WordPress 3.5
Image manipulation in WordPress 3.5Image manipulation in WordPress 3.5
Image manipulation in WordPress 3.5Marko Heijnen
 
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)Igor Bronovskyy
 
When Smalltalk Meets the Web
When Smalltalk Meets the WebWhen Smalltalk Meets the Web
When Smalltalk Meets the WebESUG
 
Overlays, Accordions & Tabs, Oh My
Overlays, Accordions & Tabs, Oh MyOverlays, Accordions & Tabs, Oh My
Overlays, Accordions & Tabs, Oh MySteve McMahon
 
Using RequireJS with CakePHP
Using RequireJS with CakePHPUsing RequireJS with CakePHP
Using RequireJS with CakePHPStephen Young
 
Cordova: Making Native Mobile Apps With Your Web Skills
Cordova: Making Native Mobile Apps With Your Web SkillsCordova: Making Native Mobile Apps With Your Web Skills
Cordova: Making Native Mobile Apps With Your Web SkillsClay Ewing
 

Ähnlich wie Drupal Recipes: Building Image Galleries with jQuery and Flickr (20)

Drupal Development
Drupal DevelopmentDrupal Development
Drupal Development
 
#D8CX: Upgrade your modules to Drupal 8 (Part 1 and 2)
#D8CX: Upgrade your modules to Drupal 8 (Part 1 and 2)#D8CX: Upgrade your modules to Drupal 8 (Part 1 and 2)
#D8CX: Upgrade your modules to Drupal 8 (Part 1 and 2)
 
#D8 cx: upgrade your modules to drupal 8
#D8 cx: upgrade your modules to drupal 8 #D8 cx: upgrade your modules to drupal 8
#D8 cx: upgrade your modules to drupal 8
 
Drupal 8, Where Did the Code Go? From Info Hook to Plugin
Drupal 8, Where Did the Code Go? From Info Hook to PluginDrupal 8, Where Did the Code Go? From Info Hook to Plugin
Drupal 8, Where Did the Code Go? From Info Hook to Plugin
 
JQuery In Drupal
JQuery In DrupalJQuery In Drupal
JQuery In Drupal
 
Extracting Plugins And Gems From Rails Apps
Extracting Plugins And Gems From Rails AppsExtracting Plugins And Gems From Rails Apps
Extracting Plugins And Gems From Rails Apps
 
Reactive Type-safe WebComponents
Reactive Type-safe WebComponentsReactive Type-safe WebComponents
Reactive Type-safe WebComponents
 
20130528 solution linux_frousseau_nopain_webdev
20130528 solution linux_frousseau_nopain_webdev20130528 solution linux_frousseau_nopain_webdev
20130528 solution linux_frousseau_nopain_webdev
 
Drupal Javascript for developers
Drupal Javascript for developersDrupal Javascript for developers
Drupal Javascript for developers
 
Refresh Austin - Intro to Dexy
Refresh Austin - Intro to DexyRefresh Austin - Intro to Dexy
Refresh Austin - Intro to Dexy
 
Drupal Best Practices
Drupal Best PracticesDrupal Best Practices
Drupal Best Practices
 
WCLA12 JavaScript
WCLA12 JavaScriptWCLA12 JavaScript
WCLA12 JavaScript
 
Artdm170 Week4 Java Script Effects
Artdm170 Week4 Java Script EffectsArtdm170 Week4 Java Script Effects
Artdm170 Week4 Java Script Effects
 
Reactive Type safe Webcomponents with skateJS
Reactive Type safe Webcomponents with skateJSReactive Type safe Webcomponents with skateJS
Reactive Type safe Webcomponents with skateJS
 
Image manipulation in WordPress 3.5
Image manipulation in WordPress 3.5Image manipulation in WordPress 3.5
Image manipulation in WordPress 3.5
 
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
 
When Smalltalk Meets the Web
When Smalltalk Meets the WebWhen Smalltalk Meets the Web
When Smalltalk Meets the Web
 
Overlays, Accordions & Tabs, Oh My
Overlays, Accordions & Tabs, Oh MyOverlays, Accordions & Tabs, Oh My
Overlays, Accordions & Tabs, Oh My
 
Using RequireJS with CakePHP
Using RequireJS with CakePHPUsing RequireJS with CakePHP
Using RequireJS with CakePHP
 
Cordova: Making Native Mobile Apps With Your Web Skills
Cordova: Making Native Mobile Apps With Your Web SkillsCordova: Making Native Mobile Apps With Your Web Skills
Cordova: Making Native Mobile Apps With Your Web Skills
 

Kürzlich hochgeladen

Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 

Kürzlich hochgeladen (20)

Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 

Drupal Recipes: Building Image Galleries with jQuery and Flickr

  • 1. Drupal Recipes: Building Image Galleries Covering Flickr, jQuery, and Drupal best practices Presented by Benjamin Shell from WorkHabit
  • 2. Start with a plan, and make Drupal work for you. (don’t limit your imagination to what Drupal and existing modules do out of the box)
  • 3. Planning Remember that most* people don’t think like a relational database *Disclaimer: I recently used database concepts in an unrelated discussion with my wife...
  • 4. My Plan User Experience: • Show random image thumbnails on the sidebar • Show a sliding image viewer on the right Technical Requirements: • Download images from Flickr • Store images as nodes • Use Views to build queries
  • 5. Looking for Modules • drupal.org • drupalmodules.com • CVS checkout of all contributions (grep search for keywords) • Asking around (drupal.org, IRC, co-workers, conferences, etc.)
  • 6. Implementation There are essentially two types of Drupal modules: 1. Reusable “ingredients” 2. Complete solutions (there’s some overlap of course)
  • 7. My Approach Use complete solutions if appropriate, BUT: • DON’T spend too long finding them • DON’T spend too long forcing them to work for you • DON’T load 2000 lines of code if you’re only using 50
  • 8. My Approach Use common “ingredients” to build what you need.
  • 9. Building the site start here Input Storage Retrieval Output
  • 10. Storage Preferred: CCK + Imagefield Not-recommended: • Attach multiple image files directly to a node • Use a non-CCK node type
  • 12. Data Input • Millions of people already use it • Easy to upload photos
  • 13. Why import to Drupal? • Theming flexibility • Integration • Security
  • 14. Flickr Import Plan: • Automatically download new photos from Flickr • Create Drupal nodes with attached images • Import Flickr tags to taxonomy terms Problem: I couldn’t find a module to do this
  • 15. The closest I could find... • Activity Stream • FlickrRippr • Emfield/Emfield Import • Flickr module
  • 16. LE U D O M EW Flickr API Module N • Loads phpFlickr • Stores the Flickr API key • Can be used by other Flickr modules
  • 18. LE U D O M EW Flickr Sync Module N Downloads new Flickr photos to new Drupal nodes
  • 19. Flickr Sync Module Settings page: • Configure the content fields to use • Specify batch importing settings
  • 20. Flickr Sync Module Every user has Flickr sync settings in their account settings
  • 21. Flickr Sync Module Performing an import manually (cron will keep things up-to-date, but the manual process is nice for the impatient among us)
  • 22. Thumbnails with a lightbox
  • 23. Lightboxes • Popular replacement for popup windows • Comparison of “lightbox” type modules: http://www.drupal.org/node/266126 • I used jLightbox for it’s simplicity, but Lightbox 2 is another great module
  • 24. Lightboxes Lightboxes typically work using the “rel” attribute of a link: <a href=quot;images/image-1.jpgquot; rel=quot;lightboxquot;>image #1</a>
  • 25. Using the Views UI Create a block Filter for image nodes
  • 26. Lightboxes Theming the view function phptemplate_views_view_imagelist($view, $type, $nodes) { foreach ($nodes as $n) { $node = node_load($n->nid); $original_file = $node->field_image[0]['filepath']; $lightbox_file = imagecache_create_url('lightbox', $file); $img_tag = theme('imagecache', 'sidebar', $original_file); $link = l($img_tag, $lightbox_file, array( 'rel' => quot;lightbox[sidebar]quot;), NULL, NULL, FALSE, TRUE); $output .= '<div>' . $link . quot;</div>nquot;; } return $output; }
  • 27. No more hunting for a module to do exactly what you want -- with just a little view theming code the possibilities are endless!
  • 29. LE U D O M EW N Image Slider Module Concept based on jQuery slideViewer 1.1
  • 30. Building a new module can be easier than building a complex theme
  • 31. Building the image slider • Setup a new View (just like before) • Call the View from your module: $view = views_get_view('imageslider'); • Render the View from your module: $output = views_build_view('block', $view, array(), false); • Theme the View (just like before)
  • 32. Theming output <div class=quot;imagesliderquot; style=quot;width: 500px; height: 300pxquot;> <ul style=quot;width: 1500pxquot;> <li><img src=quot;...quot; alt=quot;quot; title=quot;quot; /></li> <li><img src=quot;...quot; alt=quot;quot; title=quot;quot; /></li> <li><img src=quot;...quot; alt=quot;quot; title=quot;quot; /></li> </ul> </div>
  • 33. Image slider CSS div.imageslider { overflow: hidden; position: relative; } div.imageslider ul { Change left list-style-type: none; position: relative; value to move left: 0; the slider top: 0; } div.imageslider ul li { float: left; }
  • 34. Image slider JavaScript • Get the image slider container • Find out how many images there are • Get the width of the images • For each button click, move the slider to the proper position: (current image number) x (width of images)
  • 35. Add module settings Easy to add, easy to change
  • 36. Tips for using CSS and JavaScript with Drupal
  • 37. CSS and JavaScript Load only where needed
  • 39. “Auto Attach” Runs your JavaScript if JavaScript is available and when everything is ready. // Global Killswitch if (Drupal.jsEnabled) { $(document).ready(Drupal.imageslider.autoAttach); }
  • 40. Use Drupal.settings Drupal can output settings that can be easily read in your JavaScript: In PHP: drupal_add_js(array( 'imageslider' => array( 'easeFunc' => variable_get('imageslider_ease_func', ''), 'easeTime' => variable_get('imageslider_ease_time', 750) ) ), 'setting'); In JavaScript: var easeTime = Drupal.settings.imageslider.eastTime;
  • 41. Adding JavaScript Follow good naming conventions
  • 42. Naming Conventions Typically lower/upper , but just be consistent with Drupal and jQuery, or whatever JS libraries you work with. var box = getBox(); var newBoxHeight = 20; box.setHeight(newBoxHeight);
  • 43. Adding JavaScript Use proper namespacing
  • 44. JavaScript Namespacing What’s wrong with this? for (i = 0; i < 5; i++) { // do something }
  • 45. JavaScript Namespacing Using undefined variables clutters the global namespace!
  • 46. JavaScript Namespacing Define every variable! for (var i = 0; i < 5; i++) { // do something }
  • 47. JavaScript Namespacing Namespace everything. Even JavaScript functions will overwrite each other: function test() { alert('foo'); } overwritten! function test() { alert('bar'); } test();
  • 48. JavaScript Namespacing An example of proper namespacing: var Drupal = Drupal || {}; Drupal.extend = function(obj) { ... } Drupal.dimensions = function (el) { ... }
  • 49. Adding JavaScript Learn to understand scope
  • 50. Understanding Scope Simple Example of jQuery scope: function autoAttach() { var settings = { foo: 'bar' }; jQuery(quot;aquot;).mouseover(function() { alert(settings.foo); }); }
  • 51. Understanding Scope Using a separate function for handlers function autoAttach() { var settings = { foo: 'bar' }; jQuery(quot;aquot;).mouseover(function() { onOver.call(settings); }); } function onOver() { // 'this' is the settings object alert(this.foo); }
  • 52. Understanding Scope Passing additional variables with ‘call’ function autoAttach() { var settings = { foo: 'bar' }; jQuery(quot;aquot;).mouseover(function(evt) { onOver.call(settings, evt); }); } function onOver(evt) { // 'this' is the settings object alert(this.foo); }
  • 53. Tools • Firefox with Firebug • Aptana Studio • Opera Developer Tools • IE Developer Toolbar • Windows (for testing)
  • 54. New Drupal.org Releases • http://drupal.org/project/flickrapi • http://drupal.org/project/flickrsync • http://drupal.org/project/imageslider