Skip to content

Commit

Permalink
Hello world plugin example and fix #7788
Browse files Browse the repository at this point in the history
  • Loading branch information
duboisp committed Dec 7, 2016
1 parent cb29ce2 commit dccc9c7
Show file tree
Hide file tree
Showing 8 changed files with 779 additions and 2 deletions.
102 changes: 102 additions & 0 deletions site/pages/docs/ref/helloworld/helloworld-en.hbs
@@ -0,0 +1,102 @@
---
{
"title": "Hello world",
"language": "en",
"category": "Other",
"categoryfile": "other",
"description": "A quick tutorial on how you can create your own WET plugin.",
"altLangPrefix": "helloworld",
"dateModified": "2016-12-06"
}
---
<div class="wb-prettify all-pre hide"></div>

<section>
<h2>Purpose</h2>
<p>Learn on how to create a simple plugin for WET</p>
</section>

<section>
<h2>Working example</h2>
<ul>
<li><a href="../../../demos/helloworld/helloworld-en.html">English example</a></li>
<li><a href="../../../demos/helloworld/helloworld-fr.html" hreflang="fr">French example</a></li>
</ul>
</section>

<section>
<h2>Source code of <code>helloworld.js</code></h2>
<pre><code>/**
* @title WET-BOEW Hello world plugin
* @overview Plugin contained to show an example of how to create your custom WET plugin
* @license wet-boew.github.io/wet-boew/License-en.html / wet-boew.github.io/wet-boew/Licence-fr.html
* @author @duboisp
*/
( function( $, window, wb ) {
&quot;use strict&quot;;

/*
* Variable and function definitions.
* These are global to the plugin - meaning that they will be initialized once per page,
* not once per instance of plugin on the page. So, this is a good place to define
* variables that are common to all instances of the plugin on a page.
*/
var componentName = &quot;wb-helloworld&quot;,
selector = &quot;.&quot; + componentName,
initEvent = &quot;wb-init&quot; + selector,
$document = wb.doc,

/**
* @method init
* @param {jQuery Event} event Event that triggered the function call
*/
init = function( event ) {

// Start initialization
// returns DOM object = proceed with init
// returns undefined = do not proceed with init (e.g., already initialized)
var elm = wb.init( event, componentName, selector ),
$elm,
settings;

This comment has been minimized.

Copy link
@LaurentGoderre

LaurentGoderre Dec 16, 2016

Member

Should add a defaults = {}, here


if ( elm ) {
$elm = $( elm );

// ... Do the plugin initialisation

// Get the plugin JSON configuration set on attribute data-wb-helloworld
settings = wb.getData( $elm, componentName );

This comment has been minimized.

Copy link
@LaurentGoderre

LaurentGoderre Dec 16, 2016

Member

Should change this for

settings = $.extend( true, {}, defaults, window[ componentName ], wb.getData( $elm, componentName ) );

This comment has been minimized.

Copy link
@duboisp

duboisp Dec 19, 2016

Author Member

Thanks for the suggestion @LaurentGoderre , but I think that should belong to a new tutorial or to a future code snippet library.

cc/ @MaximMartel

This comment has been minimized.

Copy link
@LaurentGoderre

LaurentGoderre Dec 19, 2016

Member

Most plugins need settings. I don't see why we wouldn't add this in the new plugin dopcumentation

This comment has been minimized.

Copy link
@duboisp

duboisp Dec 19, 2016

Author Member

ok, I will see how I can add it by keeping the hello world example short and sweet.


// Call my custom event
$elm.trigger( &quot;name.of.your.event&quot;, settings );

// Identify that initialization has completed
wb.ready( $elm, componentName );
}
};

// Add your plugin event handler
$document.on( &quot;name.of.your.event&quot;, selector, function( event, data ) {
var elm = event.currentTarget,
$elm = $( elm );

$elm.append( &quot;Hello World&quot; );

if ( data &amp;&amp; data.domore ) {
$elm.prepend( &quot;Do more&quot; );
}
} );

// Bind the init event of the plugin
$document.on( &quot;timerpoke.wb &quot; + initEvent, selector, init );

// Add the timer poke to initialize the plugin
wb.add( selector );

} )( jQuery, window, wb );</code></pre>
</section>

