Skip to content

Allow using Webcomponents.js 1.x #86

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions lib/com/vaadin/polymer/Polymer.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import elemental2.dom.HTMLElement;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -43,6 +44,14 @@ public abstract class Polymer {
@JsProperty(namespace = JsPackage.GLOBAL)
public static native String getGwtBowerLocation();

/**
* Set path to webcomponents.js - default webcomponentsjs/webcomponents-lite.min.js
*/
@JsProperty(namespace = JsPackage.GLOBAL)
public static native void setWebcomponentsJsLocation(String s);

@JsProperty(namespace = JsPackage.GLOBAL)
public static native String getWebcomponentsJsLocation();

static {
if (getGwtBowerLocation() == null) {
Expand All @@ -54,6 +63,9 @@ public abstract class Polymer {
}
setGwtBowerLocation(moduleBase + "bower_components/");
}
if(getWebcomponentsJsLocation() == null) {
setWebcomponentsJsLocation("webcomponentsjs/webcomponents-lite.min.js");
}
}

@JsType(isNative=true, namespace="Polymer")
Expand Down Expand Up @@ -269,6 +281,8 @@ public static void importHref(String hrefOrTag, final PolymerFunction ok, final
pending.add(ok);
}
return;
} else {
Base.importHref(href, done, err);
}
urlImported.add(href);
}
Expand Down Expand Up @@ -333,7 +347,7 @@ public static <T> T createElement(final String tagName, final String... imports)
}

public static <T> void ensureCustomElement(final T elem, String... imports) {
if (isRegisteredElement(elem)) {
if (isRegisteredElement(elem) && urlImported.containsAll(Arrays.asList(imports))) {
return;
}

Expand Down Expand Up @@ -427,7 +441,7 @@ function done() {
function loadPolyfill() {
var s = $doc.createElement('script');
s.src = @com.vaadin.polymer.Polymer::absoluteHref(*)
('webcomponentsjs/webcomponents-lite.min.js');
($wnd.webcomponentsJsLocation);
s.onreadystatechange = s.onload = done;
$doc.head.appendChild(s);
}
Expand Down