Code Monkey home page Code Monkey logo

tdi's People

Contributors

centi avatar dependabot[bot] avatar mishal avatar msevcenko avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

mishal

tdi's Issues

TDI should not intercept link click when clicked with ctrl key

When link is clicked with a ctrl key pressed, the user indicates that he wants to open the result into a new window. I think that TDI should in this case just ignore the TDI condition and progress with the default behavior, which is sending normal request and opening the result to a new window.

Maybe this behavior may be preventable (indicated by class, or data attribute), if the author of the link knows that opening to a new window has no sense and TDI in the current window should take place anyway.

Such as like this:

function _onBeforeLinkClick( evt ) {
            if (evt.ctrlKey) {
                // do not intercept ctrl+key
                return;
            }
            evt.preventDefault();
            ...
}

Submit mutipart forms using normal ajax

Consider implementing of multipart form submit using regular ajax, which should be supported by modern browsers, instead of hacky fake ajax simulated by iframe.

It would provide more consistent bevarior, such as the possibility to send custom http headers which may be sent by other ajax calls.

On error, tdi:ajax:error may be triggered multiple times

The implementation of _error, triggers tdi:ajax:error on involved elements, or on document by default. However, there may be multiple involved elements, in which case the event is fired multiple times for each element.

Typical usage of the event is

$(document).on("tdi:ajax:error", errorHandler);

The errorHandler is usually not interested in the element which triggered the event (involved element or the document), and calling the handler multiple times is not desired.

Treat update/insert target attribute as ID

Sometimes, the ID attribute (used as target) contains characters which have special meaning in CSS selectors (dot, colon). Using $(id) method causes troubles in these cases.

As the target attribute must contain only ID anyway, TDI should use something like this to find the target element: $(document.getElementById(target))

Submitting form containing file data via TDI with jQuery v1.10.1 and IE11 fails

Fails with error in Sizzle.setDocument in the following code:

    // Support: IE>8
    // If iframe document is assigned to "document" variable and if iframe has been reloaded,
    // IE will throw "permission denied" error when accessing "document" variable, see jQuery #13936
    if ( parent && parent.frameElement ) {
        parent.attachEvent( "onbeforeunload", function() {
            setDocument();
        });
    }

parent.attachEvent being undefined in IE11.

Events are triggered multiple times when submitting a form

Events (such as ajax:tdi:start, ajax:tdi:end etc.) are being triggered N-times when a form is being submitted; where N corresponds with a length of the array data.options.involvedElms of the data param of a callback function bound to events mentioned above (see the example below). As you have noticed, it's probably caused by TDI that is trying to notify each participated element.

Example:

In the following example, both mentioned events are triggered two times; for the first time with a form as an event target and for the second time with a button.

<a href="[url]" class="tdi">link</a>

<form class="tdi" method="post" data-ajax-url="[url]">
    <input type="submit">
</form>
require(['jquery', 'tdi'], function($, TDI) {
    $(function() {
        $(document).on('tdi:ajax:start', tdiStartCallback);
        $(document).on('tdi:ajax:end', tdiEndCallback);

        function tdiStartCallback(evt, data) {
            console.info('EVENT: tdi:ajax:start');
        }

        function tdiEndCallback(evt, data) {
            console.info('EVENT: tdi:ajax:end');
            
            // contains the participating elements:
            // - link click –> the <a> only
            // - form submit –> <form> and <input type="submit">
            // data.options.involvedElms

        }
    });
});

(To be sure, I included the require.js statements too.)

TDI infusing parameter

Shouldn't we rename the "_infuse" parameter to "_tdi"?

My suggestion is to remove it with a possibility to force the old behavior by some JS parameter/configuration.

_infuse does no longer mean just infusion. And this may lead to confusion.

Coding style spec

What coding style does TDI use?

Could it be reformatted using any well known one so eslint or another tool can be used to check the source?

Event tdi:ajax:update does not work with replace="true"

When replace="true" is used on a <update> instruction, the event tdi:ajax:update is not triggered, because the element on which it is triggered is no longer a part of the DOM.

The event should be triggered on the new element.

Script instructions do not work sequentially

When a TDI response carries two script instructions, one with src and the other one inlined, the first one is not completely loaded before the second one starts. If the second instruction depends on definitions made by the first one, it may fail unexpectedly.

Example:

<status>OK</status>
<script id="demo-hiding-support" src="some-file.js"></script>
<script>
    someFunctionX();
</script>

If the someFunctionX is defined in the some-file.js, the very first call fails saying it is not defined yet. Repeated invocation do work.

Split testing into Unit and Integration

Current tests are starting to be a hinderance in the development process. They are really slow.

Tests should be divided into 2 groups:

  1. Fast unit tests for testing the API: these could (and should) be run as often as possible.
  2. Some sort of integration tests in a real browser(s): run during a build process (travis)

Allow custom attributes for default update/insert instructions

Our use case:

<update target="#target" custom-attribute="value" />

Js hook:

$(document).on('tdi:ajax:beforeUpdate', function (e, eventData) {
  var $target = eventData.target;
  // there no access to the original tag attributes
});

As per docs there are several properties of the event playload available, but there is no access to the original tag attributes (like in _onBeforeUnknown).

I patched the TDI function which triggers the event and includes the additional tag attributes. I can now access the tag attribute:

$(document).on('tdi:ajax:beforeUpdate', function (e, eventData) {
  var $target = eventData.target;
  var $tag = eventData.tag;
  var customAttribute = eventData.attributes['custom-attribute'];
  // do something cool :-)
});

We use the attribute to decide if the UI should highlight another element. We used script instructions before, but it was problematic.

Could TDI include the additional/original tag attributes for update and insert instructions?

Add support for window.pagehide event

Lighthouse penalizes for "unload" event. Possible replacement is the "pagehide" event:

const terminationEvent = 'onpagehide' in self ? 'pagehide' : 'unload';
addEventListener(terminationEvent, (event) => {
  // Note: if the browser is able to cache the page, `event.persisted`
  // is `true`, and the state is frozen rather than terminated.
}, {capture: true});

tdi:ajax:updatesDone event sometimes does not fire on document

Since some version the tdi:ajax:updatesDone event is fired preferably on "involved elements", which may be the DOM element that triggered the TDI request, such as link. TDI relies on the event bubbling from the related element to the document.

However, if the result of the TDI request is the involved element removed from DOM, the event does not bubble, and the event handlers on document do not get called.

TDI.Ajax.Request.send should support sending parameters in terms of FormData

Sometimes it is required to send data in POST reques using TDI.Ajax.Request.send, which may be potentially large, and would exceed server limit (POST requests are sent url-encoded by default).

multipart/form-request encoding should be also supported. If FormData object is passed to the send method, the call fails. Send method internally uses jquery ajax call, which requires to pass processData = false and contentType = false parameters to successfully process FormData parameters.

Event handlers should not do stopPropagation()

When TDI intercepts a link click, it stops propagation of the click event. Which prevents other components from intercepting the event and doing something useful (e.g. closing menu, dropdown, dialog etc).

Form submit fails with multipart enctype but without file input

If you submit the following form:

<form method="POST" enctype="multipart/form-data" class="tdi">
...
</form>

and the form body does not contain file input, it fails. Presumably because the form is set encoded application/x-www-form-urlencoded, but without proper content type.

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.