diff --git a/components/gc-featured-link/_base.scss b/components/gc-featured-link/_base.scss index 542ba3b67..7944f0b7c 100644 --- a/components/gc-featured-link/_base.scss +++ b/components/gc-featured-link/_base.scss @@ -2,20 +2,27 @@ .gc-featured-link { background-color: $bg-gctheme; + color: #fff; + font-family: Lato, sans-serif; + opacity: .9; + padding-bottom: $space-md; + padding-top: $space-md; - &.provisional { - font-family: Lato, sans-serif; - opacity: .9; - padding-bottom: $space-md; - padding-top: $space-md; + p:first-of-type { + margin-bottom: $space-0; + } - p:first-of-type { - font-weight: $bold-weight; - margin-bottom: $space-0; - } + a { + color: #fff; + font-weight: $bold-weight; + } + + html:not(.wb-disable) &[data-bg-color] { + background-color: transparent; + color: $text-color; - p, a { - color: #fff; + a { + color: $text-color; } } } diff --git a/components/gc-featured-link/gc-featured-link-en.html b/components/gc-featured-link/gc-featured-link-en.html index c7b286db6..8ef7ad9a6 100644 --- a/components/gc-featured-link/gc-featured-link-en.html +++ b/components/gc-featured-link/gc-featured-link-en.html @@ -34,7 +34,7 @@

Purpose

Working examples

Featured link (provisional v1.0)

-

The logic semantic structure of headings have not been followed to accommodate each working examples.

+

The logic semantic structure of headings have not been followed to accommodate the following working example. You can go directly to the source code.

-

Code

+

Code

<section class="provisional gc-featured-link">
-		<div class="container">
-			<div class="row">
-				<div class="col-xs-12">
-					<h2 class="wb-inv">Featured</h2>
-					<p><a class="stretched-link" href="#">[Promotion title]</a></p>
-					<p>Long description [optional]</p>
-				</div>
+	<div class="container">
+		<div class="row">
+			<div class="col-xs-12">
+				<h2 class="wb-inv">Featured</h2>
+				<p><a class="stretched-link" href="#">[Promotion title]</a></p>
+				<p>Long description [optional]</p>
 			</div>
 		</div>
-	</section>
-	
+ </div> +</section> + +

Customized background color

+

To customize the background color, add the attribute data-bg-color. The value should be the hexadecimal code of the desired color.

+

The plugin will automatically apply the correct color to the text: #FFFFFF for dark colors, #333333 for light colors, #000000 for colors in-between.

+

The logic semantic structure of headings have not been followed to accommodate each working examples. You can go directly to the source code.

+

Dark background example:

+
+ + + +
+

Light color example:

+
+ + + +
+

Medium color example:

+
+ + + +
+

Code

+
<section class="provisional gc-featured-link" data-bg-color="#005B61">
+		<div class="container">
+			<div class="row">
+				<div class="col-xs-12">
+					<h2 class="wb-inv">Featured</h2>
+					<p><a class="stretched-link" href="#">[Promotion title]</a></p>
+					<p>Long description [Optional]</p>
+				</div>
+			</div>
+		</div>
+	</section>
+
+	<section class="provisional gc-featured-link" data-bg-color="#99dade">
+		<div class="container">
+			<div class="row">
+				<div class="col-xs-12">
+					<h2 class="wb-inv">Featured</h2>
+					<p><a class="stretched-link" href="#">[Promotion title]</a></p>
+					<p>Long description [Optional]</p>
+				</div>
+			</div>
+		</div>
+	</section>
+
+	<section class="provisional gc-featured-link" data-bg-color="#8F8F8F">
+		<div class="container">
+			<div class="row">
+				<div class="col-xs-12">
+					<h2 class="wb-inv">Featured</h2>
+					<p><a class="stretched-link" href="#">[Promotion title]</a></p>
+					<p>Long description [Optional]</p>
+				</div>
+			</div>
+		</div>
+	</section>

Previous design patterns

diff --git a/components/gc-featured-link/gc-featured-link-fr.html b/components/gc-featured-link/gc-featured-link-fr.html index eec2ccd02..d9e7cec19 100644 --- a/components/gc-featured-link/gc-featured-link-fr.html +++ b/components/gc-featured-link/gc-featured-link-fr.html @@ -34,7 +34,7 @@

Objectif

Exemples pratiques

Lien en vedette (Provisiore v1.0)

-

La structure sémantique logique des en-têtes n'a pas été suivie afin de s'adapter à chaque exemples pratiques.

+

La structure sémantique logique des en-têtes n'a pas été suivie afin de s'adapter à l'exemple pratique suivant. Vous pouvez aller directement au code source.

-

Code

-
<section class="provisional gc-featured-link">
-		<div class="container">
-			<div class="row">
-				<div class="col-xs-12">
-					<h2 class="wb-inv">En vedette</h2>
-					<p><a class="stretched-link" href="#">[Titre de la promotion]</a></p>
-					<p>Description longue [Facultatif]</p>
-				</div>
-			</div>
-		</div>
-	</section>
-	
+

Code

+
<section class="provisional gc-featured-link">
+	<div class="container">
+		<div class="row">
+			<div class="col-xs-12">
+				<h2 class="wb-inv">En vedette</h2>
+				<p><a class="stretched-link" href="#">[Titre de la promotion]</a></p>
+				<p>Description longue [Facultatif]</p>
+			</div>
+		</div>
+	</div>
+</section>
+ +

Couleur d'arrière-plan personnalisée

+

Pour personnaliser la couleur d'arrière-pla, ajoutez l'attribut data-bg-color. La valeur doit être le code hexadécimal de la couleur souhaitée.

+

Le plugiciel appliquera automatiquement la bonne couleur au texte : #FFFFFF pour les couleurs sombres, #333333 pour les couleurs claires, #000000 pour les couleurs intermédiaires.

+

La structure sémantique logique des en-têtes n'a pas été suivie afin de s'adapter à chaque exemples pratiques. Vous pouvez aller directement au code source.

+

Exemple avec couleur sombre :

+
+ + + +
+

Exemple avec couleur claire :

+
+ + + +
+

Exemple avec couleur intermédiaire :

+
+ + + +
+

Code

+
<section class="provisional gc-featured-link" data-bg-color="#005B61">
+		<div class="container">
+			<div class="row">
+				<div class="col-xs-12">
+					<h2 class="wb-inv">En vedette</h2>
+					<p><a class="stretched-link" href="#">[Titre de la promotion]</a></p>
+					<p>Description longue [Facultatif]</p>
+				</div>
+			</div>
+		</div>
+	</section>
+
+	<section class="provisional gc-featured-link" data-bg-color="#99dade">
+		<div class="container">
+			<div class="row">
+				<div class="col-xs-12">
+					<h2 class="wb-inv">En vedette</h2>
+					<p><a class="stretched-link" href="#">[Titre de la promotion]</a></p>
+					<p>Description longue [Facultatif]</p>
+				</div>
+			</div>
+		</div>
+	</section>
+
+	<section class="provisional gc-featured-link" data-bg-color="#8F8F8F">
+		<div class="container">
+			<div class="row">
+				<div class="col-xs-12">
+					<h2 class="wb-inv">En vedette</h2>
+					<p><a class="stretched-link" href="#">[Titre de la promotion]</a></p>
+					<p>Description longue [Facultatif]</p>
+				</div>
+			</div>
+		</div>
+	</section>

Modèles de conception précédents

diff --git a/components/gc-featured-link/gc-featured-link.js b/components/gc-featured-link/gc-featured-link.js new file mode 100644 index 000000000..6dd5e775b --- /dev/null +++ b/components/gc-featured-link/gc-featured-link.js @@ -0,0 +1,88 @@ +/** + * @title WET-BOEW Featured link + * @overview Stylize a featured link + * @license wet-boew.github.io/wet-boew/License-en.html / wet-boew.github.io/wet-boew/Licence-fr.html + * @author @garneauma + */ +( function( $, window, wb ) { +"use strict"; + +var $document = wb.doc, + componentName = "gc-featured-link", + selector = ".provisional." + componentName, + initEvent = "wb-init " + selector, + white = "#FFFFFF", + black = "#000000", + darkgrey = "#333333", + luminance1, luminance2, + contrastRatio, + + /** + * @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; + + if ( elm ) { + var bgColor = elm.dataset.bgColor, + textColor; + + $elm = $( elm ); + + if ( bgColor ) { + if ( getContrastRatio( white, bgColor ) >= 4.5 ) { + textColor = white; + } else if ( getContrastRatio( darkgrey, bgColor ) >= 4.5 ) { + textColor = darkgrey; + } else { + textColor = black; + } + + elm.style.backgroundColor = bgColor; + elm.style.color = textColor; + elm.querySelectorAll( "p, a" ).forEach( e => { + e.style.color = textColor; + } ); + } + + // Identify that initialization has completed + wb.ready( $elm, componentName ); + } + }, + + getContrastRatio = function( color1, color2 ) { + function getLuminance( color ) { + var rgb = [ color.substr( 1, 2 ), color.substr( 3, 2 ), color.substr( 5, 2 ) ].map( hex => parseInt( hex, 16 ) / 255 ); + + for ( let i = 0; i < rgb.length; i++ ) { + if ( rgb[ i ] <= 0.03928 ) { + rgb[ i ] = rgb[ i ] / 12.92; + } else { + rgb[ i ] = Math.pow( ( rgb[ i ] + 0.055 ) / 1.055, 2.4 ); + } + } + + return 0.2126 * rgb[ 0 ] + 0.7152 * rgb[ 1 ] + 0.0722 * rgb[ 2 ]; + } + + luminance1 = getLuminance( color1 ); + luminance2 = getLuminance( color2 ); + + contrastRatio = ( Math.max( luminance1, luminance2 ) + 0.05 ) / ( Math.min( luminance1, luminance2 ) + 0.05 ); + + return contrastRatio.toFixed( 2 ); + }; + +// Bind the init event of the plugin +$document.on( "timerpoke.wb " + initEvent, selector, init ); + +// Add the timer poke to initialize the plugin +wb.add( selector ); + +} )( jQuery, window, wb );