Vanilla Javascript Material Components Web have missing Css attributes - material-design

I am testing Material Components Web from their recommended CDN & some minimal simple custom Vanilla Javascript to get it work properly.
For example, I can follow the single line list example showed here like this:
<!doctype html>
<html>
<head>
<link rel="stylesheet" href="https://unpkg.com/material-components-web#latest/dist/material-components-web.min.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
</head>
<body>
<ul class="mdc-list">
<li class="mdc-list-item" tabindex="0">
<span class="mdc-list-item__ripple"></span>
<span class="mdc-list-item__text">Single-line item</span>
</li>
<li class="mdc-list-item">
<span class="mdc-list-item__ripple"></span>
<span class="mdc-list-item__text">Single-line item</span>
</li>
<li class="mdc-list-item">
<span class="mdc-list-item__ripple"></span>
<span class="mdc-list-item__text">Single-line item</span>
</li>
</ul>
<script src="https://unpkg.com/material-components-web#latest/dist/material-components-web.min.js"></script>
<script>
mdc.list.MDCList.attachTo(document.querySelector('.mdc-list'));
</script>
</body>
</html>
Everything works fine except for the Css styling. No height: 48px is set to any of the list items, so all of them appear horribly collapsed, with no paddings at all.
Using the the Chrome Developer Inspector in the online example on their website, I see that height should be 48px height for every single list item.
Why are there missing styles in the official CDN Css?
NOTE: Things I am NOT asking for
I am not using any Js framework: Vue, Angular, React, Web dev server... just plain vanilla Js.
I am not asking how to add custom Css to add that specific missing value (I know how to do it, I just want to avoid doing it, since it should come already with the library). I just showed a single simple example of some missing attribute. I wonder if I am missing some other import or something.
I am already using the deprecated version of lists in production, that work fine, but I am trying here to update to the new recommended way of defining lists.

First of all, I'd recommend using docs on github repo - https://github.com/material-components/material-components-web/tree/master/packages/mdc-list:
List is currently being updated to better match the Material spec. As a result, there are two versions of List available: the deprecated old version and the new, future-proof version.
... there are differences in class names and DOM structure: the old version uses class names with a mdc-deprecated-list prefix (e.g., mdc-deprecated-list-item) whereas the new version uses the typical mdc-list prefix (e.g., mdc-list-item).
The example you referenced is related to deprecated version. You either need to add deprecated to class names, or update it according to the new docs.
Here is updated code which uses the new List version:
<!doctype html>
<html>
<head>
<link rel="stylesheet" href="https://unpkg.com/material-components-web#latest/dist/material-components-web.min.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
</head>
<body>
<ul class="mdc-list">
<li class="mdc-list-item mdc-list-item--non-interactive mdc-list-item--with-one-line" tabindex="0">
<span class="mdc-list-item__ripple"></span>
<span class="mdc-list-item__content">Single-line item</span>
</li>
<li class="mdc-list-item mdc-list-item--non-interactive mdc-list-item--with-one-line">
<span class="mdc-list-item__ripple"></span>
<span class="mdc-list-item__content">Single-line item</span>
</li>
<li class="mdc-list-item mdc-list-item--non-interactive mdc-list-item--with-one-line">
<span class="mdc-list-item__ripple"></span>
<span class="mdc-list-item__content">Single-line item</span>
</li>
</ul>
<script src="https://unpkg.com/material-components-web#latest/dist/material-components-web.min.js"></script>
<script>
mdc.list.MDCList.attachTo(document.querySelector('.mdc-deprecated-list'));
</script>
</body>
</html>

Related

Search for website pages in Bootstrap

