Giter VIP home page Giter VIP logo

lazy-component's Introduction

Lazy component

๐Ÿ”ง Component for Nette framwork which helps with creation of lazy ajax loaded components.

Introduction

Component which renders empty in the beggining and is populated by signal request.

Installation

Install package using composer

composer require infinityloop-dev/lazy-component

Dependencies

How to use

  • Create new component and extend \Infinityloop\LazyComponent\LazyComponent instead of \Nette\Application\UI\Control.
  • Trigger handleLoadComponent to load and redraw component.
  • Use macro {control componentName} to render your component as you would normally.
  • Additionaly use {control componentName:loadComponentLink} to get URL for loadComponent signal.
    • Useful for rendering URL (eg. into data attributes) so you can easily trigger signal from javascript.
  • Make sure LazyCompoennt::render() method is called if you choose to override it.
    • Preferably use beforeRender() to pass variables into template.
    • beforeRender() method is not called when empty template is used (when component is not loaded).
  • Template for your component is automaticaly deduced to be have same name (and path) as your .php file.
    • File extension is simply swapped to .latte.
  • By default the FontAwesome 5 spinner is used as placeholder. Override EMPTY_TEMPLATE constant to use different empty template file.

Example lazy tab content

Tab header:

<li class"tab" data-load-component="{control myComponent:loadComponentLink}">Tab name</li>

Tab content:

<div class="tab-content">
    {control myComponent}
</div>

JQuery ajax request on click:

$(".tab[data-load-component]").one('click',function (event) {
    const link = $(this).data("load-component");
    $.nette.ajax({
        method: 'GET',
        url: link,
    });
});
  • Load event is executed only once (jqery.one).

lazy-component's People

Contributors

peldax avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

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.