drupal front-end

91
Drupal front-end Marek Sotak a Bohdan Ganicky

Upload: atomic-ant-ltd

Post on 17-Jan-2015

4.497 views

Category:

Technology


2 download

DESCRIPTION

Presentation held at Drupalcamp Bratislava 2010.

TRANSCRIPT

Page 1: Drupal Front-end

Drupal front-end

Marek Sotak a Bohdan Ganicky

Page 2: Drupal Front-end

Představení

Marek SotakDeveloper, designer

co-founder of atomic ant ltd web design company based in London, Prague and Denmark, operates internationaly.

Creator of RootCandy admin theme

http://drupal.org/project/rootcandy

@sotak –http://twitter.com/sotak

Bohdan GanickyFront-end developer

Part of the atomic ant team since 2009. Responsible for magic things.

@bganicky – http://twitter.com/bganicky

Page 3: Drupal Front-end

Šablonování – theming – Drupal 6

Šablona = prezentační vrstva oddělená od kóduNemusíme zasahovat do modulů, když chceme přepsat

výstup (mark-up)

PHPTemplate engine (Smarty, xtemplate, atd...)

Ukládáme do sites/*/themes/moje-sablona

Page 4: Drupal Front-end
Page 5: Drupal Front-end
Page 6: Drupal Front-end
Page 7: Drupal Front-end
Page 8: Drupal Front-end

Anatomie šablony

Page 9: Drupal Front-end
Page 10: Drupal Front-end
Page 11: Drupal Front-end
Page 12: Drupal Front-end
Page 13: Drupal Front-end
Page 14: Drupal Front-end
Page 15: Drupal Front-end
Page 16: Drupal Front-end
Page 17: Drupal Front-end
Page 18: Drupal Front-end
Page 19: Drupal Front-end
Page 20: Drupal Front-end
Page 21: Drupal Front-end
Page 22: Drupal Front-end
Page 23: Drupal Front-end
Page 24: Drupal Front-end
Page 25: Drupal Front-end
Page 26: Drupal Front-end
Page 27: Drupal Front-end
Page 28: Drupal Front-end
Page 29: Drupal Front-end
Page 30: Drupal Front-end
Page 31: Drupal Front-end
Page 32: Drupal Front-end
Page 33: Drupal Front-end
Page 34: Drupal Front-end
Page 35: Drupal Front-end
Page 36: Drupal Front-end
Page 37: Drupal Front-end
Page 38: Drupal Front-end
Page 39: Drupal Front-end
Page 40: Drupal Front-end
Page 41: Drupal Front-end
Page 42: Drupal Front-end
Page 43: Drupal Front-end
Page 44: Drupal Front-end
Page 45: Drupal Front-end
Page 46: Drupal Front-end
Page 47: Drupal Front-end
Page 48: Drupal Front-end

Generování stránky – suggestions + preprocess

Page 49: Drupal Front-end

theme('hook', $arguments)

theme_breadcrumb, skolavafrice_links,...

Definováno v hook_theme()function search_theme() {

return array(

'search_theme_form' => array(

'arguments' => array('form' => NULL),

'template' => 'search-theme-form',

),

);

}

Page 50: Drupal Front-end

hook = funkce – suggestions

nazevSablony_hook($arguments)skolavafrice_breadcrumbs($arguments)

engineName_hook($arguments)phptemplate_hook($arguments)

theme_hook($aguments)

Page 51: Drupal Front-end

hook = template – suggestions

Převést $arguments $variables→

Hledání render funkce (theme_render_template)

Hledání funkce pro zjištění připony (.tpl.php)

$variables se předávají referencí

Page 52: Drupal Front-end

hook = template – suggestions

template_preprocess

template_preprocess_hook

moduleName_preprocess

moduleName_preprocess_hook

engineName_engine_preprocess

engineName_engine_preprocess_hook

Page 53: Drupal Front-end

hook = template – suggestions

engineName_preprocess

engineName_preprocess_hook

themeName_preprocess

themeName_preprocess_hook

Sesbírané návrhy

Najdi implementované funkce (drupal_discover_template)

Page 54: Drupal Front-end

hook = template – suggestions

theme_render_template

Poskládat .tpl.php

navrh.tpl.php

nebo fallback

hook.tpl.php

Page 55: Drupal Front-end

Sub-theming – šablony v šabloně

Stačí .info soubor s hodnotoubase theme = ninesixty

Můžou sdílet některé soubory z hlavní šablonyCSS, js, .tpl.php, přepsané funkce z template.php

Nesdílítheme-settings.php, logo, color, některá nast. z .info

Page 56: Drupal Front-end

Sub-theming – jak na to

Vytvořte novou složku v sites/*/themes s názvem vaší šablony – eg. sites/all/themes/skolavafrice

