GithubHelp home page GithubHelp logo

mnot / hinclude Goto Github PK

View Code? Open in Web Editor NEW
307.0 307.0 71.0 173 KB

declarative client-side inclusion for the Web

Home Page: https://mnot.github.io/hinclude/

License: MIT License

JavaScript 75.03% Shell 1.56% Makefile 2.66% HTML 20.75%

hinclude's People

Contributors

acasademont avatar fabiofabbrucci avatar gobengo avatar gyzo avatar ickbinhier avatar jdreesen avatar mnot avatar peter-gribanov avatar rjkip avatar scaule avatar yberkholz avatar yoavweiss 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

hinclude's Issues

New release including package.json would be appreciated

I have an old project that requires version 0.9.5 but it fails to install because that version lacks a package.json file. The package.json file is the latest commit, but there are currently no new releases.

I'm afraid I'm gonna have to include master, but that's not a very nice thing to do.

Browser support

Sorry if this has an obvious answer, but could you specify the supported browsers' versions somewhere, please?

Add X-Requested-With header

Hi,

I think it should be nice to have hinclude send and "X-Requested-With" header with the value "XMLHttpRequest"

Most js framework send this header with ajax requests and the server side framework i know (including symfony2 which has support for hinclude) use this header to help detect ajax requests

Thanks
Tom

Using the refresh feature

Maybe I'm missing something here, but with the current version, there is no way to actually access the refresh feature of hinclude.

Since there is no exports once the file is loaded and ran you can no longer call hinclude.refresh('element-id'); as hinclude is not in the global scope, nor able to be required or imported.

Open to corrections or suggestions?

Conditional call

Is there a way to call the ajax request only on certain condition, like if the user has a cookie ?

The idea

By default, the website contains a anonymous header.
If the user has a user_id cookie, we call the wanted source.

Today I can still make the ajax call but as 90% of my visitors are anonymous, I don't want to make a useless call.

thanks

Maintainers sought

In case it's not obvious, I haven't been doing much in this project for some time.

If someone is interested in helping maintain it, please say so here - ideally someone who has made contributions in the past, but anyone who is keen and has some experience maintaining JavaScript projects would be welcome.

Otherwise, I'll likely deprecate the project (that's what I was inclined to do first, but it still appears to be in use elsewhere).

Hinclude on event (like click)

Hi all,

i want use hinclude on a event (click on button)

but i cant "prepare" a hx:include, add a src on event and refresh it

if i do :

<hx:include></hx:include>

i obtain a error "url is null"

so i do :

$('#container').html('<hx:include src="/hincludePage"></hx:include>');
hinclude.run();

do u have a better solution ?

thx for your time

Nested hinclude's

It is not possible to nest hinclude's. If the loaded content of a hinclude has another hinclude inside, nothing happens. Just the default text between the tags is shown.

IE8 and below

When using hinclude with IE8 and below, I'm getting an "Unknown Runtime Error" on line 54? This happens with any content I try to render in IE.

include[0].innerHTML = include[1].responseText;

Is it just me?

Edit:

Tried it simply with:

<b>Hello!</b>

Async add table rows

I want to include rows in a async fashion to speed up page loading and for better caching of the view fragments.

Therefore I use hinclude.js to load the fragment asynchronously. The fragment just contains a table row (e.g.):

tr
td 29 /td
td 60% /td
td Foo, Bla /td
/tr

Problem is that this is not added as html at the position, the browser does interpret it before positioning it. This leads to the result that all tr and td are stripped away.
Any solution to use hinclude to just load some table rows?

Thanks in advance.

source : http://w3javascript.com/question/async-add-table-rows/

"Refresh" based on an event

Would love to have default support to "refresh" the hincluded section based on an event.

For example:

  • You click a button
  • You trigger for example a window event called: something_clicked
  • The hinclude will show the default text it should show like "Loading..."
  • The hinclude wil be "refreshed" with new content from the src attribute

This can be very usefull when working with session specific data, like a cart, etc.

The hinclude tag could be something like

<hx:include src="/remote.html" data-on="window.something_clicked">Loading...</hx:include>

You can make it a "rule" that the "on" attribute must exists of [css-selector].[event-name]

So next data-on attributes are valid:

  • data-on="#my-container.refresh"
  • data-on=".container.my-custom-event"

hx:include tag is messing up the head tag

I'm using hinclude to include a CSRF token in a laravel blade page that has been cached with HTTPCache.
When I put the CSRF token inside the body tag, everything works as expected.

<body>
<form>
<hx:include src="/csrf/input">
	<input type="hidden" name="_token" value="2viCQ8L7G0aHOsEQwf811kR2wLoozZl3uhEemshv">
</hx:include>
</form>
</body>

But when I put the CSRF token in a meta tag in the head (for AJAX requests), the head gets mixed up when I look in the web inspector. The hx:include tag has been moved to the body(!), and every tag that comes AFTER the hx:include tag in the head, is also moved to the body. See code example below.

My question is: am I doing something wrong here? Or are we not supposed to us the hx:include tag in the head?

View source (Chrome):

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<script src="/assets/themes/ambion2020/js/vendor/hinclude/hinclude.js"></script>
	<hx:include src="/csrf/meta"></hx:include>
	<meta name="description" content="">
	<meta name="keywords" content="">
