Google Autocomplete for Addresses and Search Terms Polymer element - polymer

I was searching for google autocomplete search for address polymer element but i was not able to find that so i decided to write of my own.
But I get google.maps as object but google.maps.places is undefined in the console below is my sample code
<script src="http://maps.googleapis.com/maps/api/js?libraries=places"></script>
<polymer-element name="google-placesearch">
<link rel="import" href="../../bower_components/polymer/polymer.html">
<template>
<style>
</style>
<input id="autocomplete" placeholder="Enter your address"
type="text"></input>
</template>
<script>
Polymer('google-placesearch', {
ready: function() {
// this.autocomplete= new google.maps.places.Autocomplete(this.$.autocomplete)
console.log(this.$.autocomplete);
autocomplete=new google.maps.places.Autocomplete(this.$.autocomplete);
// console.log(autocomplete);
},
});
</script>
</polymer-element>

There's a google-map-search element here, although it doesn't appear to use the google.maps.places.Autocomplete API.
You'll also want to load the google maps library like this: https://github.com/GoogleWebComponents/google-map/blob/master/google-map-directions.html#L44. Note, there's a google-maps-api component for loading the library and getting the timing right.

I created my own google-location-search element using maps api
<link rel="import" href="../../bower_components/polymer/polymer.html">
<link rel="import" href="../../bower_components/google-apis/google-maps-api.html">
<polymer-element name="google-place-search" attributes="location" >
<template>
<style>
.form-control {
display: block;
width: 100%;
height: 34px;
padding: 6px 12px;
font-size: 14px;
line-height: 1.42857143;
color: #555555;
background-color: #ffffff;
background-image: none;
border: 1px solid #cccccc;
border-radius: 4px;
-webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
-webkit-transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s;
transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s;
}
</style>
<google-maps-api apiKey="{{apiKey}}" version="{{version}}" on-api-load="{{mapApiLoaded}}" libraries="{{libraries}}"></google-maps-api>
<input id="autocomplete" placeholder="Enter your address first time"
type="text" class="form-control"></input>
</template>
<script>
Polymer('google-place-search', {
autocomplete:null,
version: '3.exp',
apiKey: null,
libraries: "places",
mapApiLoaded: function() {
this.autocomplete= new google.maps.places.Autocomplete(this.$.autocomplete);
google.maps.event.addListener(this.autocomplete, 'place_changed', function() {
var place = this.autocomplete.getPlace();
this.location=place.formatted_address
}.bind(this));
}
});
</script>
</polymer-element>

Related

How would i set the button to toggle viewability of the javascript array?

I am attempting to make it to where the button in the paragraph is used to toggle the viewability of the javascript array on/off. I'm not quite sure how to do it though.
Here's my html:
<body>
<div class="flexbox-container">
<h1 class="underline-small">
Heading One
</h1>
</div>
<h3 class="paragraph">Remove the duplicates in 2 Javascript arrays (found in readme), add the results to an array and output the list of distinct names in an unordered list below this paragraph when <button type="button" onclick="unshow()" id="btnID" class="javabutton">this link</button> is clicked. If the operation has been completed already, notify the user that this has already been done.</h2>
<script>
function unshow() {
document.getElementById('image')
.style.display = "none";
}
</script>
</div>
<script type="text/javascript">
let array1 = ["Matt Johnson", "Matt Johnson", "Bart Paden", "Ryan Doss", "Jared Malcolm"]
array2 = ["Matt Johnson", "Bart Paden", "Ryan Doss", "Jared Malcolm", "Jordan Heigle", "Tyler Viles"]
let set = new Set([...array1, ...array2]);
let newArray = [...set];
for(i=0;i<newArray.length;i++) {
document.write(newArray[i] + "<br/>");
}
</script>
</div>
</body>
</html>
and here's my CSS for styling:
.paragraph {
font-weight: 400;
color: white;
align-self: center;
font-size: 17px;
margin: -30px 75px 0px 75px;
}
.javabutton {
border: none;
border-radius: 50px;
cursor: pointer;
transition: all 0.3s ease 0s;
font-family: 'Poppins', sans-serif;
font-weight: 700;
font-size: 16px;
color: #DEBF79;
text-decoration: none;
background-color: #222222;
}

Create HTML Link to Call Button Click Event on Different Page

