<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Nicolas Escoffier on Medium]]></title>
        <description><![CDATA[Stories by Nicolas Escoffier on Medium]]></description>
        <link>https://medium.com/@OxyDesign?source=rss-a590c79f3327------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*BO-kwE_Tq9tBau-j.jpeg</url>
            <title>Stories by Nicolas Escoffier on Medium</title>
            <link>https://medium.com/@OxyDesign?source=rss-a590c79f3327------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 22:35:11 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@OxyDesign/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Twitter’s Heart Animation in Full CSS]]></title>
            <link>https://blog.prototypr.io/twitter-s-heart-animation-in-full-css-b1c00ca5b774?source=rss-a590c79f3327------2</link>
            <guid isPermaLink="false">https://medium.com/p/b1c00ca5b774</guid>
            <category><![CDATA[css]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[animation]]></category>
            <dc:creator><![CDATA[Nicolas Escoffier]]></dc:creator>
            <pubDate>Mon, 07 Dec 2015 21:57:05 GMT</pubDate>
            <atom:updated>2015-12-07T21:57:05.395Z</atom:updated>
            <content:encoded><![CDATA[<h4>Intro</h4><p>A few weeks ago, as everybody, I saw the Twitter Star turned into a Heart. The favorite into a like.</p><h3>Twitter on Twitter</h3><p>You can say a lot with a heart. Introducing a new way to show how you feel on Twitter: https://t.co/WKBEmORXNW https://t.co/G4ZGe0rDTP</p><p>That was a huge source for debates for sure … but the only thing that I had in mind was … is it possible to make it with only CSS (not a single picture or SVG) ?</p><p>I know it’s not a matter of life and death but when something like that gets in my head it’s too late, I can’t sleep until I have a viable answer.</p><p>After a few trials on this challenge I finally have my answer. The result is not perfect (and it’s a lot of SCSS / CSS — almost 400 lines) but it’s satisfying (based on my expectations at least).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*hRJF5CNRG6tB-SkwVU5bCw.gif" /><figcaption>Image (gif) from the animation</figcaption></figure><p>I will now describe the steps I went through to find it.</p><p>First I divided it in 3 layers : the Heart (<strong>.heart</strong>), the Ring (<strong>.ring</strong>) and the Circles (<strong>.circles</strong>), and grouped them in a wrapper (<strong>.heart-wrapper</strong>). After this, I made the drawing for each layer, then the animation of each layer and finally mixed them all together.</p><h3>Drawing</h3><h4>Heart</h4><p>First part was the <em>Heart</em>.</p><p>I separated the full area in 4 rectangles :</p><ul><li><strong>Top </strong>/ <strong>Left </strong>and <strong>Top </strong>/ <strong>Right </strong>: <strong>25%</strong> high / <strong>50%</strong> wide</li><li><strong>Bottom</strong> / <strong>Left</strong> and <strong>Bottom</strong> / <strong>Right</strong> : <strong>75%</strong> high / <strong>50%</strong> wide</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/162/1*NS2yr0ORbsVfSLjGQI9gOA.png" /></figure><p>And I used a pseudo element (<strong>:after</strong>) inside every rectangle and played with <strong>border-radius</strong> property to be as close as possible to the original shape for each part.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Dehd-pSVBmSVDEMHWVCIDQ.png" /></figure><p>Then I applied the <strong>color </strong>and <strong>overflow:hidden</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gE9ETpGVkL-QsZGI3fluxg.png" /></figure><h4>Ring</h4><p>The second part was the <em>Ring</em>.</p><p>This one is a simple rounded element with different <strong>border-size</strong> values and <strong>width </strong>/ <strong>height</strong> values.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_yFZc2rehz76xjNk2teg3g.png" /></figure><h4>Circles</h4><p>The third part was the <em>Circles</em>.</p><p>I built this one using a transparent rounded element in the middle and adding shadow boxes on it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*MmvpRjbDUXiQm0DF2nN44g.png" /></figure><p>A <strong>shadow-box </strong>value for each circle, comma separated. The position <strong>x</strong> / <strong>y</strong> is computed based on the angle with <strong>sin </strong>/ <strong>cos</strong> using <strong>Compass</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*S2lX-1vBoe2S0-cxYr1QTw.png" /></figure><h3>Animation</h3><h4>Heart</h4><p>Nothing too complex.</p><p>Increasing / decreasing the <strong>width</strong> / <strong>height</strong> of the main element (and setting the position <strong>left</strong> / <strong>top</strong> accordingly). The only thing is to make sure everything inside is relative to this element to adjust.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/1*fevLrUy3FbRyFP_U6YPXjg.png" /></figure><h4>Ring</h4><p>Adjusting the size of the <strong>border </strong>and the circle inside and the <strong>position </strong>accordingly as well as the <strong>color</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tD83iABs7VzfDfaUkMgu5w.png" /></figure><h4>Circles</h4><p>This one is a bit more tricky because all the <strong>border-shadow </strong>values have to be udpated all at the same time (position <strong>x</strong> / <strong>y</strong>, <strong>size</strong>, <strong>color</strong>) as it’s only one property with several comma separated values.</p><p>For instance :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/075a8b1c9c1260e019a7fa3bdfe8495b/href">https://medium.com/media/075a8b1c9c1260e019a7fa3bdfe8495b/href</a></iframe><p>And this is only for one step…</p><p>To make it easier to read and adjust, I created a <strong>SASS function </strong>to handle this :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/021981807b736ba6e4e4e0c1b288d69b/href">https://medium.com/media/021981807b736ba6e4e4e0c1b288d69b/href</a></iframe><p>This <strong>function </strong>loops through all the <em>Circles </em>(stored in a <strong>SASS Map</strong>) and set 2 by 2 (the big and the small <em>Circles</em>) the <strong>box-shadow </strong>values accordingly, based on the distances, the sizes, the angle of shift between them and the progression in the color, all passed as <strong>arguments</strong>.</p><h3>Completion</h3><p>Then I adjusted the timings / percentages of the animations according to what is explained in this post <a href="https://medium.com/@chrismabry/how-did-they-do-that-the-twitter-like-animation-2a473b658e43#.hn9dbewt7"><em>https://medium.com/@chrismabry/how-did-they-do-that-the-twitter-like-animation-2a473b658e43</em></a> <em>by </em>@chrismabry</p><p>Therefore I separated in 28 steps</p><pre>$animStep: 100% / 27;</pre><p>that run in 0.8s</p><pre>$animDuration: 0.8s;</pre><p>using a function to generate the percentages of the various steps :</p><pre>@function setStep($n) { @return ($n — 1) * $animStep }</pre><p>For instance :</p><pre>#{setStep(6)}</pre><p>will output :</p><pre>18.51852%</pre><p>And make the three layers superimpose with the good timing.</p><p>A picture will be better than a long explanation :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4yXFWSWTjBc13IGhdjZBig.png" /></figure><p>The animation will be active / inactive just by adding / removing the <strong>class </strong>(<strong>.active</strong>) on the container (<strong>.heart-wrapper</strong>). In my example this <strong>class </strong>toggles on <strong>click</strong>.</p><h4>Conclusion</h4><p>I achieved my goal but as you can imagine for me it was more a question of winning this personal challenge, nothing more.</p><p>Browser support is the same as the current version (IE10+) because the most advanced requirement is <strong>CSS3 Animation</strong> (<a href="http://caniuse.com/#feat=css-animation">http://caniuse.com/#feat=css-animation</a>).</p><p>This is what it looks like :</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2FOxyDesign%2Fembed%2Fpreview%2FavXVbo%3Fheight%3D600%26slug-hash%3DavXVbo%26default-tab%3Dresult%26host%3Dhttp%253A%252F%252Fcodepen.io&amp;url=http%3A%2F%2Fcodepen.io%2FOxyDesign%2Fpen%2FavXVbo%2F&amp;image=https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fi.cdpn.io%2F109751.avXVbo.small.8214909a-4dd2-45e0-9102-472f23b9d67e.png&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/0f6468cc04f39643f62406ee698eb919/href">https://medium.com/media/0f6468cc04f39643f62406ee698eb919/href</a></iframe><p>I tried to keep the code as clean and structured as possible, and I used <strong>SASS variables </strong>for settings at the top to let people easily make some tests and changes. Feel free to let me know what you think and if you find something that can be improved (by setting the debug to true in the JS you’ll be able to see the animation step by step, with 1 click for each step).</p><p>Thanks for reading</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b1c00ca5b774" width="1" height="1" alt=""><hr><p><a href="https://blog.prototypr.io/twitter-s-heart-animation-in-full-css-b1c00ca5b774">Twitter’s Heart Animation in Full CSS</a> was originally published in <a href="https://blog.prototypr.io/">Prototypr</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Benefits of CSS & Html Components with Attribute Selectors : Namespacing / Nesting…]]></title>
            <link>https://medium.com/@OxyDesign/the-benefits-of-css-html-components-with-attribute-selectors-namespacing-nesting-b884468525d2?source=rss-a590c79f3327------2</link>
            <guid isPermaLink="false">https://medium.com/p/b884468525d2</guid>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[css]]></category>
            <dc:creator><![CDATA[Nicolas Escoffier]]></dc:creator>
            <pubDate>Wed, 12 Aug 2015 21:11:53 GMT</pubDate>
            <atom:updated>2015-08-12T21:11:53.376Z</atom:updated>
            <content:encoded><![CDATA[<h2>The Benefits of CSS &amp; Html Components with Attribute Selectors : Namespacing / Nesting, Maintainability &amp; Readability</h2><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OILMLb4l2z899kOXQeOXkQ.png" /></figure><p>When I first heard about Attribute Selectors in CSS (CSS 2.1) I found it was useful. For example selecting input by type to apply a global style for each type of input without the use of any classes is really convenient.</p><p>For example :</p><pre>input[type=text]{<br>    color:red;<br>}</pre><p>will target all the <em>&lt;input type=”text” /&gt;</em> without altering the other inputs.</p><p>Then later, with CSS 3, when the possibility to target the element using the beginning (<em>[attr^=value]</em>), the end (<em>[attr$=value]</em>) or any matching string (<em>[attr*=value]</em>) in the value of the attribute, I must be honest I didn’t really see much use for this at the time and I was working on projects that usually had supports for IE 7 and 8 and I was quite convinced this selector’s magic would never work in these old pieces of c… browsers !</p><p><em>(More details : </em><a href="https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_selectors"><em>https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_selectors</em></a><em>)</em></p><p>Recently I saw them in a project. The use case was not really incredible but that made feel the need to experiment with this selector more extensively. This led me to something I find easy to implement and really convenient and maintainable.</p><p>Therefore I will share it with you now but, as it’s still just an experiment, please feel free to let me know what you think of it and whether you find it useful, rubbish, right or wrong.</p><h3>Selecting Class Name to create a Component</h3><p>My goal was to create styles using this <strong>Attribute Selector</strong> to target elements in a way that they may be reused, a <strong>Component</strong>-like approach.</p><p>I made an example with a Button <strong>Component</strong>.</p><p>Every Html <strong>Component</strong> has a <strong>Class</strong> that begins with the name of the <strong>Component</strong> (<em>‘button’</em>) and all the alternative types (let’s call them <strong>Modifiers</strong>) are added in the <strong>Class Name</strong> and separated with dashes (<em>‘big’</em>, <em>‘red’</em> etc…).</p><p>The first rule sets the basic style of the <strong>Component</strong> and is of the type <em>[attr^=value]</em> to select the <strong>Component</strong> name.</p><p>All the others set specific styles according to the <strong>Modifier</strong> and are of the type <em>[attr*=value]</em> to match the different <strong>Modifiers</strong>. They are all prefixed by the Component Selector to make sure they apply only on the Component (example : applied on <em>&lt;elt class=”component-modifier”&gt;</em> but not on <em>&lt;elt class=”modifier”&gt;</em>). This allows us to simulate a kind of <strong>Namespace</strong> where all the <strong>Modifiers</strong> are bound to the <strong>Component</strong>.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2FOxyDesign%2Fembed%2FzGXKJV%3Fheight%3D600%26slug-hash%3DzGXKJV%26default-tab%3Dresult%26host%3Dhttp%253A%252F%252Fcodepen.io&amp;url=http%3A%2F%2Fcodepen.io%2FOxyDesign%2Fpen%2FzGXKJV%2F&amp;image=https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fi.cdpn.io%2F109751.zGXKJV.small.d0139d22-51b1-49ae-b12f-4f7d51114405.png&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/0ddaf185a6d004192621097edb0aed71/href">https://medium.com/media/0ddaf185a6d004192621097edb0aed71/href</a></iframe><p>Of course the dashes as separators are just an arbitrary choice to separate the <strong>Modifier</strong> for readability and there are many possibilities. A few examples are set out below with the same CSS and different separators in the <strong>Modifiers</strong> in the Html.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2FOxyDesign%2Fembed%2FqdwaJd%3Fheight%3D600%26slug-hash%3DqdwaJd%26default-tab%3Dresult%26host%3Dhttp%253A%252F%252Fcodepen.io&amp;url=http%3A%2F%2Fcodepen.io%2FOxyDesign%2Fpen%2FqdwaJd%2F&amp;image=https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fi.cdpn.io%2F109751.qdwaJd.small.02869cd4-8573-41f1-a604-581fa8528bf2.png&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/1a0c84f5f5b59aad11ac936824a7ad95/href">https://medium.com/media/1a0c84f5f5b59aad11ac936824a7ad95/href</a></iframe><p>This also works to avoid any separator but as the readability will be much more complicated, another solution can be removing all the separators and writing the <strong>Component</strong> and <strong>Modifiers</strong> in camelCase. In this case there is just a need to rename the CSS Selectors because it’s case sensitive. This way :</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2FOxyDesign%2Fembed%2FvOMXVy%3Fheight%3D600%26slug-hash%3DvOMXVy%26default-tab%3Dresult%26host%3Dhttp%253A%252F%252Fcodepen.io&amp;url=http%3A%2F%2Fcodepen.io%2FOxyDesign%2Fpen%2FvOMXVy%2F&amp;image=https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fi.cdpn.io%2F109751.vOMXVy.small.85cdc88f-96d0-4fa0-a4b9-4c5ab7d1323d.png&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/25cc20e4a774f3145096fd7dfa640cfa/href">https://medium.com/media/25cc20e4a774f3145096fd7dfa640cfa/href</a></iframe><h3>Using a Custom Attribute to improve the safety</h3><p>This seemed to me pretty convenient but this kind of <strong>Component</strong> may have conflicts if you use any other element with a <strong>Class</strong> beginning with the name of the Component. For example you create a <strong>Component</strong> ‘link’ and if you add an element with <em>class=”linkable”</em> or <em>class=”linked”</em> it will have the basic style of your Component.</p><p>Another issue can also arise if you have classes generated server-side on the element or dynamically added / changed with Javascript you will likely have two unwanted behaviours : in the first case, if the name of the component is not the beginning of the value (the <strong>Component</strong> won’t apply) or in the second case, you have more classes added with matching value with the <strong>Modifiers</strong> (for example you have a <strong>Modifier</strong> <em>‘light’</em> and Javascript adds dynamically the class <em>‘highlighted’</em> to the element, the <em>‘light’</em> will be applied).</p><p>To avoid this, I thought it would be much better to use a different attribute instead of class. We are talking about selecting elements with attributes only so why bother with classes ?</p><p>Then I add an attribute <em>‘data-component’</em> and set its value to the previous class value and change the selector from <em>[class^=”button”]</em> to <em>[data-component^=”button”]</em>.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2FOxyDesign%2Fembed%2FmJgrzW%3Fheight%3D600%26slug-hash%3DmJgrzW%26default-tab%3Dresult%26host%3Dhttp%253A%252F%252Fcodepen.io&amp;url=http%3A%2F%2Fcodepen.io%2FOxyDesign%2Fpen%2FmJgrzW%2F&amp;image=https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fi.cdpn.io%2F109751.mJgrzW.small.28810917-7ba8-47f7-aad5-3a29d259ac71.png&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/615a1078d83a831b5479f45eec6b4c3a/href">https://medium.com/media/615a1078d83a831b5479f45eec6b4c3a/href</a></iframe><p>As you can see that works exactly the same.</p><p>And of course, that still perfectly works with the camelCase version.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2FOxyDesign%2Fembed%2FGJLjYm%3Fheight%3D600%26slug-hash%3DGJLjYm%26default-tab%3Dresult%26host%3Dhttp%253A%252F%252Fcodepen.io&amp;url=http%3A%2F%2Fcodepen.io%2FOxyDesign%2Fpen%2FGJLjYm%2F&amp;image=https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fi.cdpn.io%2F109751.GJLjYm.small.ac38681c-fc54-4b64-9fce-0da5a212591e.png&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/368a6d2a06ad6b0c2708d837bac0d75e/href">https://medium.com/media/368a6d2a06ad6b0c2708d837bac0d75e/href</a></iframe><h3>Moving the Component in the Attribute to improve the understanding and the readability</h3><p>Now the component is <em>‘namespaced’</em>, safe and far from any possible conflict with the rest of the CSS.</p><p>We can still improve the ease of use in the Html <strong>Component</strong> and at the same time having a cleaner CSS file.</p><p>How ?</p><p>By using the Name of the<strong> Component</strong> in the attribute. Example : <em>data-button=”big-red”</em></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2FOxyDesign%2Fembed%2FgpywBR%3Fheight%3D600%26slug-hash%3DgpywBR%26default-tab%3Dresult%26host%3Dhttp%253A%252F%252Fcodepen.io&amp;url=http%3A%2F%2Fcodepen.io%2FOxyDesign%2Fpen%2FgpywBR%2F&amp;image=https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fi.cdpn.io%2F109751.gpywBR.small.b57b5539-a5e1-47b4-95a4-5d1426961d75.png&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/eae8105b9c9a7b04386e0f4e3d9d6f72/href">https://medium.com/media/eae8105b9c9a7b04386e0f4e3d9d6f72/href</a></iframe><p>The selector becomes <em>[data-button]</em> instead <em>[data-component^=”button”]</em>, much cleaner and easier to read.</p><p>The html is more obvious to understand :</p><pre>data-<strong><em>componentName</em></strong>=&quot;<strong><em>modifier1</em></strong>-<strong><em>modifier2</em></strong>&quot;</pre><p>instead of</p><pre>data-component=&quot;<strong><em>componentName</em></strong>-<strong><em>modifier1</em></strong>-<strong><em>modifier2</em></strong>&quot;</pre><p>The name of the <strong>Component</strong> in the attribute, the <strong>Modifiers</strong> in the value of the attribute. Every man to his trade.</p><p>It’s still possible with camelCase obviously (just keeping in mind that now even the first element has its first letter in uppercase) :</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2FOxyDesign%2Fembed%2FPqgGyK%3Fheight%3D600%26slug-hash%3DPqgGyK%26default-tab%3Dresult%26host%3Dhttp%253A%252F%252Fcodepen.io&amp;url=http%3A%2F%2Fcodepen.io%2FOxyDesign%2Fpen%2FPqgGyK%2F&amp;image=https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fi.cdpn.io%2F109751.PqgGyK.small.9806e53e-c7fe-487a-ae1b-9397e2a24a56.png&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/c2264d26becffb6f005fc54480e72dcc/href">https://medium.com/media/c2264d26becffb6f005fc54480e72dcc/href</a></iframe><p>I personally find this <strong>Component</strong> really reusable and maintainable now.</p><p>And guess what, the support is IE7+ !</p><p><em>(Sources : </em><a href="http://caniuse.com/#feat=css-sel3"><em>http://caniuse.com/#feat=css-sel3</em></a><em>)</em></p><h3>Compare</h3><p>A similar approach is to use BEM Methodology <em>(</em><a href="https://en.bem.info/"><em>https://en.bem.info/</em></a><em>)</em>, which would be written this way for the same component :</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2FOxyDesign%2Fembed%2FOVGRBx%3Fheight%3D600%26slug-hash%3DOVGRBx%26default-tab%3Dresult%26host%3Dhttp%253A%252F%252Fcodepen.io&amp;url=http%3A%2F%2Fcodepen.io%2FOxyDesign%2Fpen%2FOVGRBx%2F&amp;image=https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fi.cdpn.io%2F109751.OVGRBx.small.54bd2d90-6cf6-4bfb-aa44-dd6642d889ac.png&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/45f18e6fe214ec0adbad5d871cd5ec99/href">https://medium.com/media/45f18e6fe214ec0adbad5d871cd5ec99/href</a></iframe><p>In this case the <strong>Class Names</strong> are longer, there are several <strong>Classes</strong> repeated with the same prefix (which is not ideal for readability) and all the <strong>Modifiers</strong> are at the first level in the CSS file, no nesting, which can be compared to global variables in Javascript, always a risk.</p><p>If you use a preprocessor which supports Nested Rules like Sass (<a href="http://sass-lang.com/documentation/file.SASS_REFERENCE.html#nested_rules">http://sass-lang.com/documentation/file.SASS_REFERENCE.html#nested_rules</a>), another benefit is that you can nest all the <strong>Modifiers</strong> in the <strong>Component</strong> (like in all my Codepen’s examples) which let you know visually which <strong>Modifier</strong> depends on which Component. Not the case with BEM.</p><p>I set out my thoughts on this the same way I came through it but this seems too easy and convenient to be without any disadvantages :-). If you have any leads or opinions to push the thinking forward on this, please let me know.</p><p>Thank you for reading.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b884468525d2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Thoughts about Privacy with Class, Prototype, Factory Function and Closure in JavaScript]]></title>
            <link>https://medium.com/@OxyDesign/thoughts-about-privacy-with-class-prototype-factory-function-and-closure-in-javascript-cfae4c0a13c4?source=rss-a590c79f3327------2</link>
            <guid isPermaLink="false">https://medium.com/p/cfae4c0a13c4</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[object-oriented]]></category>
            <dc:creator><![CDATA[Nicolas Escoffier]]></dc:creator>
            <pubDate>Mon, 13 Jul 2015 16:10:54 GMT</pubDate>
            <atom:updated>2015-07-13T16:10:54.763Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mqgMwykPerWJtYDowwArXw.png" /></figure><p>Sometimes you just have something in your mind you need to solve. You don’t know exactly why but you simply need to find an answer to appease your brain.</p><p>Some people try to change the world. Some others try to find the formula to turn lead into gold etc…</p><p>Mine recently was the privacy in JavaScript, and of course, as with the Philosopher’s stone I’m not the first one to chase this myth :-)</p><p>But this is absolutely not the kind of thing that would stop me as I’m about to expose (yes told you, not easy to keep the privacy ;-) ) the process of my humble reflection and the (not completely satisfying) options I have come up with (I also wanted to keep the methods shared to avoid massive duplication).</p><p>Of course I’ll be glad to hear or read any advice and if you have the perfect solution for this I would be very happy to know it.</p><h3><strong>First Case : Typical Class with a property</strong></h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c2066184f959158429c26611a2af7387/href">https://medium.com/media/c2066184f959158429c26611a2af7387/href</a></iframe><pre><strong><em>-- Console --<br></em></strong><em>Shared Prototype</em> : <strong>true</strong><br><em>Shared Prototype Method</em> : <strong>true</strong><br><em>getVal</em> : <strong>internalVal</strong><br><em>getVal (after setVal)</em> : <strong>newVal</strong><br><em>.val</em> : <strong>newVal</strong><br><em>.val (after .val =)</em> : <strong>newerVal</strong></pre><p>One Class, shared methods using the prototype.</p><p>But as seen in the console, .val is exposed and can be changed anytime just by assigning a new value to instance.val = ‘something’.</p><h3><strong>Second Case : Typical Class with a var statement</strong></h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/00b899f69a1bb3eb6ec12e8a0e933922/href">https://medium.com/media/00b899f69a1bb3eb6ec12e8a0e933922/href</a></iframe><pre><strong><em>-- Console --<br></em></strong><em>Shared Prototype</em> : <strong>true</strong><br><em>Shared Prototype Method</em> : <strong>true</strong><br><em>getVal</em> : <strong>undefined</strong><br><em>.val</em> : <strong>undefined</strong></pre><p>One Class, one prototype, shared methods between instances. The var statement keeps the variable private to the scope of the function … then of course it’s not accessible outside the constructor or by the methods of the prototype either. Private but not accessible by the methods, therefore useless…</p><h3><strong>Third Case : Var statement with methods inside the Class</strong></h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1ac4fac4f91c6666e42ba149e6a55399/href">https://medium.com/media/1ac4fac4f91c6666e42ba149e6a55399/href</a></iframe><pre><strong><em>-- Console --<br></em></strong><em>Shared Prototype</em> : <strong>true</strong><br><em>Shared Method</em> : <strong>false</strong><br><em>getVal</em> : <strong>internalVal</strong><br><em>getVal (after setVal)</em> : <strong>newVal</strong><br><em>.val</em> : <strong>undefined</strong></pre><p>It is not possible to set the prototype methods inside the function itself so I added methods to the instance (this.method).</p><p>The val is private but the methods are duplicate, which is a shame because they always have the same functionality.</p><h3><strong>Fourth Case : Factory Function with var statement</strong></h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ca5391b264a034772be4ee7c747a91c3/href">https://medium.com/media/ca5391b264a034772be4ee7c747a91c3/href</a></iframe><pre><strong><em>-- Console --<br></em></strong><em>Shared Prototype</em> : <strong>false</strong><br><em>Shared Prototype Method</em> : <strong>false</strong><br><em>getVal</em> : <strong>internalVal</strong><br><em>getVal (after setVal)</em> : <strong>newVal</strong><br><em>.val</em> : <strong>undefined</strong></pre><p>Var statement in the scope of the Factory Function to keep it private. The methods of the prototype can access it … but they are redefined for each instance, which creates the same issue as the previous one. Using the prototype this time but that loses all its usefulness because the Class is a new one for each instance.</p><h3><strong>Fifth Case : Private Array containing references for each instance in a Closure returning a Class</strong></h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1cdb6964fc6d23649403798a80adc83e/href">https://medium.com/media/1cdb6964fc6d23649403798a80adc83e/href</a></iframe><pre><strong><em>-- Console --<br></em></strong><em>Shared Prototype</em> : <strong>true</strong><br><em>Shared Prototype Method</em> : <strong>true</strong><br><em>Instance 1, getVal</em> : <strong>internalVal</strong><br><em>Instance 2, getVal</em> : <strong>internalVal</strong><br><em>Instance 1, getVal (after setVal)</em> : <strong>newVal1</strong><br><em>Instance 2, getVal (after setVal)</em> : <strong>newVal2</strong><br><em>.val</em> : <strong>undefined</strong></pre><p>A count variable (private) is incremented to keep the order of the instances in the Array (instances) and assigned to a property. The Array is private, as val. The methods are shared using the same prototype and can access the val.</p><p>The issue is then the property indexInst (the one that holds the number representing the position of the instance inside all the instances) is exposed so it can be changed and in this case the instance would access the wrong val (a val meant to be related to an other instance).</p><p>This solution seems a bit twisted, but (except the potential issue of the indexInst) this is the only one that fulfills the original needs : Private Value &amp; Shared Methods.</p><p>Thank you for reading and please fell free to let me know your thoughts on this.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cfae4c0a13c4" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>