Přidejte .info soubor se základními vlastnostmi – name, description,...

Přidejte “base theme = ninesixty” do .info souboru

Hotovo

Subtheming quick and dirty - http://drupal.org/node/441088

Page 57: Drupal Front-end

Užitečné tipy

DrupalContrib.orghttp://drupalcontrib.org

admin/settings/performanceOptimalizace css + js souborů

Base themesZen, Ninesixty, Genesis,... http://drupal.org/project/Themes

Page 58: Drupal Front-end

Užitečné tipy

Themer modulehttp://drupal.org/project/devel_themer

Firebug – firefox extension - http://getfirebug.com/

Page 59: Drupal Front-end

Odkazy

Theming handbook d.o - Drupal 6http://drupal.org/theme-guide

Drupal 6.x 7.x guide→http://drupal.org/update/theme/6/7

Mailing listhttp://drupal.org/mailing-lists

Theme garden - http://themegarden.org

IRC #drupal-themes

Page 60: Drupal Front-end

Drupal a JavaScript

jQuery

Page 61: Drupal Front-end

jQuery?

Javascriptová knihovna (nejpopulárnější)

Abstrakce JS do srozumitelného API

Řeší rozdíly implementace JS v různých prohlížečích

Přidává vlastní funkcionalitu (např. animace)

Usnadňuje nám práci

Page 62: Drupal Front-end

Ukázka<ul>

<li>Joomla</li>

<li>Drupal</li>

<li>Wordpress</li>

</ul>

<ul>

<li>Prototype</li>

<li>jQuery</li>

<li>Dojo</li>

</ul>

Page 63: Drupal Front-end

Ukázka<ul>

<li class=”odd”>Joomla</li>

<li>Drupal</li>

<li class=”odd”>Wordpress</li>

</ul>

<ul>

<li class=”odd”>Prototype</li>

<li>jQuery</li>

<li class=”odd”>Dojo</li>

</ul>

Page 64: Drupal Front-end

Před

var lists = document.getElementsByTagName('ul');

for (var i = 0; i < lists.length; i++) {

var items = lists[i].getElementsByTagName('li');

for (var j = 1; j < items.length; j += 2) {

if (!/(^|s)odd(s|$)/.test(items[i].className)) {

rows[i].className += ' odd';

}

}

}

Page 65: Drupal Front-end

Po

$('ul li:nth-child(odd)').addClass('odd');

demo

Page 66: Drupal Front-end

Základní koncept

$('ul li:nth-child(odd)').addClass('odd');

Něco najdi . . .

. . .něco s t ím udělej .

Page 67: Drupal Front-end

Základní koncept

$('ul li:nth-child(odd)').addClass('odd');

CSS selektor (CSS3)

jQuery metoda

Page 68: Drupal Front-end

$ == jQuery

$('ul li:nth-child(odd)').addClass('odd');

Page 69: Drupal Front-end

$ == jQuery

jQuery('ul li:nth-child(odd)').addClass('odd');

Page 70: Drupal Front-end

CSS selektory...

Všechny pokročilé selektory včetně CSS3$('div p'), $('div > p')

$('div ~ p'), $('div + p')

$('div p:first-child'), $('div p:last-child')

$('div p:only-child'), $('div p:nth-child(2)')

...a mnoho dalších

Page 71: Drupal Front-end

+ filtry

$(“li:odd”), $(“li:even”)

$(“li:first”), $(“li:last”)

$(“input:checked”), $(“input:not(:checked)”)

$(“div:contains('Drupal')”), $(“div:has(ul)”)

$(“div:hidden”), $(“div:visible”)

...a mnoho dalších

http://api.jquery.com/category/selectors/

Page 72: Drupal Front-end

Řetězení metod

