SlideShare una empresa de Scribd logo
1 de 45
Descargar para leer sin conexión
jQuery UI in Drupal 7
              Darren Mothersele @mothersele
             http://www.darrenmothersele.com




Ivan Sutherland's Sketchpad system is demonstrated on the console of the TX-2 at MIT (1963)
jQuery UI in Drupal 7

• Using Javascript to improve UI
• Javascript in Drupal 7
• jQuery UI widgets
• Building complex interactions
HTML + Javascript

• HTML defines a set of standard form elements
• Javascript allows us to build new interactive widgets
• jQuery UI provides widgets, interactions and effects
Javascript widgets

• Reduce errors in data entry
• Quicker/more efficient
• More engaging/fun
• ...
Progressive Enhancement

 • Create widget using jQuery
 • Hide old widget
 • Fill in value in the background
 • Transparent to Drupal, nice and safe
 • Non-js friendly
Before Active Tags


• Multiple tagging methodologies
• Some people just expect to use spaces
• http://drupal.org/node/91074
• Character-delimited system
Active Tags


•   Action-delimited system
•   Autocomplete
•   Original widget hidden
•   http://drupal.org/project/active_tags
Javascript in Drupal 7

• Theme or Module?
• Scope?
• Module specific or reuseable?
  (Javascript Library)
• How and where to include code?
theme.info
name = My theme
description = Theme developed by me.
core = 7.x
engine = phptemplate
scripts[] = my_script.js
drupal_add_js($data, $options)

 $data is either:
  • path to Javascript file to include
  • Javascript code to include ‘inline’
  • absolute path to external JS code
  • array of settings for Javascript
 $options includes type, location, caching, ...
hook_preprocess_page()
function mytheme_preprocess_page(&$vars, $hook) {

    if (true) {

        drupal_add_js(
          drupal_get_path('theme', 'mytheme') . '/scriptname.js',
          'theme');

        $vars['scripts'] = drupal_get_js();

    }

}
hook_library()

• Used in Core for jQuery UI
• Use to include other third-party plugins
• Define your own reusable Javascript
jQuery UI Buttons
Dialog Example
function dproj_form_user_login_block_alter(&$form, $form_state) {

    drupal_add_library('system', 'ui.dialog');

    $dialog_js =
      '$("#block-user-login").dialog({title: "User login"});';

    $dialog_js =
      'jQuery(document).ready(function () { (function ($) {' .
      $dialog_js . '}(jQuery)); });';

    drupal_add_js($dialog_js,
      array('type' => 'inline', 'scope' => 'footer',
        'weight' => 5));

}
id="edit-field-issue-type-und"



$("#edit-field-issue-type-und").buttonset();
drupal_add_library()
function dproj_form_issue_node_form_alter(&$form, $form_state,
$form_id) {
    $language = $form['#node']->language;
    $form['field_issue_type'][$language]['#after_build'][] =
                                         '_dproj_button_helper';
}

function _dproj_button_helper($element, &$form_state) {
    $button_js = '$("#'. $element['#id'] .'").buttonset();';
    $button_js = JS_PREFIX . $button_js . JS_SUFFIX;
    drupal_add_library('system', 'ui.button');
  drupal_add_js($button_js, array('type' => 'inline', 'scope' =>
'footer', 'weight' => 5));
    return $element;
}
https://github.com/padolsey/jQuery.fn.autoResize
hook_library()
function dproj_library() {

    $path = drupal_get_path('module', 'dproj');

    return array('autoresize' =>     array(

      'title' => 'AutoResize',

      'website' => 'https://github.com/...'

      'version' => '1.14',

      'js' => array(

           $path .'/jquery.autoresize.js' => array(),

      ),

    ));

}
id="edit-field-project-desc-und-0-value"




$("#edit-field-project-desc-und-0-value").autoResize();
function dproj_form_project_node_form_alter(&$form,
$form_state, $form_id) {

    $language = $form['#node']->language;

    $form['field_project_desc'][$language]['#after_build'][]

      = '_dproj_autoresize_helper';

}

function _dproj_autoresize_helper($element, &$form_state) {

    $id = $element[0]['value']['#id']

    $autoresize_js = '$("#'. $id .'").autoResize();';

    $autoresize_js = JS_PREFIX . $autoresize_js . JS_SUFFIX;

    drupal_add_library('dproj', 'autoresize');

    drupal_add_js($autoresize_js, array('type' => 'inline',
      'scope' => 'footer', 'weight' => 5));

    return $element;

}
Building a more
  complex interaction
• Drupal Behaviors
• jQuery ui.draggable
• jQuery ui.droppable
• jQuery AJAX
• Contrib modules:
  Page manager (ctools), Rules, Relation
Behaviors
• Replacement for $(document).ready();
• Use attach function:
   (function ($) {

     Drupal.behaviors.exampleModule = {
       attach: function (context, settings) {

              $('.dproj', context).draggable();

          }
     };

   }(jQuery));

• AJAX safe
• Detachable
Drag and Drop
Draggable


                          Droppable




               $.ajax()
    Callback
.dproj-draggable




              .dproj-droppable



$('.dproj-draggable').draggable();
$('.dproj-droppable').droppable();
path1 =
      add-attendee/[uid]




           path2 =
            /[nid]



     callback = path1 + path2
callback = add-attendee/[uid]/[nid]
Callback argument
inserted into header
<span class='callback'>
  add-attendee/1
</span>




   <span class='callback'>/20</span>




callback = add-attendee/1/20
Drupal.behaviors.dprojdrag = {
  attach: function (context, settings) {
    $('.dproj-draggable', context).draggable({revert: 'invalid'});
    $('.dproj-droppable', context).droppable({
      hoverClass: 'drop-hover',      accept: '.dproj-draggable',
      drop: function (e, ui) {
        $(ui.draggable).hide();
        $(e.target).fadeTo('fast', 0.5);
        var view_id = '.' +
          $(e.target).attr('class').match(/view-dom-id-d+/)[0];
        var href = Drupal.settings.basePath +
          $('.callback', ui.draggable).html()
          + $('.callback', e.target).html();
        $.ajax({ url: href,
                 success: function (data) {
                 $(view_id).html($(view_id, $(data)));
                  $(view_id).fadeTo('fast', 1);
}});}});}};
Resources
•   jQuery UI                 •   Contrib Modules
    http://jqueryui.com/
    demos                         •   Views

•   Managing Javascript in        •   Relation
    Drupal 7
    http://drupal.org/node/
    756722
                                  •   Page manager

                                  •   Rules

Más contenido relacionado

La actualidad más candente

La actualidad más candente (18)

Jquery In Rails
Jquery In RailsJquery In Rails
Jquery In Rails
 
15. CodeIgniter editarea inregistrarilor
15. CodeIgniter editarea inregistrarilor15. CodeIgniter editarea inregistrarilor
15. CodeIgniter editarea inregistrarilor
 
DrupalCamp Foz - Novas APIs Drupal 7
DrupalCamp Foz - Novas APIs Drupal 7DrupalCamp Foz - Novas APIs Drupal 7
DrupalCamp Foz - Novas APIs Drupal 7
 
Magento Dependency Injection
Magento Dependency InjectionMagento Dependency Injection
Magento Dependency Injection
 
Django at the Disco
Django at the DiscoDjango at the Disco
Django at the Disco
 
Django at the Disco
Django at the DiscoDjango at the Disco
Django at the Disco
 
Building iPhone Web Apps using "classic" Domino
Building iPhone Web Apps using "classic" DominoBuilding iPhone Web Apps using "classic" Domino
Building iPhone Web Apps using "classic" Domino
 
8. vederea inregistrarilor
8. vederea inregistrarilor8. vederea inregistrarilor
8. vederea inregistrarilor
 
Coding website
Coding websiteCoding website
Coding website
 
HirshHorn theme: how I created it
HirshHorn theme: how I created itHirshHorn theme: how I created it
HirshHorn theme: how I created it
 
Command-Oriented Architecture
Command-Oriented ArchitectureCommand-Oriented Architecture
Command-Oriented Architecture
 
Propel sfugmd
Propel sfugmdPropel sfugmd
Propel sfugmd
 
Mysocial databasequeries
Mysocial databasequeriesMysocial databasequeries
Mysocial databasequeries
 
Mysocial databasequeries
Mysocial databasequeriesMysocial databasequeries
Mysocial databasequeries
 
Pagination in PHP
Pagination in PHPPagination in PHP
Pagination in PHP
 