<section>
<h2>Source code</h2>
<p><a href="https://github.com/wet-boew/wet-boew/tree/master/src/other/helloworld">Hello world source code on GitHub</a></p>
</section>
102 changes: 102 additions & 0 deletions site/pages/docs/ref/helloworld/helloworld-fr.hbs
@@ -0,0 +1,102 @@
---
{
"title": "Exemple de plugiciel, Bonjour le monde",
"language": "fr",
"category": "Autre",
"categoryfile": "other",
"description": "Un tutoriel rapide sur commment créer votre plugiciel BOEW.",
"altLangPrefix": "helloworld",
"dateModified": "2016-12-06"
}
---
<div class="wb-prettify all-pre hide"></div>

<section>
<h2>But</h2>
<p>Apprendre à comment créer son propre plugiciel BOEW.</p>
</section>

<section>
<h2>Exemples pratiques</h2>
<ul>
<li><a href="../../../demos/helloworld/helloworld-fr.html">Exemple français</a></li>
<li><a href="../../../demos/helloworld/helloworld-en.html" hreflang="en">Exemple anglais</a></li>
</ul>
</section>

<section>
<h2>Code source de <code>bonjour.js</code></h2>
<pre><code>/**
* @title WET-BOEW Plugiciel bonjour le monde
* @overview Plugiciel démontrant un example de comment créer votre propre plugiciel BOEW personalisé
* @license wet-boew.github.io/wet-boew/License-en.html / wet-boew.github.io/wet-boew/Licence-fr.html
* @author @duboisp
*/
( function( $, window, wb ) {
&quot;use strict&quot;;

/*
* Définition de variable et de fonction.
* Ceux-ci sont généraux au plugiciel - cela veux dire qu'ils seront initialisé une fois par page,
* et non à chaque fois que le plugiciel sera instancié sur la page. Donc, ici c'est un bon endroit
* enfin de définir des variables qui sont communes à toutes les instance du plugiciel sur la page.
*/
var nomComposant = &quot;wb-bonjour&quot;,
selecteur = &quot;.&quot; + nomComposant,
initEvent = &quot;wb-init&quot; + selecteur,
$document = wb.doc,

/**
* @method init
* @param {jQuery Event} event L'object événement lors du déclanchement de la fonction
*/
init = function( event ) {

// Début de l'initialisation
// retourne un objet DOM = procéder avec l'initialisation
// retourne undefined = ne pas procéder avec l'initialisation (ex., il est déjà initialisé)
var elm = wb.init( event, nomComposant, selecteur ),
$elm,
parametres;

if ( elm ) {
$elm = $( elm );

// ... Faire l'initialisation du plugiciel

// Obtenir les paramètres JSON du plugiciel tel que définie par l'attribut data-wb-bonjour
parametres = wb.getData( $elm, nomComposant );

// Appel d'un événement personalisé
$elm.trigger( &quot;nom.de.votre.evenement&quot;, parametres );

// Annonce que l'initialisation de l'instance a été complélté
wb.ready( $elm, nomComposant );
}
};

// Ajouter votre code pour gérer les événement de votre plugiciel
$document.on( &quot;nom.de.votre.evenement&quot;, selecteur, function( evenenment, donnee ) {
var elm = evenenment.currentTarget,
$elm = $( elm );

$elm.append( &quot;Bonjour le monde&quot; );

if ( donnee &amp;&amp; donnee.surpassetoi ) {
$elm.prepend( &quot;Surpasse toi&quot; );
}
} );

// Liaison à l'événement init du plugiciel
$document.on( &quot;timerpoke.wb &quot; + initEvent, selecteur, init );

// Ajouter notre poke pour que l'initialisation des instances
wb.add( selecteur );

} )( jQuery, window, wb );</code></pre>
</section>

