Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebComponent support - specify where dynamic styles go instead of head #540

Closed
newlukai opened this issue Oct 14, 2016 · 7 comments · Fixed by #1152
Closed

WebComponent support - specify where dynamic styles go instead of head #540

newlukai opened this issue Oct 14, 2016 · 7 comments · Fixed by #1152

Comments

@newlukai
Copy link

We try to integrate Gridstack in a WebComponent/Polymer environment which means to embed Gridstack in a custom element. We recognized that the dynamically calculated stylesheets for the height of items is added to the head node, so the styles are not available inside the shadow DOM of the custom element.

In order to enable Gridstack for WebComponents it would be great if Gridstack would be aware of the Shadow DOM and for example allow to provide the DOM root where to place the dynamically created stylesheets.

@IftachSadeh
Copy link

Hey radiolips,

Can you please say if this is expected to be fixed? Currently use with polymer is simply impossible.
If it's not a priority, is there a recommended workaround in the meantime?

@VinodLouis
Copy link

Any one got workaround for this ?

@VinodLouis
Copy link

VinodLouis commented Aug 25, 2017

I tried something in case if anyone is interested https://github.com/VinodLouis/polymer-gridstack

[adumesny] Note: this code IS NOT BASED on gristack (nor maintained), or is older than 2014.

@radiolips
Copy link
Member

@VinodLouis Can you create a PR with changes such that gridstack would work as a web component?

@adumesny adumesny changed the title Adjustable node for dynamic height styles WebComponent support - specify where dynamic styles go instead of head Dec 22, 2019
@adumesny
Copy link
Member

adumesny commented Dec 22, 2019

I use angular component for this lib, and having local to that components styles would be better and might be using webcomponents soon as well.

@VinodLouis wish you had done a PR instead of creating a fork off the code!

looking at your file you have var GridStackEngine = function (width, onchange) which means it is very very old (or not based on gridstack but maybe gridster?) as the float param feature was added back in 11/19/2014 2 days after this project started....
(all the methods were renamed to camelCase in 2/17/2016 which do you not have either). And you released your in Aug 2017 ???

Note: that gridstack auto-generated CSS files added to the head on 11/25/2014 (for y and height in px) which you don't do
Note2: the only real change I see vs our first file (other than missing float, oneColumn, etc...) is changed
appendTo: 'body', to appendTo: 'parent',

@adumesny
Copy link
Member

adumesny commented Feb 17, 2020

the offending code is:

var Utils = {
  createStylesheet: function(id) {
    var style = document.createElement('style');
    style.setAttribute('type', 'text/css');
    style.setAttribute('data-gs-style-id', id);
    if (style.styleSheet) {
      style.styleSheet.cssText = '';
    } else {
      style.appendChild(document.createTextNode(''));
    }
    document.getElementsByTagName('head')[0].appendChild(style);
    return style.sheet;
  },

  removeStylesheet: function(id) {
    $('STYLE[data-gs-style-id=' + id + ']').remove();
  },
}

which can be overridden using:

$(function () {
  window.GridStackUI.Utils.createStylesheet = function(id) {
    //...new code...
  };

  $('.grid-stack').gridstack();
...
});

@adumesny adumesny mentioned this issue Feb 17, 2020
2 tasks
@adumesny
Copy link
Member

sorry for taking so long to address. fixed in 0.6.4

adumesny pushed a commit to adumesny/gridstack.js that referenced this issue May 12, 2020
* insert style before our grid (instead of head) to support webcomponent
* fix gridstack#540
* tested on Chrome, FF, Edge, IE11 and all our demos
*Note: I didn't have a way to test webcomponent support, but this should do it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants