• No results found

729G26 Interaction programming. Lecture 4

N/A
N/A
Protected

Academic year: 2021

Share "729G26 Interaction programming. Lecture 4"

Copied!
39
0
0

Loading.... (view fulltext now)

Full text

(1)

729G26 Interaction programming

Lecture 4

(2)

Lecture overview

⁃ Project reminder

⁃ Assignment 4

⁃ API documentation

⁃ jQuery UI

What is it? How do I set it up?

Widgets: How do I use them?

Interaction: Drag and drop

⁃ Using plugins/third party scripts

⁃ Github

(3)

Project

Deliverables

GUI Analysis (Gold, Silver, Bronze) Specification (Gold, Silver, Bronze) Implementation

Review session for GUI analysis and Specification

Deadlines: See course web page

(4)
(5)

Todays lecture in the context of the course

Knowing how to approach and read API documentation is a core programming skill.

⁃ jQuery UI makes it easier to create standard UI components.

⁃ jQuery plugins extend the functionality of jQuery.

⁃ Using standard UI components and using plugins written by other people will be very useful when you get to your

project!

Lots of web related stuff can be found on Github, you should not be afraid of it.

(6)

Assignment 4

⁃ You will use jQuery UI + plugins

⁃ Reading plugin documentation

⁃ Keeping track of jQuery and jQuery UI version requirements

⁃ Keeping your folders tidy

(7)

The API

⁃ API - Application Programming Interface

⁃ Specifies how to interact with software using code.

⁃ Think “GUI” for software.

(8)

Examples from the jQuery API

.attr() http://api.jquery.com/attr/

.animate() http://api.jquery.com/animate/

(9)

Return type is important!

Pay attention to parameter type!

(10)

Parameters in [brackets] are optional!

(11)

PlainObject

var cssPlainObject = {

width: "200px", height: "200px"

};

$(selector).animate(cssPlainObject);

A PlainObject has the form { attribute: value, attribute: value ... }

(12)
(13)

What is jQuery UI?

“jQuery UI is a widget and interaction library built on top of the jQuery JavaScript Library that you can use to build

highly interactive web applications.”

(14)

Example widgets

⁃ Accordion

⁃ Dialog

⁃ Date picker

⁃ Menu

⁃ Tooltip

(15)

Interactions

⁃ Draggable

⁃ Droppable

⁃ Resizable

⁃ Selectable

⁃ Sortable

(16)

jQuery UI setup

1. Link to jQuery UI CSS theme 2. Link to your own CSS

1. Link to jQuery library

2. Link to jQuery UI library 3. Link to your own JavaScript

(17)

jQuery UI themes

⁃ Different jQuery UI themes can be used.

⁃ A theme is a CSS.

⁃ Themes can be downloaded and created at
 http://jqueryui.com/themeroller/

(18)

Accordion example

https://trinket.io/html/0d9ed71d12

https://api.jqueryui.com/accordion/

(19)

Accordion

<div id="accordion">

<h3>Section 1</h3>

<div>

<p>Mauris mauris ante, blandit et, ultrices a, suscipit

eget, quam. Integer ut neque. Vivamus nisi metus, molestie vel, gravida in, condimentum sit amet, nunc.</p>

</div>

<h3>Section 2</h3>

<div>

<p>Sed non urna. Donec et ante. Phasellus eu ligula.

Vestibulum sit amet purus. Vivamus hendrerit, dolor at aliquet laoreet, mauris turpis porttitor velit, faucibus interdum

tellus libero ac justo.</p>

</div>

<h3>Section 3</h3>

<div>

<p>Nam enim risus, molestie et, porta ac, aliquam ac,

risus. Quisque lobortis. Phasellus pellentesque purus in massa.

Aenean in pede. Phasellus ac libero ac tellus pellentesque semper.</p>

<ul>

<li>List item one</li>

<li>List item two</li>

<li>List item three</li>

</ul>

</div>

<h3>Section 4</h3>

<div>

<p>Cras dictum. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.</p>

<p>Suspendisse eu nisl. Nullam ut libero. Integer dignissim consequat lectus.</p>

</div>

</div>

<script>

$(function() {

$( "#accordion" ).accordion();

});

</script>

<h3>Section 1</h3>

<div>

<p>Mauris mauris ante, blandit et,

ultrices a, suscipit eget, quam. Integer ut neque. Vivamus nisi metus, molestie vel,

gravida in, condimentum sit amet, nunc.</p>

</div>

(20)

Basic pattern to use jQuery UI element

1. Add content using specified structure

2. Add jQuery UI call in script, associating content with a jQuery widget:


