Web Components: executing code on the <content> added - web-component

I have been tinkering with web components, and I had the idea to make a <slide-show> component that would work with this syntax:
<slide-show>
<img src="...."/>
<img src="...."/>
<img src="...."/>
<img src="...."/>
</slide-show>
For this, I took a code that was already working, and tried to separate it into a template. A first draft that worked perfectly was this:
Index.html
<slide-show></slide-show>
slideshow.html
<link rel="import" href="../bower_components/polymer/polymer.html">
<polymer-element name="slide-show" attributes="foo">
<template>
<div style="width:500px;">
<div id="slides">
<img src="http://placehold.it/300x200&text=6">
<img src="http://placehold.it/300x200&text=7">
<img src="http://placehold.it/300x200&text=8">
<img src="http://placehold.it/300x200&text=9">
<img src="http://placehold.it/300x200&text=0">
</div>
</div>
</template>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script src="http://www.slidesjs.com/examples/standard/js/jquery.slides.min.js"></script>
<script>
Polymer('slide-show', {
foo: 'bar',
ready: function(){
$(this.$.slides).slidesjs({ });
}
});
</script>
</polymer-element>
But when I tried to move the elements outside the template, it is when things went wrong:
Index.html
<slide-show>
<img src="http://placehold.it/300x200&text=6">
<img src="http://placehold.it/300x200&text=7">
<img src="http://placehold.it/300x200&text=8">
<img src="http://placehold.it/300x200&text=9">
<img src="http://placehold.it/300x200&text=0">
</slide-show>
slideshow.html
<link rel="import" href="../bower_components/polymer/polymer.html">
<polymer-element name="slide-show" attributes="foo">
<template>
<div style="width:500px;">
<div id="slides">
<content></content>
</div>
</div>
</template>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script src="http://www.slidesjs.com/examples/standard/js/jquery.slides.min.js"></script>
<script>
Polymer('slide-show', {
foo: 'bar',
ready: function(){
$(this.$.slides).slidesjs({ });
}
});
</script>
</polymer-element>
In this case, the slideshow behaves "weirdly". Maybe it is that I have not understand correctly how the <content> tag works. What is wrong in my coding?

Related

Bootstrap tooltips progressively off center