</head>
<body>
	<div class="wrapper"></div>
</body>
</html>

Web Inspector (Chrome/Firefox):

<html lang="en"><head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<script src="/assets/themes/ambion2020/js/vendor/hinclude/hinclude.js"></script>
</head>
<body>
	<hx:include src="/csrf/meta" class="included include_200">
		<meta name="csrf-token" content="2viCQ8L7G0aHOsEQwf811kR2wLoozZl3uhEemshv">
	</hx:include>
	<meta name="description" content="">
	<meta name="keywords" content="">
	<div class="wrapper"></div>
</body>
</html>

data-attributes instead of "meta"-elements

I've read #13, but I'm unsure, if that arguments fits here, because it is a slightly different suggestions.

To keep things together, whats about data-*-attributes instead of meta-elements

<script 
  data-include-mode="async"
  data-include-timeout="2"
   src="/lib/hinclude.js"
   type="text/javascript">
</script>

One argument is, that both are not really documents metadata, but values for the script

Controller attributes cannot contain non-scalar\/non-null values

I would like to provide my controller object like this with hinclude.js :

{{ render_hinclude(controller("AppBundle:Default:Test"), { 'my_object': object }) }}

Unfortunately I got this error:

An exception has been thrown during the rendering of a template ("Controller attributes cannot contain non-scalar/non-null values (value for key "object" is not a scalar or null).")

Can you help me ?

Thanks in advance !

Refresh a hx:include

Hi,
is there a way to call the refresh of an ?
Something like $('hx:include').refresh();

Rendering JSON data

HInclude does a good job of fetching HTML and injecting that into the DOM. This obviously requires the data to be rendered server side. I would like to explore the possibility of extending this with the ability to render data client side.

There are quite a few JavaScript libraries for taking JSON data and render it in HTML. One of my favorite ones is mustache.js. It can be extended with ICanHaz.js to allow you to define the templates inline in the HTML.

I would love something like this for HInclude, so it can help remove the glue code you need today if you want to fetch JSON and have it rendered in HTML. The following is an example of what it could look like.

<hx:render src="/api/members.json">
  <h1>Meet our <em>{{count}}</em> members!</h1>
  <ul>
  {{#members}}
    <li>{{name}}</li>
  {{/members}}
  </ul>
</hx:render>

What do you think of this idea? Would functionality along these lines fit within the scope of HInclude?

seo friendly

Hello,

i would like use hinclude for a e-commerce website. The system is friendly with google and others ?

Thanks to you ! 👍

Missing parameter when call include in refresh method

Hi,

in refresh method you call include method, but missing media parameter :

refresh method :

    refresh: function (element_id) {
      var i = 0;
      var mode = this.get_meta("include_mode", "buffered");
      var callback = function (element, req) {};
      callback = this.set_content_buffered;
      for (i; i < this.includes.length; i += 1) {
        if (this.includes[i].getAttribute("id") === element_id) {
          this.include(this.includes[i], this.includes[i].getAttribute("src"), callback);
        }
      }
    },

include method :

include: function (element, url, media, incl_cb) { ... }

will be :

    refresh: function (element_id) {
      var i = 0;
      var mode = this.get_meta("include_mode", "buffered");
      var callback = function (element, req) {};
      callback = this.set_content_buffered;
      for (i; i < this.includes.length; i += 1) {
        if (this.includes[i].getAttribute("id") === element_id) {
          this.include(this.includes[i], this.includes[i].getAttribute("src"), this.includes[i].getAttribute("media"), callback);
        }
      }
    },

Switch from namespace to data attributes

Hi @mnot ,
what do you think about switch from this

<hx:include src="http://www.google.it" id="google"></hx>

to this

<div data-src="http://www.google.it" id="google">

?

I dont like so much to add a new namespace, so I would prefer to use a TAG that is already available in DTD.
Can you see any problems in this?

review addDOMLoadEvent

Make sure that addDOMLoadEvent is still relevant / correct, and plays nicely with jquery, etc.

Tests

hinclude needs tests; probably Selenium, but maybe also by examining the dom with JS.

Async data display

on a symfony2.6 page I have several blocks that are rendered by twig render_hinclude.
The response content doesn't updated asynchronously but waits while all hinclude requests will finish and then updates all blocks with corresponding content.

Is it possible to make it to display content immediately as request is finished.
thanks

Using hinclude to display a response multiple times

As hinclude is now used within Symfony2 (it's in their docs), I came across an issue I hope could be fixed.

The issue was reported here.

The gist of the issue is that I'm using hinclude to retrieve data that I want to display multiple times on my page (not really an edge case). If I want this to happen, I can either make multiple requests for the same data (very poor).. or use JavaScript to write a loop that waits for hinclude to perform it's stuff, parses for the data between the <hinclude> tags, and then propogates this throughout the code.

As a result of using JS to perform this, I feel that I might as well ditch hinclude and use a regular XMLHTTPRequest or jQuery's $.ajax().

I really don't want to go down the road of pulling in jQuery if I can avoid it. Please could you suggest whether or not a solution for this could be obtained?

Possibility to personalize the method request

Would it be possible to personalize the method of the XMLHttpRequest for each include with attribute "method" on the hinclude tag with GET by default ?

<hx:include src="/src" method="post"></hx:include>

?

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.