<section>
<h2>Code source</h2>
<p><a href="https://github.com/wet-boew/wet-boew/tree/master/src/other/helloworld">Code source pour Bonjour le monde sur GitHub</a></p>
</section>
12 changes: 12 additions & 0 deletions site/pages/docs/ref/plugins-en.hbs
Expand Up @@ -23,6 +23,7 @@
<li><a href="footnotes/footnotes-en.html">Footnotes</a> - Provides a consistent, accessible way of handling footnotes across websites.</li>
<li><a href="formvalid/formvalid-en.html">Form validation</a> - Provides generic validation and error message handling for Web forms.</li>
<li><a href="geomap/geomap-en.html">Geomap</a> - Displays a dynamic map over which information from additional sources can be overlaid.</li>
<li><a href="helloworld/helloworld-en.html">Hello world plugin example</a> - A quick tutorial on how you can create your own WET plugin.</li>
<li><a href="lightbox/lightbox-en.html">Lightbox</a> - Helps build a photo gallery on a web page.</li>
<li><a href="menu/menu-en.html">Menu</a> - Provides an interactive menu with optional sub-menus.</li>
<li><a href="multimedia/multimedia-en.html">Multimedia player</a> - Provides an accessible multimedia player for embedding video and audio into web pages.</li>
Expand All @@ -36,3 +37,14 @@
<li><a href="toggle/toggle-en.html">Toggle</a> - Allows a link to toggle elements between on and off states.</li>
<li><a href="twitter/twitter-en.html">Twitter embedded timeline</a> - Helps with implementing Twitter embedded timelines.</li>
</ul>

<h2>Using your own plugin</h2>

<p>In order to have your plugin working with WET:</p>
<ol>
<li>Your plugin needs to follow the WET plugin initialisation.</li>
<li>Your script needs to be inserted after the <code>wet-boew.min.js</code> script in your page.</li>
<li>An element in your page needs to call the plugin by having the plugin name in its class atttribute.</li>
</ol>

<p>Take a look at the <a href="../../demos/helloworld/helloworld-en.html">Hello world</a> example.</p>
16 changes: 14 additions & 2 deletions site/pages/docs/ref/plugins-fr.hbs
Expand Up @@ -7,7 +7,7 @@
"dateModified": "2014-03-31"
}
---
<p lang="en"><strong>Needs translation</strong> A WET plugin provides various types of functionality useful to a website and provided by calling the function in the class attribute of an HTML tag.</p>
<p>Les plugiciels BOEW fournis divers fonctionalités utilent pour un site web et l'initialisation de ceux-ci se font l'intermédaire d'une classe CSS défénie à un élément HTML.</p>
<ul>
<li><a href="collapsible-alerts/collapsible-alerts-fr.html">Alertes repliables</a> - Créer des alertes que les utilisateurs peuvent replier.</li>
<li><a href="toggle/toggle-fr.html">Basculer</a> - Plugiciel qui permet un lien à basculer des éléments entre les états activé et désactivé.</li>
Expand All @@ -19,6 +19,7 @@
<li><a href="data-inview/data-inview-fr.html">Data Inview</a> - Affiche de contenu superposé quand une section se déplace hors de la clôture.</li>
<li><a href="data-picture/data-picture-fr.html">Data Picture</a> - Conversion de Picturefill guidé par l'événement.</li>
<li><a href="equalheight/equalheight-fr.html">Égalisation des hauteurs</a> - Un plugiel d'égalisation des hauteurs réactif.</li>
<li><a href="helloworld/helloworld-fr.html">Exemple de plugiciel, Bonjour le monde</a> - Un tutoriel rapide sur commment créer votre plugiciel BOEW.</li>
<li><a href="session-timeout/session-timeout-fr.html">Expiration de la session</a> - Ferme la session de l'utilisateur après un certain délai.</li>
<li><a href="favicon/favicon-fr.html">Favoricône</a> - Offre la possibilité d'ajouter et de mettre à jour les favoricônes d'une page.</li>
<li><a href="feeds/feeds-fr.html">Fils de syndication</a> - Affiche les articles d’un ou plus fils de syndication.</li>
Expand All @@ -34,5 +35,16 @@
<li><a href="footnotes/footnotes-fr.html">Notes de bas de page</a> - Une méthode cohérente et facile d’accès pour répertorier les notes de bas de page.</li>
<li><a href="prettify/prettify-fr.html">Prettify</a> - Affiche de la syntaxe des extraits de code source.</li>
<li><a href="tables/tables-fr.html">Tables</a> - Integrates the DataTables plugin into WET providing searching, sorting, filtering, pagination and other advanced features for tables.</li>
<li><a href="formvalid/formvalid-fr.html">Validation de formulaires</a> - Effectue la validation de formulaires Web selon un ensemble de règles de base avant qu'ils soient soumis.</li>
<li><a href="formvalid/formvalid-fr.html">Validation de formulaires</a> - Effectue la validation de formulaires Web selon un ensemble de règles de base avant qu'ils soient soumis.</li>
</ul>