https://file.coffee/u/R5wzGxVezHd.gif
I have the following problem using bootstrap's tooltips
The get progressively off centre
Here is the code i use for the icons
{{#each guilds}}
<div class="col-sm-1">
<a href="/dash/{{this.id}}">
<div class="gicon">
{{#if this.icon}}
<img src="https://cdn.discordapp.com/icons/{{this.id}}/{{this.icon}}" alt="{{this.name}}" class="rounded-circle mt-4" width="75" height="75" id="{{this.id}}" data-toggle="tooltip" data-placement="bottom" title="{{this.name}}">
{{else}}
<img src="/public/images/default_guild.png" alt="{{this.name}}" class="rounded-circle mt-4" width="75" height="75" id="{{this.id}}" data-toggle="tooltip" data-placement="bottom" title="{{this.name}}">
{{/if}}
</div>
</a>
</div>
{{/each}}
.gicon {
transition: ease-in-out 0.2s;
}
.gicon:hover {
filter: brightness(80%);
}
Does anyone know why this is happening and how to fix it?
https://jsfiddle.net/kblau237/vx92pnec/3/
I went ahead and coded your example in jsfiddle. You can click on this fiddle and see that the tooltips, are indeed centered. I hope this post helps you. It serves as a model, for having tooltips centered.
I put the image in my folder called Images. It is at the similar level that the javascript code is in Scripts.
https://jsfiddle.net/kblau237/vx92pnec/3/
Script
#{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index6</title>
<style type="text/css">
.gicon {
transition: ease-in-out 0.2s;
}
.gicon:hover {
filter: brightness(80%);
}
</style>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.7.6/handlebars.min.js"></script>
<script type="text/javascript">
//credit stack overflow
$(function () {
$("body").tooltip({ selector: '[data-toggle=tooltip]' });
var an_array = [
{ id: 1, name: "Guild Name 1", imgURL: "https://file.coffee/u/R5wzGxVezHd.gif" },
{ id: 2, name: "Guild Name 2", imgURL: "https://file.coffee/u/R5wzGxVezHd.gif" }
];
var source = $("#src").html();
var template = Handlebars.compile(source);
$("body").append(template({ guilds: an_array }));
})
</script>
</head>
<body>
Tooltips are centered
<script type='text/template' id='src'>
{{#each guilds}}
<div class="col-sm-1">
<a href="/dash/{{this.id}}">
<div class="gicon">
#*Changed the order of the images*#
{{#if this.icon}}
<img src="https://cdn.discordapp.com/icons/{{this.id}}/{{this.icon}}" alt="{{this.name}}" class="rounded-circle mt-4" width="75" height="75" id="{{this.id}}" data-toggle="tooltip" data-placement="bottom" title="{{this.name}}">
{{else}}
<img src="{{imgURL}}" alt="{{this.name}}" class="rounded-circle mt-4" width="75" height="75" id="{{this.id}}" data-toggle="tooltip" data-placement="bottom" title="{{this.name}}">
{{/if}}
</div>
</a>
</div>
{{/each}}
</script>
</body>
</html>

Implementing firebase to Polymer Starter Kit

I have my Polymer Starter Kit up and running and I want to implement Firebase, In the index file I imported polymerfire/firebase-app.html and in my-list.html I imported polymerfire/polymerfire.html and try to query the database and repeat a template and not working
index.html:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="generator" content="Polymer Starter Kit">
<title>Vidala</title>
<meta name="theme-color" content="#2E3AA1">
<link rel="manifest" href="manifest.json">
<meta name="msapplication-TileColor" content="#3372DF">
<meta name="mobile-web-app-capable" content="yes">
<meta name="application-name" content="PSK">
<link rel="icon" sizes="192x192" href="images/touch/chrome-touch-icon-192x192.png">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-title" content="Polymer Starter Kit">
<link rel="apple-touch-icon" href="images/touch/apple-touch-icon.png">
<meta name="msapplication-TileImage" content="images/touch/ms-touch-icon-144x144-precomposed.png">
<!-- build:css styles/main.css -->
<link rel="stylesheet" href="styles/main.css">
<!-- endbuild-->
<!-- build:js bower_components/webcomponentsjs/webcomponents-lite.min.js -->
<script src="bower_components/webcomponentsjs/webcomponents-lite.js"></script>
<link rel="import" href="elements/elements.html">
<link rel="import" href="../bower_components/polymerfire/firebase-app.html">
<!-- For shared styles, shared-styles.html import in elements.html -->
<style is="custom-style" include="shared-styles"></style>
</head>
<body unresolved>
<firebase-app
name="vida_fire"
api-key="AIzaSyABq6WXbt1LUoAsg26QIbJfgkV0R_T3nUg"
auth-domain="vidala-63738.firebaseapp.com"
database-url="https://vidala-63738.firebaseio.com">
</firebase-app>
<template is="dom-bind" id="app">
<paper-drawer-panel id="paperDrawerPanel">
<paper-scroll-header-panel drawer fixed>
<paper-toolbar id="drawerToolbar">
<span class="menu-name">Menu</span>
</paper-toolbar>
<paper-menu class="app-menu" attr-for-selected="data-route" selected="[[route]]">
<a data-route="home" href="{{baseUrl}}">
<iron-icon icon="home"></iron-icon>
<span>Home</span>
</a>
<a data-route="users" href="{{baseUrl}}users">
<iron-icon icon="info"></iron-icon>
<span>Users</span>
</a>
<a data-route="contact" href="{{baseUrl}}contact">
<iron-icon icon="mail"></iron-icon>
<span>Contact</span>
</a>
</paper-menu>
</paper-scroll-header-panel>
<!-- Main Area -->
<paper-scroll-header-panel main id="headerPanelMain" condenses keep-condensed-header>
<!-- Main Toolbar -->
<paper-toolbar id="mainToolbar" class="tall">
<paper-icon-button id="paperToggle" icon="menu" paper-drawer-toggle></paper-icon-button>
<span class="space"></span>
<!-- Toolbar icons -->
<paper-icon-button icon="refresh"></paper-icon-button>
<paper-icon-button icon="search"></paper-icon-button>
<!-- Application name -->
<div class="middle middle-container">
<div class="app-name">Vidala</div>
</div>
<!-- Application sub title -->
<div class="bottom bottom-container">
<div class="bottom-title">The future of the web today</div>
</div>
</paper-toolbar>
<!-- Main Content -->
<div class="content">
<iron-pages attr-for-selected="data-route" selected="{{route}}">
<section data-route="home" tabindex="-1">
<paper-material elevation="2">
<my-greeting></my-greeting>
<p class="subhead">Here the list from Firebase:</p>
<my-list></my-list>
</paper-material>
<paper-material elevation="2">
<p>This is another card.</p>
</paper-material>
</section>
<section data-route="users" tabindex="-1">
<paper-material elevation="2">
<h1 class="page-title" tabindex="-1">Users</h1>
<p>This is the users section</p>
<a href$="{{baseUrl}}users/Addy">Addy</a><br>
<a href$="{{baseUrl}}users/Rob">Rob</a><br>
<a href$="{{baseUrl}}users/Chuck">Chuck</a><br>
<a href$="{{baseUrl}}users/Sam">Sam</a>
</paper-material>
</section>
<section data-route="user-info" tabindex="-1">
<paper-material elevation="-1">
<h1 class="page-title" tabindex="-1">User: {{params.name}}</h1>
<div>This is {{params.name}}'s section</div>
</paper-material>
</section>
<section data-route="contact" tabindex="-1">
<paper-material elevation="2">
<h1 class="page-title" tabindex="-1">Contact</h1>
<p>This is the contact section</p>
</paper-material>
</section>
</iron-pages>
</div>
</paper-scroll-header-panel>
</paper-drawer-panel>
<paper-toast id="toast">
<span class="toast-hide-button" role="button" tabindex="0" onclick="app.$.toast.hide()">Ok</span>
</paper-toast>
</template>
<script src="scripts/app.js"></script>
</body>
</html>
my-list.html:
<link rel="import" href="../../bower_components/polymer/polymer.html">
<link rel="import" href="../../bower_components/paper-styles/typography.html">
<link rel="import" href="../bower_components/polymerfire/polymerfire.html">
<dom-module id="my-list">
<template>
<style>
:host {
display: block;
}
span {
#apply(--paper-font-body1);
}
</style>
<firebase-query
id="query"
app-name="vida_fire"
path="/notes"
data="{{data}}">
</firebase-query>
<ul>
<template is="dom-repeat" items="{{data}}" as="note">
<li>xx</li>
</template>
</ul>
</template>
<script>
(function() {
'use strict';
Polymer({
is: 'my-list',
properties: {
data: {
type: Object
}
},
ready: function() {
}
});
})();
</script>
</dom-module>
and this is my firebase database:
https://vidala-63738.firebaseio.com/
vidala-63738
notes
diego:"dp"
mares:"dp"
The code above is correct. The issue was firebase permissions.
{
"rules": {
".read": "auth == null",
".write": "auth != null"
}
}
Another good thing to do when implementing firebase is adding an error handler
<link rel="import" href="../../bower_components/polymer/polymer.html">
<link rel="import" href="../../bower_components/paper-styles/typography.html">
<link rel="import" href="../../bower_components/polymerfire/polymerfire.html">
<dom-module id="my-list">
<template>
<style>
:host {
display: block;
}
span {
#apply(--paper-font-body1);
}
</style>
<firebase-query
id="query"
app-name="vida_fire"
path="/notes"
data="{{data}}"
on-error="handleError">
</firebase-query>
<ul>
<template is="dom-repeat" items="{{data}}" as="note">
<li>xx</li>
</template>
</ul>
</template>
<script>
(function() {
'use strict';
Polymer({
handleError: function(e, err) {
alert(err);
},
is: 'my-list',
ready: function() {
}
});
})();
</script>
</dom-module>

angular js routing trouble

I am unable to get my code working. I am a newbiew on JS and trying to implement some example I found online on routing on angularJs. I have spent many hours trying to fix it, but could not.
Issue : Default View(View2) is opened by $routeProvider configuration. However, when I redirect this to view2.htm to view1.htm but blank page opens up.
Please help !
HTML CODE
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link href="JS/bootstrap/css/bootstrap-theme.css" rel="Stylesheet" />
<link href="/JS/bootstrap/css/bootstrap-theme.min.css" rel="Stylesheet" />
<link href="JS/bootstrap/css/bootstrap-theme.css.map" rel="Stylesheet" />
<link href="JS/bootstrap/css/bootstrap.css" />
<link href="JS/bootstrap/css/bootstrap.css.map" />
<link href="JS/bootstrap/css/bootstrap.min.css" />
<link href="JS/bootstrap/fonts/glyphicons-halflings-regular.eot" />
<link href="JS/bootstrap/fonts/glyphicons-halflings-regular.svg" />
<link href="JS/bootstrap/fonts/glyphicons-halflings-regular.ttf" />
<link href="JS/bootstrap/fonts/glyphicons-halflings-regular.woff" />
</head>
<script src="JS/jquery-2.1.1.js" language="javascript" type="text/javascript"></script>
<script src="JS/angular.js" language="javascript" type="text/javascript"></script>
<script src="/JS/angular-route.js" language="javascript" type="text/javascript"></script>
<script src="/JS/bootstrap/js/bootstrap.js" language="javascript" type="text/javascript">
</script>
<script src="/JS/bootstrap/js/bootstrap.min.js" language="javascript" type="text/javascript">
</script>
<body>
<title>::DEMO APP:: </title>
<div data-ng-app="demoApp1">
<script src="DemoJS.js" language="text/javascript" type="text/javascript"></script>
<div class="container">
<h3>
All the examples AngularJS Here:</h3>
</div>
<div class="container-fluid" data-ng-view="">
</div>
</div>
</body>
</html>
View1.htm Markup
<div id="View1" >
<h2>
Example 4 & 5
</h2>
<div class="container">
Name <input type="text" data-ng-model="inputData.name" placeholder="Name" />
<br />
City <input type="text" data-ng-model="inputData.city" placeholder="City" />
<br />
<button class="btn btn-primary" data-ng-click="addCustomer()">
Add Customer</button>
<br />
Filter <input type="text" data-ng-model="nameText" placeholder="Filters" />
<br />
<ul>
<li data-ng-repeat="customer in customers |filter:nameText">{{customer.name|uppercase}}
- {{customer.city}} </li>
</ul>
<a ng-href="#/View2.htm">View2</a>
</div>
</div>
View2.htm Markup
<div id="View2">
<h2>
Example 1,2 and 3</h2>
<div class="container">
<h3>
Data Binding Fundamentals</h3>
<h4>
Using a Data Binding Template</h4>
Name:
<input type="text" data-ng-model="name" placeholder="Type something" />
{{ name }}
</div>
<h1>
Example 2</h1>
<div data-ng-init="names=['Sunil','Deepak','Rajat','Somu']">
<ul>
<li data-ng-repeat="name in names">{{name}}</li>
</ul>
</div>
<h1>
Example 3</h1>
<div>
<h3>
Adding a Simple Controller</h3>
<ul>
<li data-ng-repeat="name in names">{{name}} </li>
</ul>
</div>
<a ng-href="#/View1.htm">View1</a>
</div>
DemoJS.js file code
var demoApp1 = angular.module('demoApp1', ['ngRoute'])
demoApp1.config(function ($routeProvider) {
$routeProvider
.when('/',
{
controller: 'SimpleController1',
templateUrl: '/View2.htm'
})
.when('View1',
{
controller: 'SimpleController',
templateUrl: '/View1.htm'
});
});
demoApp1.controller('SimpleController1', function ($scope) {
$scope.names = ['Dave', 'Napur', 'Heedy', 'Shriva'];
});
demoApp1.controller('SimpleController', function ($scope) {
$scope.customers = [
{ name: 'Sunil', city: 'Delhi' },
{ name: 'Ritu', city: 'Shbad' }
];
$scope.addCustomer = function () {
$scope.customers.push({ name: $scope.inputData.name, city: $scope.inputData.city });
}
});
I have found my mistake. The href link I used was not correct. As href is managed by angular itself, we should not add ".html" and the string we mention here should match to $routeProvide config string.. Below is the Modification I Made:
Incorrect on View1.html
<a ng-href="#/View2.htm">View2</a>
Corrected on View1.html:
View2
Samething I did on View2.html.

responsive layout with Bootstrap,.visible-phone not working

Trying to hide two banners when users are using phone, but using the classs such as .visible-phone or visible-desktop not working.
I then searched and thought maybe by adding the .less and less.js would solve the issue but failed either.
Code in HTML:
<link type="text/css" rel="stylesheet" href="/css/bootstrap.min.css" />
<link type="text/css" rel="stylesheet" href="/css/site.css" />
<link type='text/css' href='/js/jquery.simplemodal.css' rel='stylesheet' media='screen' />
<link href="/css/bootstrap-responsive.css" rel="stylesheet">
<link rel="stylesheet/less" type="text/css" href="css/less/responsive.less">
<script type="text/javascript" src="/js/jquery.js" ></script>
<script type="text/javascript" src="/js/bootstrap.min.js" ></script>
<script type="text/javascript" src="/js/site.js" ></script>
<script type='text/javascript' src='/js/jquery.simplemodal.js'></script>
<script type='text/javascript' src='/js/less.min.js'></script>
... I need to hide the banners when view on phones:
<div class="hidden-phone">
<div id="banner0" class="hidden-phone">
<div class="container-fluid">
<div id="index_slider">
<div class="banner-product">
<div class="mask">
<div class="banner-text">
<h1>...</h1>
<br>
<h5>...</h5>
<div class="banner-button">
<strong>...
</strong>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div id="banner1" class="hidden-phone">
<div class="container-fluid">
<div id="index_slider">
<div class="banner-product">
<div class="uploadmask">
<div class="banner-text">
<h1>...<br>
</h1>
<br>
<h5>...</h5>
<div class="banner-button">
<strong>...
</strong>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
... I need to show the video only when it is on desktop:
<div class="visible-desktop">
<p align=center>View Demo</p>
<br>
</div>
</div>
There are scripts binding on the banners, would this be the issue?
<script type="text/javascript">
function bindMouse(){
var _o1=document.getElementById("online");
var _o2=document.getElementById("banner1");
var _o3=document.getElementById("desktop");
var _o4=document.getElementById("banner0");
_o1.onmousemove=function(){
_o2.style.display="block";
_o4.style.display="none";
};
_o3.onmousemove=function(){
_o4.style.display="block";
_o2.style.display="none";
}
}
bindMouse();
$(document).ready(function(){
loadImage("/images/Backbanner.jpg",function(img){$("#banner0").css("background","#b9c0d0 url(" + img.src + ") top center no-repeat");});
loadImage("/images/banner-another.jpg",function(img){$("#banner1").css("background","#000000 url(" + img.src + ") top center no-repeat");});
})
function loadImage(url, callback) {
var img = new Image();
img.src = url;
$(img).load(function(){
if (this.complete||this.readyState=="complete") {
callback(img);
return;
}
})
}
</script>
Did you try just puting the display property to none when he is on phone?
In css you could do
/* Phone */
#media only screen and (max-width: 760px) {
.hidden-phone{
display: none;
}
}
Just adapt to your classes and it should be enough for what you are asking i think

WHY VIDEO IS NOT SHOWING ON PHOTO CLICK?

I have written the code...I want to open a youtube video in popup using iframe by clicking on the photo.below is the code i have written.
I have written the code...I want to open a youtube video in popup using iframe by clicking on the photo.below is the code i have written.
<iDOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
<script></script>
</head>
<body>
<div data-role="page" id="page1">
<div data-role="div" id="div1">
<img src="image1.jpg" onclick="play()" width="200px" height="200px" id="Zu5XUbig5G0">
</div>
<div data-role="footer" data-position="fixed">
<h4>Featured</h4>
</div>
</div>
<div data-role="popup" id="popup2" data-overlay-theme="a" data-theme="a" data-corners="false" data-tolerance="15,15">
<script>
function play()
{
var vid=document.getElementById("div1").getElementsByTagName('img')[0].id;
//alert(vid);
{
alert(vid);
document.getElementById("popup2").innerHTML="<iframe src='http://www.youtube.com/embed/tyOy3kRzkcM' width='480' height='320' seamless='' id='plyerIframe1'></iframe>";
//alert(vid);
}
}
</script>
</div>
</body>
</html>

Resources