Add edit delete in Codeigniter in PHP
Add edit delete in Codeigniter in PHPAdd edit delete in Codeigniter in PHP
Add edit delete in Codeigniter in PHP
 
Daily notes
Daily notesDaily notes
Daily notes
 
Country State City Dropdown in PHP
Country State City Dropdown in PHPCountry State City Dropdown in PHP
Country State City Dropdown in PHP
 

Similar a jQuery UI Widgets, Drag and Drop, Drupal 7 Javascript

JQuery In Drupal
JQuery In DrupalJQuery In Drupal
JQuery In Drupalkatbailey
 
What's new in the Drupal 7 API?
What's new in the Drupal 7 API?What's new in the Drupal 7 API?
What's new in the Drupal 7 API?Alexandru Badiu
 
Drupal Javascript for developers
Drupal Javascript for developersDrupal Javascript for developers
Drupal Javascript for developersDream Production AG
 
Taming that client side mess with Backbone.js
Taming that client side mess with Backbone.jsTaming that client side mess with Backbone.js
Taming that client side mess with Backbone.jsJarod Ferguson
 
Your Entity, Your Code
Your Entity, Your CodeYour Entity, Your Code
Your Entity, Your CodeDrupalDay
 
Learning the basics of the Drupal API
Learning the basics of the Drupal APILearning the basics of the Drupal API
Learning the basics of the Drupal APIAlexandru Badiu
 
Drupal Module Development - OSI Days 2010
Drupal Module Development - OSI Days 2010Drupal Module Development - OSI Days 2010
Drupal Module Development - OSI Days 2010Siva Epari
 
Drupal Module Development
Drupal Module DevelopmentDrupal Module Development
Drupal Module Developmentipsitamishra
 
Debugging in drupal 8
Debugging in drupal 8Debugging in drupal 8
Debugging in drupal 8Allie Jones
 
Routing in Drupal 8
Routing in Drupal 8Routing in Drupal 8
Routing in Drupal 8kgoel1
 
Drupal & javascript
Drupal & javascriptDrupal & javascript
Drupal & javascriptAlmog Baku
 
Javascript first-class citizenery
Javascript first-class citizeneryJavascript first-class citizenery
Javascript first-class citizenerytoddbr
 
international PHP2011_Bastian Feder_jQuery's Secrets
international PHP2011_Bastian Feder_jQuery's Secretsinternational PHP2011_Bastian Feder_jQuery's Secrets
international PHP2011_Bastian Feder_jQuery's Secretssmueller_sandsmedia
 
Php on the desktop and php gtk2
Php on the desktop and php gtk2Php on the desktop and php gtk2
Php on the desktop and php gtk2Elizabeth Smith
 
Nickolay Shmalenuk.Render api eng.DrupalCamp Kyiv 2011
Nickolay Shmalenuk.Render api eng.DrupalCamp Kyiv 2011Nickolay Shmalenuk.Render api eng.DrupalCamp Kyiv 2011
Nickolay Shmalenuk.Render api eng.DrupalCamp Kyiv 2011camp_drupal_ua
 
Building Large jQuery Applications
Building Large jQuery ApplicationsBuilding Large jQuery Applications
Building Large jQuery ApplicationsRebecca Murphey
 
How I Learned to Stop Worrying and Love jQuery (Jan 2013)
How I Learned to Stop Worrying and Love jQuery (Jan 2013)How I Learned to Stop Worrying and Love jQuery (Jan 2013)
How I Learned to Stop Worrying and Love jQuery (Jan 2013)David Giard
 

Similar a jQuery UI Widgets, Drag and Drop, Drupal 7 Javascript (20)

JQuery In Drupal
JQuery In DrupalJQuery In Drupal
JQuery In Drupal
 
What's new in the Drupal 7 API?
What's new in the Drupal 7 API?What's new in the Drupal 7 API?
What's new in the Drupal 7 API?
 
Drupal 8 migrate!
Drupal 8 migrate!Drupal 8 migrate!
Drupal 8 migrate!
 
Drupal Javascript for developers
Drupal Javascript for developersDrupal Javascript for developers
Drupal Javascript for developers
 
Taming that client side mess with Backbone.js
Taming that client side mess with Backbone.jsTaming that client side mess with Backbone.js
Taming that client side mess with Backbone.js
 
Your Entity, Your Code
Your Entity, Your CodeYour Entity, Your Code
Your Entity, Your Code
 