<h2>Utilisation de votre plugiciel</h2>

<p>Pour que vous puissez utiliser votre propre plugiciel dans la BOEW, vous devez:</p>
<ol>
<li>Votre plugiciel doit suivre la procédure d'initialisation de la BOEW.</li>
<li>Votre script doit être ajouter après que le script <code>wet-boew.min.js</code> soit inséré dans votre page.</li>
<li>Un élément dans votre page doit contenir l'appel de votre plugiciel, tel que le nom du plugiciel soit existant dans l'attribut "class".</li>
</ol>

<p>Prenez le temps de consulter l'example <a href="../../demos/helloworld/helloworld-fr.html">Bonjour le monde</a>.</p>
68 changes: 68 additions & 0 deletions src/other/helloworld/demo/bonjour.js
@@ -0,0 +1,68 @@
/**
* @title WET-BOEW Plugiciel bonjour le monde
* @overview Plugiciel démontrant un example de comment créer votre propre plugiciel BOEW personalisé
* @license wet-boew.github.io/wet-boew/License-en.html / wet-boew.github.io/wet-boew/Licence-fr.html
* @author @duboisp
*/
( function( $, window, wb ) {
"use strict";

/*
* Définition de variable et de fonction.
* Ceux-ci sont généraux au plugiciel - cela veux dire qu'ils seront initialisé une fois par page,
* et non à chaque fois que le plugiciel sera instancié sur la page. Donc, ici c'est un bon endroit
* enfin de définir des variables qui sont communes à toutes les instance du plugiciel sur la page.
*/
var nomComposant = "wb-bonjour",
selecteur = "." + nomComposant,
initEvent = "wb-init" + selecteur,
$document = wb.doc,

/**
* @method init
* @param {jQuery Event} event L'object événement lors du déclanchement de la fonction
*/
init = function( event ) {

// Début de l'initialisation
// retourne un objet DOM = procéder avec l'initialisation
// retourne undefined = ne pas procéder avec l'initialisation (ex., il est déjà initialisé)
var elm = wb.init( event, nomComposant, selecteur ),
$elm,
parametres;

if ( elm ) {
$elm = $( elm );

// ... Faire l'initialisation du plugiciel

// Obtenir les paramètres JSON du plugiciel tel que définie par l'attribut data-wb-bonjour
parametres = wb.getData( $elm, nomComposant );

// Appel d'un événement personalisé
$elm.trigger( "nom.de.votre.evenement", parametres );

// Annonce que l'initialisation de l'instance a été complélté
wb.ready( $elm, nomComposant );
}
};

// Ajouter votre code pour gérer les événement de votre plugiciel
$document.on( "nom.de.votre.evenement", selecteur, function( evenenment, donnee ) {
var elm = evenenment.currentTarget,
$elm = $( elm );

$elm.append( "Bonjour le monde" );

if ( donnee && donnee.surpassetoi ) {
$elm.prepend( "Surpasse toi" );
}
} );

// Liaison à l'événement init du plugiciel
$document.on( "timerpoke.wb " + initEvent, selecteur, init );

// Ajouter notre poke pour que l'initialisation des instances
wb.add( selecteur );

} )( jQuery, window, wb );

0 comments on commit dccc9c7

Please sign in to comment.