$('ul li:nth-child(odd)').addClass('odd').append(“I'm odd”).fadeOut(“slow”);

demo

Page 73: Drupal Front-end

jQuery API

● http://api.jquery.com● http://www.futurecolors.ru/jquery/

Page 74: Drupal Front-end

Rozšíření pro jQuery - plugins

stěžejní vlastnost jQuery → http://plugins.jquery.com

$.fn.showLinkTarget = function() {

return this.each(function() {

console.log(this.href);});

}

$(“a”).showLinkTarget(); demo

Page 75: Drupal Front-end

$(document).ready();

Událost nastane 1x běhěm načtení dokumentu→

V daný moment máme k dispozici celý DOM a můžeme s ním začít manipulovat

Netýká se obrázků! $(window).load();→

$(document).ready(function() {

alert('Dokument je připraven.');

});

Page 76: Drupal Front-end

Progressive enhancement

3 vrstvy

Obsah (html) prezentace (css) chování (js)→ →

Jedna nezávislá na druhé pokud možno co nejmenší →třecí zóny

JQuery ideální nástroj pro PE!→

Page 77: Drupal Front-end

Verze jQuery

Drupal 5.x jQuery 1.0.x ( 1.0.4)→ →

Drupal 6.x jQuery 1.2.x ( 1.2.6)→ →

Drupal 7.x snad jQuery 1.4.x →http://drupal.org/node/653580

Page 78: Drupal Front-end

Modul “jQuery update”

http://drupal.org/project/jquery_update

Drupal 5.x jQuery 1.2.6→

Drupal 6.x jQuery 1.3.2 (dev verze)→

Page 79: Drupal Front-end

Jak začít?

Čeho chci dosáhnout?

Neudělal to už někdo za mě? (viz plugins)

Neexistuje dokonce řešení ve formě Drupal modulu? (viz jCarousel či Lightbox2)

Nic z výše uvedeného? →

Page 80: Drupal Front-end

page.tpl.php

<?php print $scripts; ?>

Page 81: Drupal Front-end

Soubor .info

● Drupal automaticky vezme soubor script.js v kořenovém adresáři tématu.

● Pokud chceme použít jiný název či umístění, pak upravíme .info soubor:

...

stylesheets[all][] = my_style.css

scripts[] = js/my_script.js

...

Page 82: Drupal Front-end

Soubor .info

● Drupal automaticky vezme soubor script.js v kořenovém adresáři tématu.

● Pokud chceme použít jiný název či umístění, pak upravíme .info soubor:

...

stylesheets[all][] = my_style.css

scripts[] = js/jquery.plugin.js

scripts[] = js/my_script.js

...

Page 83: Drupal Front-end

Automatické změny v HTML

<html class=”js” ...>

<script type=”text/javascript” src=”jquery.js”>

<script type=”text/javascript” src=”drupal.js”>

<script type=”text/javascript” src=”my_script.js”>

Page 84: Drupal Front-end

<html class=”js” ...>

Opomíjená třída

Důležité pro stylování prvků s nimiž nějak manipulujeme přes JS/jQuery

Místo v .js:$(document).ready(function() {

$('#something').hide();

});

● použijeme CSS: .js #something { display: none; }

Page 85: Drupal Front-end

function fancyLogin() {var $login_block = $('#block-user-0');var $target = $('.top-navigation .item-list .first');var $trigger = $target.find('a').click(function() {

if ($login_block.is(':visible')) {$login_block.add($overlay).fadeOut();return false;

}else {

$login_block.add($overlay).fadeIn();$('#edit-name').focus();return false;

}});var $overlay = $('<div id="overlay">').appendTo('body').click(function() {

$trigger.trigger('click');});

$login_block.appendTo($target);}

$(document).ready(fancyLogin);

Page 86: Drupal Front-end

Nástroje

Firebug pro Firefox: http://getfirebug.com/

Developer Tools v Google Chrome

IE8 Developer Tools

http://jsbin.com/

http://james.padolsey.com/jquery/

http://www.woods.iki.fi/interactive-jquery-tester.html

Page 87: Drupal Front-end

Odkazy

http://jquery.com

http://api.jquery.com

http://www.futurecolors.ru/jquery/

Page 89: Drupal Front-end

Otázky?

Page 90: Drupal Front-end

Děkujeme za pozornost!

Page 91: Drupal Front-end

Credits

Slide 4 by Medical Student on flickr

Slide 44 - http://web.mac.com/moistproduction/flash/index.html

Slide 60 by poopoorama on flickr

Website preview: http://skolavafrice.cz