Learning the basics of the Drupal API
Learning the basics of the Drupal APILearning the basics of the Drupal API
Learning the basics of the Drupal API
 
Drupal Module Development - OSI Days 2010
Drupal Module Development - OSI Days 2010Drupal Module Development - OSI Days 2010
Drupal Module Development - OSI Days 2010
 
Drupal Module Development
Drupal Module DevelopmentDrupal Module Development
Drupal Module Development
 
Debugging in drupal 8
Debugging in drupal 8Debugging in drupal 8
Debugging in drupal 8
 
Routing in Drupal 8
Routing in Drupal 8Routing in Drupal 8
Routing in Drupal 8
 
Drupal & javascript
Drupal & javascriptDrupal & javascript
Drupal & javascript
 
Javascript first-class citizenery
Javascript first-class citizeneryJavascript first-class citizenery
Javascript first-class citizenery
 
international PHP2011_Bastian Feder_jQuery's Secrets
international PHP2011_Bastian Feder_jQuery's Secretsinternational PHP2011_Bastian Feder_jQuery's Secrets
international PHP2011_Bastian Feder_jQuery's Secrets
 
Jquery fundamentals
Jquery fundamentalsJquery fundamentals
Jquery fundamentals
 
Php on the desktop and php gtk2
Php on the desktop and php gtk2Php on the desktop and php gtk2
Php on the desktop and php gtk2
 
Nickolay Shmalenuk.Render api eng.DrupalCamp Kyiv 2011
Nickolay Shmalenuk.Render api eng.DrupalCamp Kyiv 2011Nickolay Shmalenuk.Render api eng.DrupalCamp Kyiv 2011
Nickolay Shmalenuk.Render api eng.DrupalCamp Kyiv 2011
 
Building Large jQuery Applications
Building Large jQuery ApplicationsBuilding Large jQuery Applications
Building Large jQuery Applications
 
How I Learned to Stop Worrying and Love jQuery (Jan 2013)
How I Learned to Stop Worrying and Love jQuery (Jan 2013)How I Learned to Stop Worrying and Love jQuery (Jan 2013)
How I Learned to Stop Worrying and Love jQuery (Jan 2013)
 
jQuery secrets
jQuery secretsjQuery secrets
jQuery secrets
 

Último

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
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integrationmarketing932765
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
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
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observabilityitnewsafrica
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
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
 
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
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...itnewsafrica
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Kaya Weers
 
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
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...itnewsafrica
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 

Último (20)

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
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
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
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
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
 
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
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)
 
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
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 