$(selector).jQueryUIfunction()

(21)

Accordion

<div id="accordion">

<h3>Section 1</h3>

<div>

<p>Mauris mauris ante, blandit et, ultrices a, suscipit

eget, quam. Integer ut neque. Vivamus nisi metus, molestie vel, gravida in, condimentum sit amet, nunc.</p>

</div>

<h3>Section 2</h3>

<div>

<p>Sed non urna. Donec et ante. Phasellus eu ligula.

Vestibulum sit amet purus. Vivamus hendrerit, dolor at aliquet laoreet, mauris turpis porttitor velit, faucibus interdum

tellus libero ac justo.</p>

</div>

<h3>Section 3</h3>

<div>

<p>Nam enim risus, molestie et, porta ac, aliquam ac,

risus. Quisque lobortis. Phasellus pellentesque purus in massa.

Aenean in pede. Phasellus ac libero ac tellus pellentesque semper.</p>

<ul>

<li>List item one</li>

<li>List item two</li>

<li>List item three</li>

</ul>

</div>

<h3>Section 4</h3>

<div>

<p>Cras dictum. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.</p>

<p>Suspendisse eu nisl. Nullam ut libero. Integer dignissim consequat lectus.</p>

</div>

</div>

<script>

$(function() {

$( "#accordion" ).accordion();

});

</script>

<h3>Section 1</h3>

<div>

<p>Mauris mauris ante, blandit et,

ultrices a, suscipit eget, quam. Integer ut neque. Vivamus nisi metus, molestie vel,

gravida in, condimentum sit amet, nunc.</p>

</div>

(22)

jQuery UI Widgets: options, methods, events

Options

PlainObject passed on initialization

Methods

Call by passing a string to the jQuery UI function
 e.g.

$("#accordion").accordion("disable");

Events

Specify event handlers in options during init

(23)
(24)

Note: jQuery UI

events are not

ordinary events.

(25)

Menu example

https://trinket.io/html/fc3d097bd2

https://api.jqueryui.com/menu/

(26)

Tabs

https://trinket.io/html/c87c300c05

https://api.jqueryui.com/tabs/

(27)

jQuery UI demo site

https://jqueryui.com/demos/

Various widgets that share the jQuery UI theme

jQuery UI versions of common widgets Button

Slider Spinner

Selectmenu ...

Special purpose widgets Datepicker

Tooltip

(28)

jQuery UI widgets vs standard HTML widgets

⁃ HTML has incorporated more widgets in HTML5 increasing the overlap between with jQuery UI

⁃ jQuery UI widgets use the same theme

(29)

Drag and drop using jQuery

UI

(30)

Making something draggable

⁃ Call

$(selector).draggable()

(31)

Droppable - a target for something draggable

$( ".selector" ).droppable({

drop: function( event, ui ) {

// ui.draggable is the jQuery of the element dragged console.log(ui.draggable)

} });

The drop option specifies the function handler for the drop event.

UI is a plain object with the property draggable.

The drop target is $(this)

(32)

Drag and drop example

https://trinket.io/html/71ea1f4fcf

(33)

jQuery Plugins

(34)

jQuery plugins

⁃ jQuery plugins extend the functionality of jQuery using a pattern similar to jQuery UI

⁃ In fact, jQuery UI can be seen as a jQuery plugin.

(35)

Example plugins

⁃ roundSlider: https://roundsliderui.com/

⁃ jQuery Waypoints: http://imakewebthings.com/waypoints

⁃ AnimateScroll: http://plugins.compzets.com/animatescroll/

⁃ Animsion: http://git.blivesta.com/animsition/

⁃ Masonry: http://masonry.desandro.com/

⁃ Isotope: http://isotope.metafizzy.co/

(36)

Using a plugin

1. Find a plugin you want to use 2. Visit the plugin web page

3. Read the install guide 4. Download the plugin

5. Follow instructions either on the plugin web page or look for a README file in the unpacked archive.

(Your milage may vary)

(37)

Quick introduction to GitHub

http://www.github.com

(38)

github.com

⁃ Git software for distributed version control, i.e. managing different versions of files.

⁃ Versions are stored in repositories.

⁃ A repository can be local (on your computer) or remote

⁃ Github is a (remote) Git repository hosting service

browsing

issue tracking wiki pages

and more

(39)

A short glossary

node.js: JavaScript for server side use (backend)

npm: package manager and automation tool for node.js

bower: package manager (downloads and manages package dependencies)

gulp: workflow automation

Folders

dist: "distribution", use these files

src: source files used to build files for distribution

References

Related documents