I am a beginner, trying to teach myself code. I know HTML and have recently learnt the basics of Javascript syntax and bootstrap - I realise the best way to learn is to build something. So I am trying to build a website where users can search for famous people to see what books they recommend. For example, if I want to know what books Elon Musk would recommend, I should be able to type in his name and it would take me to a page where there is a list of all books recommended by him.
I have the index page ready looking something like google, and I am trying to understand how I can have the search bar functioning so people can search through all the pages I would build. I realise I need the auto complete feature to work so people can type in the first few letters of the person's name and click on the suggestion to go to the page.
Here's my code so far:
#content {height: 100%;}
html, body {height: 100%;}
.center-block {
display: block;
margin-left: auto;
margin-right: auto;
margin-top: 200px;
margin-bottom: 20px;
}
<!DOCTYPE html>
<html>
<head>
<!-- Bootstrap JS from CDN -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<!-- Bootstrap CSS from CDN -->
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<!-- Custom CSS -->
<link href="css/styles.css" rel="stylesheet">
<title>Page Title</title>
</head>
<body>
<div class="container">
<div class="row">
<div class="span4"></div>
<div class="span4"><img class="center-block" src="images/logo.png" width="270" height="95" alt="Google" id="logo"></div>
<div class="span4"></div>
</div>
<div class="row">
<div class="col-xs-8 col-xs-offset-2">
<div class="input-group">
<input type="text" class="form-control" name="x" placeholder="Search term...">
<span class="input-group-btn">
<button class="btn btn-default" type="button"><span class="glyphicon glyphicon-search"></span></button>
</span>
</div>
</div>
</div>
</div>
</div>
<div id="footer">
<div class="navbar navbar-default navbar-fixed-bottom" role="navigation">
<div class="container">
<ul class="nav navbar-nav navbar-left">
<li>Submit</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>About</li>
<li>Privacy</li>
<li>Donate</li>
</ul>
</div>
</div>
</div>
</body>
</html>
as you said, best way to learn is building something on your own from scratch. To create the functionality you described you need:
server for responding to the requests made by browser. I suggest starting with Node js especially with express (https://expressjs.com/). It's really simple to install and get started.
database (or just static json file) with node you can use for example Mongo db with Mongoose (http://mongoosejs.com/)
front-end framework and libraries you are using bootstrap which is fine! Add React js (https://facebook.github.io/react/) to that and you are ready to go!
So my suggestion is to use those libraries/frameworks and learn just bit by bit. Start from server and try creating some basic pages (or just page). You can fetch the autocomplete data then with AJAX techinque. React has lot of well written components and for example for ajax autocomplete you can use this: https://jedwatson.github.io/react-select/
Happy learning!

Search With AMP HTML Possible?

I would just love to try creating an AMP HTML website. However, what I cannot miss is our search function.
From what I understand so far, a search (input field, JavaScript handler) would not be possible with AMP HTML.
Is there any way to provide a neat search functionality within AMP HTML? Maybe using the amp-list component?
Forms are supported in AMP via the amp-form component. Using amp-form, you can embed a search form into your AMPs and render the search results into a new AMP on your server.
This is a search form in AMP:
<html>
<head>
<script async custom-element="amp-form" src="https://cdn.ampproject.org/v0/amp-form-0.1.js"></script>
<!-- ... AMP boilerplate ... -->
</head>
<body>
<form method="get" action="https://example.com/search" target="_top">
<input name="search" type="search">
<input type="submit" value="">
</form>
</body>
</html>
https://example.com/search can then render to an AMP page showing the search results:
<html>
<head>
<!-- ... AMP boilerplate ... -->
</head>
<body>
<h1>Results</h1>
<ul>
<li>Result 1</li>
<li>Result 2</li>
</ul>
</body>
</html>
You can find a working sample for a search implemented with AMP here.
Form support will come eventually. Please file a on Github with your use case: https://github.com/ampproject/amphtml/issues/new
There is a placeholder issue on Github to capture intent and use cases for Forms, see: https://github.com/ampproject/amphtml/issues/1286

lungo framework does not work with example code

I am testing lungo framework, and by reading their examples (http://lungo.tapquo.com/howto/prototype), it does not work.
I am using their skeleton code:
<body class="app">
<section id="main" data-transition="">
<article id="main-article" class="active">
test.
</article>
</section>
<script src="components/quojs/quo.js"></script>
<script src="components/lungo/lungo.js"></script>
<script type='text/javascript'>
Lungo.init({
name: 'example'
});
</script>
</body>
I have no errors in my console. What can be causing the issue?
Thanks in advance.
If that's all of your HTML, then you're missing a whole bunch of CSS files, etc. Could you share a JS fiddle or longer code example? The way you're not getting any JS errors implies to me you may well be missing some CSS. Also, what version of Lungo are you using? How did you obtain it?
Lots of questions :) However, I created a basic Lungo JSfiddle a while ago - http://jsfiddle.net/otupman/vz59n/ - try that and see if it works. In the "External Resources" section you'll find the CSS & JS I'm including to make it work.
The simple code I'm using (as S/O won't let me post a JSFiddle link without code) simply looks like this:
<section id="main" >
<header data-title="JsFiddle Lungo">
<nav class="left">
<a data-icon="home"></a>
</nav>
</header>
<article class="active" id="first_article">
<strong>Simple Example</strong>
Second article
<br/>
Second section
</article>
<article id="second_article">
<strong>Second article</strong>
First article
<br/>
Second section
</article>
</section>
All of the CSS/JS files are coming from Lungo's example, for example, one CSS is http://lungo.tapquo.com/example/components/lungo/lungo.css

Unable to get position() in JQuery $.each loop

I am trying to make an editable box (kind of a richTextBox) using html5 (contenteditable="true") and jquery. I need to find out position of each element inside the editable div so that I can insert a page break like microsoft word does.
Here is the page
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>jQuery Context Menu Plugin Demo</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<script src="http://code.jquery.com/jquery-1.7.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready( function() {
$("#divEdit").keyup(function(){
$.each($("#divEdit").find("*"), function(i,item){
alert(item.position());
});
});
});
</script>
</head>
<body>
<h1>jQuery Context Menu Plugin and KendoUI Demo</h1>
<div style="width:740px;height:440px" contenteditable="true" id = "divEdit">
<p>
<img src="http://www.kendoui.com/Image/kendo-logo.png" alt="Editor for ASP.NET MVC logo" style="display:block;margin-left:auto;margin-right:auto;" />
</p>
<p>
Kendo UI Editor allows your users to edit HTML in a familiar, user-friendly way.<br />
In this version, the Editor provides the core HTML editing engine, which includes basic text formatting, hyperlinks, lists,
and image handling. The widget <strong>outputs identical HTML</strong> across all major browsers, follows
accessibility standards and provides API for content manipulation.
</p>
<p id="para">Features include:</p>
<ul>
<li>Text formatting & alignment</li>
<li>Bulleted and numbered lists</li>
<li>Hyperlink and image dialogs</li>
<li>Cross-browser support</li>
<li>Identical HTML output across browsers</li>
<li>Gracefully degrades to a <code>textarea</code> when JavaScript is turned off</li>
</ul>
<p>
Read more details or send us your
feedback!
</p>
</div>
</body>
The problem is that alert(item.position()) is not fetching anything. The error that comes in firefox developer toolbar is 'item.position is not a function'.
My guess is that it has to do something with the type of each element in $("#divEdit").find("*") as all the elements are different.
Any help would be appreciated.
Thanks
You need to get the jQuery object out of item, as position() is a jQuery method, hence the complain about position() is not a function
$(item).position() // instead of item.position()
Or even more concise:
$.each($("#divEdit").find("*"), function(i,item){
alert(item.position());
}
change to
$('#divEdit').find('*').each(function() {
alert($(this).position());
})
Change this line
alert(item.position());
to
alert($(item).position());

How to properly use partial views in express with ejs?

I have a web app were the entire layout remains constant except for one <div>. Currently, I'm just using routes to handle links and it seems like quite a waste to reload the rest of the layout.ejs file where the only thing I wish to change is my <div>.
What would I have to change in my layout.ejs file? Here is my current file:
<!DOCTYPE html>
<html lan="en">
<head>
<title><%= title %></title>
<link rel="stylesheet" href="/stylesheets/reset.css">
<link rel='stylesheet' href='/stylesheets/style.css' />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<script src="/nowjs/now.js"></script>
<script src="/javascripts/chat.js"></script>
</head>
<body>
<div id="wrapper">
<div id="header">
</div>
<div id="chat">
<input type="text" id="text-input">
<input type="button" value="Send" id="send-button">
</div>
<div id="content">
<%- body %>
</div>
<div id="rooms">
</div>
<div id="footer">
<div id="footer_links">
Home | About | Contact
</div>
</div>
</div>
</body>
</html>
I was thinking about using AJAX to use this, but I've heard some good things about using partial views. I'm just not sure at all about how to set this up. Also, I've heard that it's possible to use WebSockets with partial views instead of AJAX. Is this a good idea, or even possible?
Sorry this may be straightforward. I'm having a difficult time with the documentation.
Thanks!
I just worked it out.
You can call `partial(filename)` in the view to load the partial. say we use EJS, and there is three files in `views/`:
1. layout.ejs
2. index.ejs
3. header.ejs
and the content of index.ejs is :
then, start the server, browser it, you will see `header.ejs` is loaded to `index.ejs`.
!!! UPDATE
In the express version >=3.0, there is no partial() any more. But we can use <% include xxx.file %>, or just use another module: "express-partials". Please search it on Github.

Resources