jQuery UI Widgets, Drag and Drop, Drupal 7 Javascript

  • 1. jQuery UI in Drupal 7 Darren Mothersele @mothersele http://www.darrenmothersele.com Ivan Sutherland's Sketchpad system is demonstrated on the console of the TX-2 at MIT (1963)
  • 2. jQuery UI in Drupal 7 • Using Javascript to improve UI • Javascript in Drupal 7 • jQuery UI widgets • Building complex interactions
  • 3. HTML + Javascript • HTML defines a set of standard form elements • Javascript allows us to build new interactive widgets • jQuery UI provides widgets, interactions and effects
  • 4. Javascript widgets • Reduce errors in data entry • Quicker/more efficient • More engaging/fun • ...
  • 5.
  • 6. Progressive Enhancement • Create widget using jQuery • Hide old widget • Fill in value in the background • Transparent to Drupal, nice and safe • Non-js friendly
  • 7. Before Active Tags • Multiple tagging methodologies • Some people just expect to use spaces • http://drupal.org/node/91074 • Character-delimited system
  • 8. Active Tags • Action-delimited system • Autocomplete • Original widget hidden • http://drupal.org/project/active_tags
  • 9. Javascript in Drupal 7 • Theme or Module? • Scope? • Module specific or reuseable? (Javascript Library) • How and where to include code?
  • 10. theme.info name = My theme description = Theme developed by me. core = 7.x engine = phptemplate scripts[] = my_script.js
  • 11. drupal_add_js($data, $options) $data is either: • path to Javascript file to include • Javascript code to include ‘inline’ • absolute path to external JS code • array of settings for Javascript $options includes type, location, caching, ...
  • 12. hook_preprocess_page() function mytheme_preprocess_page(&$vars, $hook) { if (true) { drupal_add_js( drupal_get_path('theme', 'mytheme') . '/scriptname.js', 'theme'); $vars['scripts'] = drupal_get_js(); } }
  • 13. hook_library() • Used in Core for jQuery UI • Use to include other third-party plugins • Define your own reusable Javascript
  • 15.
  • 16. Dialog Example function dproj_form_user_login_block_alter(&$form, $form_state) { drupal_add_library('system', 'ui.dialog'); $dialog_js = '$("#block-user-login").dialog({title: "User login"});'; $dialog_js = 'jQuery(document).ready(function () { (function ($) {' . $dialog_js . '}(jQuery)); });'; drupal_add_js($dialog_js, array('type' => 'inline', 'scope' => 'footer', 'weight' => 5)); }
  • 17.
  • 19. drupal_add_library() function dproj_form_issue_node_form_alter(&$form, $form_state, $form_id) { $language = $form['#node']->language; $form['field_issue_type'][$language]['#after_build'][] = '_dproj_button_helper'; } function _dproj_button_helper($element, &$form_state) { $button_js = '$("#'. $element['#id'] .'").buttonset();'; $button_js = JS_PREFIX . $button_js . JS_SUFFIX; drupal_add_library('system', 'ui.button'); drupal_add_js($button_js, array('type' => 'inline', 'scope' => 'footer', 'weight' => 5)); return $element; }
  • 20.
  • 22. hook_library() function dproj_library() { $path = drupal_get_path('module', 'dproj'); return array('autoresize' => array( 'title' => 'AutoResize', 'website' => 'https://github.com/...' 'version' => '1.14', 'js' => array( $path .'/jquery.autoresize.js' => array(), ), )); }
  • 24. function dproj_form_project_node_form_alter(&$form, $form_state, $form_id) { $language = $form['#node']->language; $form['field_project_desc'][$language]['#after_build'][] = '_dproj_autoresize_helper'; } function _dproj_autoresize_helper($element, &$form_state) { $id = $element[0]['value']['#id'] $autoresize_js = '$("#'. $id .'").autoResize();'; $autoresize_js = JS_PREFIX . $autoresize_js . JS_SUFFIX; drupal_add_library('dproj', 'autoresize'); drupal_add_js($autoresize_js, array('type' => 'inline', 'scope' => 'footer', 'weight' => 5)); return $element; }
  • 25.
  • 26. Building a more complex interaction • Drupal Behaviors • jQuery ui.draggable • jQuery ui.droppable • jQuery AJAX • Contrib modules: Page manager (ctools), Rules, Relation
  • 27. Behaviors • Replacement for $(document).ready(); • Use attach function: (function ($) { Drupal.behaviors.exampleModule = { attach: function (context, settings) { $('.dproj', context).draggable(); } }; }(jQuery)); • AJAX safe • Detachable
  • 28. Drag and Drop Draggable Droppable $.ajax() Callback
  • 29.
  • 30. .dproj-draggable .dproj-droppable $('.dproj-draggable').draggable(); $('.dproj-droppable').droppable();
  • 31. path1 = add-attendee/[uid] path2 = /[nid] callback = path1 + path2 callback = add-attendee/[uid]/[nid]
  • 32.
  • 34.
  • 35. <span class='callback'> add-attendee/1 </span> <span class='callback'>/20</span> callback = add-attendee/1/20
  • 36. Drupal.behaviors.dprojdrag = { attach: function (context, settings) { $('.dproj-draggable', context).draggable({revert: 'invalid'}); $('.dproj-droppable', context).droppable({ hoverClass: 'drop-hover', accept: '.dproj-draggable', drop: function (e, ui) { $(ui.draggable).hide(); $(e.target).fadeTo('fast', 0.5); var view_id = '.' + $(e.target).attr('class').match(/view-dom-id-d+/)[0]; var href = Drupal.settings.basePath + $('.callback', ui.draggable).html() + $('.callback', e.target).html(); $.ajax({ url: href, success: function (data) { $(view_id).html($(view_id, $(data))); $(view_id).fadeTo('fast', 1); }});}});}};
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45. Resources • jQuery UI • Contrib Modules http://jqueryui.com/ demos • Views • Managing Javascript in • Relation Drupal 7 http://drupal.org/node/ 756722 • Page manager • Rules