Per the code below, I'm able to create a Link with parameters that will navigate to my desired target page:
<style>
.fancy-link{
color: #FFFFFF;
text-decoration: none;
transition: all 0.3s linear;
-webkit-transition: all 0.3s linear;
-moz-transition: all 0.3s linear;
border-radius: 4px;
border: 1px solid black;
background: #0080FF;
padding-top: 0px;
padding-left: 5px;
padding-right: 5px;
padding-bottom: 0px;
width: 100px;
height: 10px;
font-size: 15px;
font-weight: bold;}
.fancy-link:hover{
color: #F44336;
padding-left: 10px;}
</style>
<html>
<a class="fancy-link" name="View" id="View"
href="'||'https://XXXXXX-sb1.app.website.com/app/common/custom/custrecordentry.nl?
rectype=142&id='||{internalid}||'"target="_blank">Check-In</a>
</html>
While this is useful, my intended goal is for this link to actually call the following button click event/element that lives # at the desired url (see href above), without actually navigating to that page. Is this possible? If so, some code examples would be very helpful.
.<input type="button" style="" class="rndbuttoninpt bntBgT"value="Check-In" id="custpageworkflow157" name="custpageworkflow157"onclick="try{
if (!!window) {
var origScriptIdForLogging = window.NLScriptIdForLogging;
var origDeploymentIdForLogging = window.NLDeploymentIdForLogging;
window.NLScriptIdForLogging ='CUSTOMSCRIPT_STICK_USER_PREFERENCE';
window.NLDeploymentIdForLogging= 'CUSTOMDEPLOY_STICK_USER_PREFERENCE';
}
try{
NS.Workflow.buttonClick('custpageworkflow157');
}
catch(e){
document.location = addParamToURL(addParamToURL(addParamToURL(document.location.href,'workflowbutton','157'),'workflowbuttoninstanceid','84083'),'workflowbuttonobsoletehandling','T');
}
}
finally{
if (!!window) {
window.NLScriptIdForLogging = origScriptIdForLogging;
window.NLDeploymentIdForLogging = origDeploymentIdForLogging;
}
}
;
return false;
"onmousedown="this.setAttribute('_mousedown','T');
setButtonDown(true, false, this);
" onmouseup="this.setAttribute('_mousedown','F');
setButtonDown(false, false, this);
" onmouseout="if(this.getAttribute('_mousedown')=='T') setButtonDown(false,false, this);
" onmouseover="if(this.getAttribute('_mousedown')=='T') setButtonDown(true, false, this);
" _mousedown="F">
You should be able to get away with this with a simple event listener in the button you are creating:
document.getElementById('custpageworkflow157).click();
So basically something like this:
document.getElementById("View").addEventListener("click", function(){
document.getElementById('custpageworkflow157).click();
});

Customise scrollbar thumb to be at bottom by using css

Is it possible for the scrollbar thumb to be by default at the bottom of the page by just using css and webkit. I used jquery to do so but that is not giving me the desired result and i want to do it using css
Here is my css code
.container::-webkit-scrollbar {
width: 12px;
background-color: #000000;
}
.container::-webkit-scrollbar-track {
-webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3);
background-color: #F5F5F5;
}
.container::-webkit-scrollbar-thumb {
border-radius: 10px;
-webkit-box-shadow: inset 0 0 6px rgba(0,0,0,.3);
background-color: #555;
}
Here is the jquery code i used to achieve this
<script type="text/javascript">
var refreshIntervalId=null;
refreshIntervalId = setInterval(function(){
var element = document.getElementsByClassName('container')[0];
if (element.scrollHeight > element.clientHeight || element.scrollWidth > element.clientWidth) {
$('#mydiv').animate({
scrollTop: $(document).height()
},
'slow');
return false;
}
}, 100);
</script>
If you have jQuery, you can do this—
$('html,body').animate({scrollTop: document.body.scrollHeight},"slow");
That's it.

How to manage responsive design in angular?

While clicking on the add button the static text and a text box is adding vertically.
How can I add this horizontally ?
How can I make this design responsive ?
For Desktop/Laptop : 4 in a row., Tablet: 3 in row and Mobile : 1 in a row.
Attached the HTML, Java script and css files. Please suggest.
var app = angular.module('angularjs-starter', []);
app.controller('MainCtrl', function($scope) {
$scope.choices = [{id: 'choice1'}, {id: 'choice2'}];
$scope.addNewChoice = function() {
var newItemNo = $scope.choices.length + 1;
$scope.choices.push({'id': 'choice' + newItemNo});
};
$scope.removeChoice = function() {
var lastItem = $scope.choices.length - 1;
$scope.choices.splice(lastItem);
};
});
fieldset {
background: #FCFCFC;
padding: 16px;
border: 1px solid #D5D5D5;
}
.addfields {
margin: 10px 0;
}
#choicesDisplay {
padding: 10px;
background: rgb(227, 250, 227);
border: 1px solid rgb(171, 239, 171);
color: rgb(9, 56, 9);
}
.remove {
background: #C76868;
color: #FFF;
font-weight: bold;
font-size: 21px;
border: 0;
cursor: pointer;
display: inline-block;
padding: 4px 9px;
vertical-align: top;
line-height: 100%;
}
input[type="text"],
select {
padding: 5px;
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.min.js"></script>
<div ng-app="angularjs-starter" ng-controller="MainCtrl">
<fieldset data-ng-repeat="choice in choices">
<select>
<option>Mobile</option>
<option>Office</option>
<option>Home</option>
</select>
<input type="text" ng-model="choice.name" name="" placeholder="Enter mobile number">
<button class="remove" ng-show="$last" ng-click="removeChoice()">-</button>
</fieldset>
<button class="addfields" ng-click="addNewChoice()">Add fields</button>
<div id="choicesDisplay">
{{ choices }}
</div>
</div>
For making it responsive you should use Angular Material or Bootstrap
You can use Bootstrap grid (which can bug out in other way though since you won't have proper .rows when adding columns this way) or just use flexbox and code it manually as your requirements are really simple: https://css-tricks.com/dont-overthink-flexbox-grids/

Bottom bar position in tab UI - Polymer

I am using Scrollable paper-tabs - Polymer. I have placed a NEXT button above the tabs and I want to change the position of the selected bar(bar which is displayed on bottom of the selected tab ) on next button's click. I am new to Ploymer. Any help will be appreciated.
https://www.polymer-project.org/0.5/components/paper-tabs/demo.html
in order to change the position of the selected bar you can change the paper-tabs's index selection. It's better to use tabs.selectIndex(); function than selectNext(); in order to make the change cyclic : meaning once you've reached the end, it will select the first element and so on, if you provide the right index.
Here's the javascript function to do that :
function clickAction(e) {
var t = e.target;
if (t.localName === 'paper-icon-button') {
if (!t.hasAttribute('disabled')) {
var tabs = document.querySelector('paper-tabs');
var index = tabs.selectedIndex;
index = index+1 == tabs.children.length ? 0 : index + 1;
tabs.selectIndex(index);
}
}
}
If you need a working sample, here's the one I've been working one (it's from Polymer's official documentation with a bit more) :
<!doctype html>
<html>
<head>
<title>paper-tabs</title>
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1, user-scalable=yes">
<script src="webcomponentsjs/webcomponents.js"></script>
<link rel="import" href="core-icons/core-icons.html">
<link rel="import" href="font-roboto/roboto.html">
<link rel="import" href="paper-tabs/paper-tabs.html">
<link rel="import" href="core-toolbar/core-toolbar.html">
<link rel="import" href="core-media-query/core-media-query.html">
<link rel="import" href="paper-icon-button/paper-icon-button.html">
<style shim-shadowdom>
body {
font-family: RobotoDraft, 'Helvetica Neue', Helvetica, Arial;
margin: 0;
padding: 24px;
color: #333;
}
body.core-narrow {
padding: 8px;
}
paper-tabs, core-toolbar {
background-color: #00bcd4;
color: #fff;
box-shadow: 0px 3px 2px rgba(0, 0, 0, 0.2);
}
core-toolbar paper-tabs {
box-shadow: none;
}
paper-tabs[noink][nobar] paper-tab.core-selected {
color: #ffff8d;
}
paper-tabs.transparent-teal {
background-color: transparent;
color: #00bcd4;
box-shadow: none;
}
paper-tabs.transparent-teal::shadow #selectionBar {
background-color: #00bcd4;
}
paper-tabs.transparent-teal paper-tab::shadow #ink {
color: #00bcd4;
}
h3 {
font-size: 16px;
font-weight: 400;
}
</style>
</head>
<body>
<div>
<paper-icon-button icon="arrow-forward" title="arrow-forward" onclick="clickAction(event)"></paper-icon-button>
</div>
<paper-tabs selected="0">
<paper-tab>ITEM ONE</paper-tab>
<paper-tab>ITEM TWO</paper-tab>
<paper-tab>ITEM THREE</paper-tab>
</paper-tabs>
<script>
function clickAction(e) {
var t = e.target;
if (t.localName === 'paper-icon-button') {
if (!t.hasAttribute('disabled')) {
var tabs = document.querySelector('paper-tabs');
var index = tabs.selectedIndex;
index = index+1 == tabs.children.length ? 0 : index + 1;
tabs.selectIndex(index);
}
}
}
</script>
</body>
</html>