Git Product home page Git Product logo

trimmings's Introduction

Trimmings logo

Trimmings

What happens to your web development process when you can focus on designing views and stop thinking about how to stitch them together? Trimmings by Postlight is a zero-configuration JavaScript library that adds a layer of smooth and fast in-page interaction to your web pages. All you have to do is add some hints to the HTML you already have.

Read more about it in our introduction to Trimmings.

This project follows in the footsteps of libraries like Turbolinks and Stimulus. It believes that the best place for your business and rendering logic is on the server, that you should send your users HTML, and that JavaScript is best suited for progressively-enhanced DOM manipulation. Trimmings is a set of patterns that allow you to add DOM manipulation to your app by adding data-trimmings-* attributes to your interactive elements. Less JavaScript in your project means less risk.

Once you've built your website and it's serving HTML that's presented the way you like it, you can start adding Trimmings hints that will enhance the way your interactions behave.

Perhaps you have a link to a detail page that you'd like to open in a modal. The standalone page probably has a header and footer that you wouldn't want to render in your modal. That's no problem. Just add an inline hint to your link:

<a data-trimmings-inline="from: .detail-container, to: .modal-container" href="/photos/2">
  View as a modal
</a>

If your visitor clicks that link, the page will be fetched in the background, the element with the detail-container class will be extracted from the result, and it will be inserted in an element with the modal-container class that's already on the page. You can write CSS that will make this show up however you like. Now you have a modal! That's all there is to it!

Installation

Just include trimmings.js in your <head>. That's it. Trimmings will automatically activate when your page loads—no need to think about lifecycles.

<script src="/trimmings.js"></script>

Usage

Trimmings features are enabled on specific elements by adding data-trimmings-* attributes. For more details on usage of each Trimmings feature, please consult the Trimmings handbook.

License

Licensed under either of

at your option.

Contributing

If you've found a bug or you'd like to propose a new feature, submit an issue and let's talk about it!

We expect that all contributors to Trimmings will abide by our Code of Conduct.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.


🔬 A Labs project from your friends at Postlight. Happy coding!

trimmings's People

Contributors

dependabot[bot] avatar ginatrapani avatar johnholdun avatar therumbler avatar wismer 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

trimmings's Issues

"Autosubmit + Replace" feature

Looking through the autosubmit and the replace javascript.

Wondering how to best write a "search" feature.

How I'd like it to work: On input change, submit the form, and replace the dom section. I also have a couple of checkboxes that I'd like to do the same thing.

Check for newly-revealed nodes based on media query changes

The embed feature does not fetch an embedded link if the <a> has the display: none; property, which is handy for avoiding extraneous network calls on mobile devices, for example. If one of these links is revealed after the DOM is loaded as the result of a media query, it should be detected and fetched.

Note that we already listen for orientationchange events, so we just need to handle viewport size queries.

IE11/Edge support

The tests run in Chrome and I've done plenty of testing manually in Safari and Firefox, but we should make sure this works in IE11 and Edge as well.

Embed vs Inline

Is there a significant difference between these two features? I was trying to understand the difference but it's not clear to me from the docs. They seem to serve a similar purpose which is to inline content.

"Remove After" feature enhancement

Maybe the Remove feature could be extended to accept a delay value:

<button data-trimmings-remove=".modal" data-trimmings-remove-after="5">
  Close modal
</button>

If no delay value is provided it waits for a click (current behavior). If a delay value is provided it removes the element after the delay time, whether a click was detected or not. Great for automatically dismissing notifications.

Similar to what @snellingio mentioned in #1

Transitions

Unsure if this is supported, it might already be by adding css classes.

If so, we should document how to use them. I can see wanting to transition both the content (think counter) and the content area (think modal)

"Auto" feature

Automatically interact with something after a specified duration, or when it comes into view. Useful for automatic data refreshes and infinite scroll.

  • What should this be called? "Autoclick" works for links and buttons but we should allow form submission as well. Maybe just "Auto?"
  • Should we consider time-based and visibility-based interactions to be two options of the same feature, or two different features?

"Refresh" feature

See #1

I would like to see an option to refresh a section every X (where X is in ms, sec, or minutes).

Would essentially be a long polling feature.

"Swipe" feature

Add a feature that listens for swipe gestures and clicks/submits the targeted element.

<div 
  class="deck-slide"
  data-trimmings-swipe-right="a.next-slide"
  data-trimmings-swipe-left="a.previous-slide"
>

"Trimmings"

I know that adding -trimmings to all the data elements namespaces it nicely. However, it seems a bit silly to write -trimmings on every data element. data-inline or data-replace seem like that wouldn't collide with anything anyways.

Same thing goes with writing css classes with trimmings in them (on the enabled and on the current feature).

Maybe there is a happy medium to be had here.

If not, feel free to close. Just thinking out loud.

"Before Cache" / "Event" feature

I'd like to create a dropdown with the Toggle feature. However, the toggle will remain open on hitting the back button with Turbolinks. Using stimulus and turbolinks, I'd normally either remove the node or add / remove a class.

Maybe there is room for a before cache feature? Or alternatively, maybe an event feature might keep it more flexible?

Inline - optional from and to parameters

Presently you have to duplicate where you want to load from and to for the inline feature:

<a
        data-trimmings-inline="from: main, to: main"
        href="/cake"
      >
        Cake
      </a>
... etc
... etc

This can get pretty repetitive if you serve just a partial from the server of the exact element to be replaced.

So it would be great if the from and to were both optional and infered based on the top-root element in response from the server.

For example:

<a
        data-trimmings-inline
        href="/cake"
      >
        Cake
      </a>

Response from server:

<main>.....</main>

Trimmings will assume from: main, to: main

Another example:

<a
        data-trimmings-inline="to: custom-main"
        href="/cake"
      >
        Cake
      </a>

Assuming the same response from the server <main> trimmings will essentially assume:

from: main, to: custom-main

"Loading" feature

Currently, there is a "trimmings-loading" class on both the embed and the inline feature.

Would like to see a "saving" class on the autosubmit, as well as a "loading" class on the inline.

"Morph" as replacement method

I'd personally like to see something like nanomorph brought in as a replacement method for both inline and replace.

Totally understand if you do not want to add another dependency or more surface area.

Handle non-200 requests

When features that involve fetching external documents receive unexpected responses, their behavior should change. Generally, this means that they should fall back to working like regular, unenhanced links and forms.

For example, if an inline link fetches a URL that returns a response with a status code in the 400 or 500 range, it should just display the full response as if the user clicked a regular link, as we cannot ensure that the targeted elements actually exist on the page or that the fetched content can reliably be rendered on the current page. An embed that returns a 400+ response should do nothing, leaving the enhanced link on the page for the user to click if they so desire.

300 requests should probably be followed, which is the default behavior when using fetch, so there's no work to be done here.

Inline form submission should support multipart

Currently, an inline-enhanced form will only submit data as application/x-www-form-urlencoded. It would be nice if Trimmings would respect enctype and submit multipart forms appropriately.

More clarity around how to use it?

I'm super stoked about this project, but a bit confused about how to use it!

  • The installation says "just include trimmings.js in your " But the only spot I see a trimmings.js file is when I look at the code over on glitch
  • The Getting Started is more like background; it doesn't quite explain how to use Trimmings.

I hope this can get a bit more user-friendly, because I loooooove the idea and the background behind it. Y'all rule!

Docs for "Inline": descriptions for arguments "to" and "from"are reversed

The arguments "to" and "from" work the other way around (unlike in the documentation)
It should be like that:

  • from: A selector targeting the linked page where our content will come from. (required)
  • to: A selector targeting an element in the current document where our content will be inserted. (required)

(Thanks for making trimmings, it's great!)

Configure default parameters for ajax requests

It would be great if we could configure the ajax/fetch requests to include additional information, a bit like axios config defaults

Our use case is that we want to add a custom header X-Requested-With-Trimmings that way we can detect this on the server and only serve partial HTML if we know we don't need to render the full page.

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.