Giter Club home page Giter Club logo

interactive-examples's Introduction

interactive-examples

code style: prettier

Home of the MDN interactive code examples.

Project maintainers

Should you have any questions regarding this project, please feel free to @mention either @wbamberg, @bsmth or @NiedziolkaMichal.

Good first issues

Want to contribute to the interactive examples project? Here are a couple of good first issues to get you started. Thanks!

Good first issues

Folder structure

  • [css] - This contains the CSS used by the base templates.
  • [js] - This contains the JS used by the base templates.
  • [live-examples] - This contains the live example CSS and JS fragments.
  • [media] - This contains images used by the live examples and templates.
  • [tmpl] - The base templates.

The dynamically generated pages, their dependencies, and assets are generated to the prod branch.

Browser support baseline

The following is a list of browser/version combinations supported by the interactive editor. In browsers that do not meet the criteria, the editor degrades gracefully to displaying static examples.

  • Firefox - Latest three release versions.
  • Chrome - Latest three release versions.
  • Safari - Latest two release versions.
  • Edge - Latest release version.

Contributing

If you're interested in contributing to this project, great! Please see the CONTRIBUTING document.

interactive-examples's People

Contributors

a2sheppy avatar bsmth avatar caugner avatar chrisdavidmills avatar ddbeck avatar dependabot-preview[bot] avatar dependabot[bot] avatar elchi3 avatar escattone avatar hamishwillee avatar ikarasz avatar jgmize avatar kenrick95 avatar maboa avatar mdn-bot avatar mendyberger avatar mfluehr avatar niedziolkamichal avatar onkarruikar avatar queengooborg avatar rachelandrew avatar renovate[bot] avatar rumyra avatar sahilempire avatar sphinxknight avatar stephaniehobson avatar stephanmax avatar tannerdolby avatar velusgautam avatar wbamberg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

interactive-examples's Issues

Review UI and UX for JS and CSS examples

There has been some feedback from the SF All Hands that we have discussed and a general review needed of the current JS and CSS editor. This relates to interactivity, better blending with the new MDN overall brand, enhancements to the editors, and the output. This issue is to collect all of the information and spin of separate issues for implementation.

Switch CSS example borders to left side

Currently CSS code example have either a red or yellow border on the right.

Red indicates invalid CSS
Yellow indicates the currently active example

To aid in the overall user experience and a generally better UI, we need to:

  1. Move above mentioned borders to the left
  2. Change the yellow border to green
  3. Add a default gray border to inactive examples

CSS examples: long lines escape from their box

-> http://imgur.com/a/LGnP2

I think the overflow should be hidden, and they should get a horizontal scrollbar.

But also I think we should try to avoid long lines: in this case, for example, we could have something like:

transform: scale(2, 0.5) rotate(50deg);

That still makes the point but is much shorter.

Also, in these cases the "Reset" button obscures the end of the line. I don't think this is as much of a problem, but again we should design the content to try to avoid this.

CSS examples: tab behavior is weird

If I load, say, https://developer.mozilla.org/en-US/docs/User:schalkneethling:transform and press Tab, the last item gets a dotted grey border, as if it's selected, and its Reset button appears.

If I press Tab after having selected a few different rows, then their Reset buttons appear: http://imgur.com/a/47YZm.

We should probably think about what we want Tab behavior to be. Ideally it feels like it should:

  • focus the Reset button in the current row, if that row has an active reset button
  • or select the next row (as if you had clicked to, so you can start typing)

Instrument with GA

In order to determine how/if users are using the interactive samples we need to instrument the live code samples. This issue tracks the instrumentation of the examples as well as clearly defining what needs to be instrumented.

CSS examples: "Reset" does not persist

With the CSS examples, if I change the initial contents of row A, the Reset button appears. If I switch to a different row, the button disappears - this is as expected. But if I then switch back to row A, the Reset button does not reappear - it's now impossible to get back to the original without reloading the page.

CSS examples: initial cursor placement is strange

Trying out: https://developer.mozilla.org/en-US/docs/User:schalkneethling:transform

If I click one of the examples, then reload the page, the cursor is placed oddly: visually it appears between the currently selected item and the previous item. Logically it appears on the line before the selected example. If you just start typing, you see default-font text.

I've attached a GIF to try to explain: http://imgur.com/a/5AWvy.

The cursor should probably be initially placed at the end of the selected row. I don't think it should be possible to put the cursor in the place shown in the GIF.

Conditionally show live examples based on feature detection

[Schalk]

Do we want to do feature detection for certain examples and only show those that are supported by the browser? Is there a baseline we want to define and say, if the feature does not meet our baseline, do not add it or, is there another way you would suggest?

[Stephanie]

The samples are meant to showcase the technology. For example: I would not include the -ms- prefix to make a flexbox demo work in IE 10โ€ฆ I would suggest we:

  • Show a plain text version of the example (I assume we have a plain text version already? since we need to serve something to our users with js disabled)
  • Put a small note beneath it that their browser does not support the feature. Thoughts?

Investigate switching to Prism for JS examples

Investigate the amount of effort involved in switching the JS examples over to using Prismjs as apposed to CodeMirror.

The main benefits are:

  1. Lighter code base
  2. Consistent theming for syntax highlighting
  3. Improved maintenance as we drop one dependency

It's possible to delete rows

If you select all the text in a row and delete it, the whole row has gone and you can't reset: http://imgur.com/a/hdK19

I don't think this should be possible.

Also, if you position the cursor at the start of the row and press delete, the row gets smaller: http://imgur.com/a/Ns8eq

I don't think this should be possible either (the rows should just be fixed one-line things IMO).

Typing "while(1){}" then clicking "Run" hangs the browser

Note that e.g. codepen.io detects this kind of thing. I think they take a heuristic approach: like, it runs the example for a couple of seconds, then kills it if it is still running. I think this would be more robust than trying to detect all the ways someone could get into this situation.

Use AWS/S3 for generated pages

Currently generated pages are pushed to a gh-pages branch to be served via Github. This will not scale well so, we need to have a S3 bucket that these pages can be pushed to via Travis-CS

Reset Reset button

Can the reset button fade out again after it's clicked until the user makes another edit? It seems like a good way to signal to the user that it has done its job.

Change layout for CSS examples

CSS examples will work much better with a side by side display. This issue tracks the implementation of side by side display for CSS examples with a fallback to examples on top, output at the bottom.

Refactor enableLiveEditor function

This function is completely out of hand now ;) I need time to refactor it so we have less event handlers and definitely not adding event handlers inside loops.

Should we style the iframe differently for no-js

As I wrote up the brief for Brigade I noticed that, especially the JavaScript example, look pretty odd when JS is disabled.

screen shot 2017-07-18 at 11 13 45

Here is an example of the CSS example:

screen shot 2017-07-18 at 11 50 14

Couple of questions on this then:

  1. Will the JS interactive example, and thus the static fallback replace the syntax block? Like for example here?

https://developer.mozilla.org/en-US/docs/User:schalkneethling:push

screen shot 2017-07-18 at 11 59 30

If that is the case, we should probably:

  1. Have the default height of the iframe be a lot less tall.
  2. Add the blue side border to the output area as it is on the current Syntax example
  3. Add a Syntax heading that will be displayed as part of the fallback

The CSS is a bit more tricky perhaps or, maybe we can do the same. Thoughts @stephaniehobson @wbamberg

Do not use eval

Do not use eval for JS code execution. Function gives us all we need, and does not have the security problems of eval

MDN integration of new examples

I tried embedding some of them in MDN pages, and noticed a few things.

For example, compare:
https://developer.mozilla.org/en-US/docs/User:wbamberg/Examples_on_top/filter_old
https://developer.mozilla.org/en-US/docs/User:wbamberg/Examples_on_top/filter_new

  • the examples don't get any border at the top
  • the old version is more compact
  • the help text "Try editing the selected examples, or select a different example below:"
    should have a style that matches the page.

I tried embedding some of the new ones, for example: https://developer.mozilla.org/en-US/docs/User:wbamberg/Examples_on_top/animation_new

  • when I load the page initially, the cursor ends up in a weird place, right under the "Try editing the selected examples, or select a different example below:" line.
  • you can see (I hope you agree :) that the big comment about slidein is quite distracting
  • the lines are too long for the content column, so we get horizontal scrollbars

Handle JS disabled

When JavaScript is disabled we want to simply show the code for the examples without the output section as static text that is not colour coded.

JS editor: disable/hide Reset button unless it's needed

This also came up in SF: people we confused about the Reset button and suggested it might be clearer if the Reset button was either hidden or disabled if the contents of the editor had not been changed. This might be a signal about what the button does.

I'm not sure if hiding or disabling is better.

Make CSS and JS code match

All syntax highlighting on MDN should match.

Currently the CSS examples and MDN's code examples use Prism with the default theme.

Two questions need to be resolved to make all 3 match:
Can we switch the JS examples to use Prism? (Are there technical reasons it does not use it currently?)
What do we want all 3 to look like? (Will and I liked Code Mirror's "eclipse" best of the Code Mirror themes)

Make all buttons match

The buttons in the JS and CSS examples should match.

I suggest the following styles for all reset buttons:

background-color: #fff;
border: 2px solid #9b9b9b;
color: #4c4c4c;
font-size: 14px;
line-height: 1;
padding: 3px 5px;

And the following change for the run button in the JS examples:

border: transparent;
background-color: #29627e;
color: #fff;

This gives the buttons roughly the same proportions as the redesign ones but makes them a bit smaller to fit better.

Feature not supported case

When a JS or CSS feature is not supported by the current browser we want to instead fallback to a static example. Need to decide whether we want to include a lib to handle the feature detection or, create a minimal lib that handles only known cases.

For this iteration, it was decided that if one of the examples is not supported, we fallback to static examples.

Invalid CSS notification does not work correctly

The "invalid CSS" thing doesn't seem to work properly any more. For example, if you visit the original https://mdn.github.io/css-examples/editable-samples-2/pages/filter/ and edit a function so it's misspelled, you get a little warning in that row. It's displayed immediately, and hidden if you select a different row (but is shown again if you go back to the broken row). If you do the same in https://mdn.github.io/interactive-examples/pages/css/filter, the warning seems to be shown immediately in the first row, but not in the broken row (but is shown in the broken row if you go back to it).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.