Angular styleUrls and styles in a component

Angular templates can add CSS styling by referencing external CSS files using the styleUrls directive or by adding inline CSS by way of the styles directive. Both directives can be present in the same component but the inline and external styles will not render. No errors will be thrown. Testing shows that only the style directive defined last will take effect.

In the code snippet below the CSS within the styles directive will take effect. The CSS in the external style.css file will be ignored.

@Component({
moduleId: module.id,
styleUrls: ['../assets/css/style.css'],
styles: [
'.topInputLabel { padding:5px 0 0 5px; }',
'.inputLabel { padding:0 0 0 5px; }',
'.topInputField { padding:5px 5px 0 5px; }',
'.inputField { padding:0 5px 0 5px; }'
],
templateUrl: 'my.component.html',
})

Move the styleUrls directive after the styles directive as in the code snippet below and the opposite is true. The CSS in the external style.css file will take effect and the inline CSS of the styles directive is ignored.

@Component({
moduleId: module.id,
styles: [
'.topInputLabel { padding:5px 0 0 5px; }',
'.inputLabel { padding:0 0 0 5px; }',
'.topInputField { padding:5px 5px 0 5px; }',
'.inputField { padding:0 5px 0 5px; }'
],
styleUrls: ['../assets/css/style.css'],
templateUrl: 'my.component.html',
})




Posted in Angular | Tagged | Comments Off on Angular styleUrls and styles in a component

Setting up Google My Business

If you are a business owner you need to get acquainted with Google My Business. Once set up your business location on the map will appear in Google Search Engine Result Pages (SERPs), along with other information about your business that you provide.

Step 1

Go to Google My Business and log in with your Google account.

Step 2

Provide basic information about your business, such as physical address, phone number and web site address. See screen shot:

Google My Business basic info

Google My Business basic info

Step 3

Check the box stating that you are authorized to manage this business and agree to the terms and conditions:

Google My Business authorization

Google My Business authorization

Step 4

Select the option as to how you want your business verified. NOTE – some features are disabled until the business is verified.

Google My Business verification

Google My Business verification

Step 5

Click the Continue button to acknowledge verification is pending and the dashboard for the business is displayed:

Google My Business dahsboard

Google My Business dahsboard

Step 6

Update other business information, such as daily hours of operation.

Google My Business hours

Google My Business hours of operation

Step 7

Verify your business with the code provided via telephone call, text or postcard by clicking the “Verify location” link on the left side menu and entering the code in the space provided:

Verify location

Verify location

Verified

Verified confirmation

Step 8

Once verified you can update more business information and add photos.

Perform a Google search for your business and see your Google My Business information displayed on the right side of the search results pages!




Posted in Google | Tagged , | Comments Off on Setting up Google My Business

Angular Safe Navigation Operator

For those that are new to Angular there is an incredibly useful operator for use in templates. It is called the safe navigation operator and is noted with a question mark (?). Avoid the extra code of checking an object for null/undefined with the *ngIf directive in a template by using the safe navigation operator.

Using *ngIf

<div *ngIf="person">
{{person.name}}
</div>

Using safe navigation operator (?)

{{person?.name}}

If the person object in the example above is null/undefined then the rest of the expression is ignored and the name is not attempted to be resolved.

See the Template Syntax section of the Angular cheat sheet for other tips.




Posted in Angular | Tagged , | Comments Off on Angular Safe Navigation Operator

Classic AJAX

AJAX stands for Asynchronous JavaScript And XML and has become an integral part of JavaScript coding. Implementing AJAX can often be simplified by using a JavaScript framework, like jQuery. Sometimes a framework is not available and you must use classic JavaScript. No need to worry, it is easily done using the code snippets below.


First define the Ajax HTTP request object.



function getHTTPObject()
{
var xmlhttp;
/*@cc_on
@if (@_jscript_version >= 5)
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}
@else
xmlhttp = false;
@end @*/
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
try {
xmlhttp = new XMLHttpRequest();
} catch (e) {
xmlhttp = false;
}
}
return xmlhttp;
}


An Ajax HTTP request can be made different ways, with GET and POST the most commonly used.


First create the Ajax request object and define a function to handle the response.

var ajax = getHTTPObject(); // See code snippet above
ajax.onreadystatechange=function()
{
/*
* Ready state:
* 0 = The request is not initialized
* 1 = The request has been set up
* 2 = The request has been sent
* 3 = The request is in process
* 4 = The request is complete
*/
if (ajax.readyState == 4) {
// Show response in alert box
alert('AJAX response = ' + ajax.responseText);
}
} // function

GET request:

// Open a connection to the server
/*
* param1 - Request method - GET or POST
* param2 - Server URL to send request
* param3 - Asynchronous connection (true for Ajax requests)
*/
ajax.open('GET', 'yoururl?yourparm1='+value1, true);
// Send the request
ajax.send(null);

POST request:

// Create a variable for the POST parameters
var params = 'parm1=value1&parm2=value2';
// Opening the server connection is the same, apart from the method parameter
ajax.open('POST', url, true);
//Send the proper header information along with the request
// Set the content type to text/html for pages without forms
// Pages with forms should have a content type of "application/x-www-form-urlencoded"
ajax.setRequestHeader("Content-type", "text/html");
ajax.setRequestHeader("Content-length", params.length);
ajax.setRequestHeader("Connection", "close");
// Send POST request
ajax.send(params);


If you need to access to the DOM (document object model) then use the responseXML property of the HTTP request object.
NOTE: The content type must be application/xml or text/xml for the responseXML property to be populated.



if (ajax.readyState == 4) {
// Show XML response in alert box
alert('AJAX response = ' + ajax.responseXML);
// Show "location" element value in alert box
alert(ajax.responseXML.documentElement.
getElementsByTagName("location")[0].firstChild.data);
}





Posted in JavaScript | Tagged | Comments Off on Classic AJAX

How to verify your business Facebook Page

The reach of Facebook cannot be denied. With over 1.7 billion (with a “B”) monthly active users, it makes sense for your business to have a presence here. Assuming you have set up a Page for your business, a crucial step is to verify your business. Once verified, a check mark is shown on the Page and provides a level of authenticity to visitors. Facebook also claims it helps with search engine placement.

Below is a step-by-step guide to get your business Page verified.

Go to the business Page after logging in and click the Settings button at the upper right of the page.

Facebook Page verification

Facebook Page verification – step 1

Click the Page Verification option in the General settings.

Facebook Page verification

Facebook Page verification – step 2

Click the Verify this Page link.

Facebook Page verification

Facebook Page verification – step 3

A window will open with instructions on verification. Phone number verification is far simpler and is the method used here.

Facebook Page verification

Facebook Page verification – step 4

Ensure the business phone number is correct. An automated call will be initiated to the business phone number. Be prepared to write down a verification code. Click the Call Me Now button when ready.

Facebook Page verification

Facebook Page verification – step 5

Enter the verification code provided by the automated call in the space provided and click the Continue button.

Facebook Page verification

Facebook Page verification – step 6

That’s it! You now have a verified the Facebook Page for your business. When finsihed you will see a gray checkmark by the business name.

Facebook Page verified

Verified Facebook Page




Posted in Facebook | Tagged | Comments Off on How to verify your business Facebook Page

CSS Vertical Padding in a Span Element

If you have worked with CSS a fair amount then you are undoubtedly familiar with the span element. And if you have worked with the span element then you have likely scratched your head and possibly pulled out some hair trying to apply vertical margins or padding to it.

The fact is that span elements are inline elements. Content that is inserted after an inline element will continue on the same line whereas content following block elements will start on a new line. For this reason top and bottom padding cannot be added to a span element. Left and right padding can be added to a span element but top and bottom padding cannot be added without additional coding.

A CSS Trick

What do you do if you have a span element that needs top or bottom padding? The answer is to change its behavior to a block element. Add the display:block style to the span element that needs vertical padding and the top/bottom padding will work since the span element will now be treated as a block element.

Code Example

<style type="text/css">
.header { background-color:yellow; height:30px; }
.header span { display:block; font-weight:bold; padding-left:20px; padding-top:6px; }
</style>
...
<div class="header"><span style="">Shipment Information</span></div>

The header CSS class sets the element height at 30 pixels with a yellow background. The 2nd line in the style section tells the page to render any span element inside an element with the header class to render it as a block element. This allows the padding styles to take effect. Without the display:block style the padding would be ignored. See the code in action below.

Shipment Information




Posted in Web Development | Tagged | Comments Off on CSS Vertical Padding in a Span Element

Images in Sitemaps

This is not new information but bears repeating.

Most SEO professionals know about creating XML sitemaps for web sites so that search engines can more easily find and index content. One limitation of sitemaps is the ability only to include URLs in the map – until now. Google has created an extension to XML sitemaps that is used to provide additional information about important images that exist on each page in the sitemap. This may be useful for logos or other branded images. See the sitemap code example below.

<?xml version=”1.0″ encoding=”UTF-8″?>
<urlset xmlns=”http://www.sitemaps.org/schemas/sitemap/0.9″
xmlns:image=”http://www.google.com/schemas/sitemap-image/1.1″>
<url>
<loc>http://www.webtechnologyinc.com/contact.htm</loc>
<image:image>
<image:loc>http://www.webtechnologyinc.com/images/logo.jpg</image:loc>
</image:image>
</url>
</urlset>

More complete information is available on the Google blog.




Posted in Search Engine Optimization | Tagged , , | Comments Off on Images in Sitemaps

Page Title Tag

The HTML page title tag describes the content of the page itself and is displayed at the top of the browser for all web site visitors. These are good reasons to always pay attention to the page title but the title also plays an important role in search engine optimization (SEO) strategies.

<title>This is the title of the page</title>
<meta name="description" content="This is an example of a meta description. This will normally show in search engine result pages (SERPs)." />
<meta name="keywords" content="meta, description, tag" />

Learn more about meta tags and the meta description tag in a prior post on this blog.

Creating a descriptive title tag is one of the most important organic SEO factors. The title tag is normally the fist thing that potential web site visitors see so it is important to convey your site’s content as well as entice the person to click on that link to your site.

Keywords

The presence and prominence of keywords in the title tag is a major factor for SEO. It is advantageous to have keywords appear early in the page title. This ensures the most important parts of the title are not cut off in the search engine result pages (SERPs) and also gives a more clear message about the site’s content.

Branding

Including a brand name in the title tag can be an effective SEO strategy if the brand is recognizable and gives the potential visitor a good idea of the web site’s content.

Length

Title tags displayed in SERPs are limited to 70 characters. There is no penalty for title tags longer than 70 characters but know that anything over 70 characters will be truncated when displayed in the SERPs.

Ideal Title Tag Format

As described in the factors above, the title tag ideally follows a specific pattern:

Primary Keyword – Secondary Keyword | Brand Name

NOTE – The dash and horizontal bar are interchangeable.




Posted in Search Engine Optimization | Tagged , | Comments Off on Page Title Tag

Accept Terms and Conditions using jQuery Dialog

There may be a page on your web site that you want to protect by forcing visitors to read a disclaimer or accept terms and conditions before viewing the page contents. This is entirely possible with the jQuery JavaScript library along with jQuery UI, the user interface library that goes along with the jQuery core library.

The Page

The page contains the usual head and body sections. The interactivity of the page to make the web site visitor accept the terms and conditions is made possible by using the jQuery and jQueryUI JavaScript libraries.

Head section


<head>
<meta charset="utf-8">
<title>jQuery UI Dialog - Modal confirmation</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
<link type="text/css" rel="stylesheet" href="http://code.jquery.com/ui /1.10.3/themes/smoothness/jquery-ui.css">
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.3.js"></script>
<script type="text/javascript" src="http://code.jquery.com/ui /1.8.2/jquery-ui.js"></script>
</head>

The jQuery and jQueryUI libraries are included in the head section, like any other external JavaScripr file reference. In this example the files are included from jquery.com. It is easy to download the jQuery and jQuery UI files and reference them locally.

Body Section


<body>

<div id="dialog-confirm" title="Terms and Conditions">
<p>Access to and use of this site is subject to the Terms and Conditions listed below.</p>
More legal-ese...
</div>

<div>
<p>
The content of the page goes here, just like any other page.
</p>
</div>

<script type="text/javascript">
$(document).ready(function() {
$( "#dialog-confirm" ).dialog({
buttons: {
"I agree": function() {
$( this ).dialog( "close" );
},
Cancel: function() {
window.location.replace ("http://www.webtechnologyinc.com");
}
},
closeOnEscape: false,
draggable: false,
height: ($(window).height()) * 0.8,
modal: true,
open: function(event, ui) {
// Set opacity of parent window
$( ".ui-widget-overlay" ).css( "opacity", 0.90 );
// Hide close button on modal dialog
$( ".ui-dialog-titlebar-close" ).css( "display", 'none' );
},
resizable: false,
width: ($(window).width()) * 0.7
});
});
</script>

</body>

The body contains a section containing the text of the terms and conditions. This is what shows in the jQuery dialog box that is presented to web site visitors before they can view the page contents. The terms and conditions are contained in the following code snippet.


<div id="dialog-confirm" title="Terms and Conditions">
<p>Access to and use of this site is subject to the Terms and Conditions listed below.</p>
More legal-ese...
</div>

The dialog-confirm id on the opening div element uniquely identifies the element and its contents for the jQuery dialog to show when the page is loaded.

The title attribute on the div element is used by the jQuery dialog as the heading.

Lastly, in the JavaScript code at the bottom of the body section, note the id is used to assign behaviors to the div element associated with that id.
$( "#dialog-confirm" ).dialog

The buttons options contains all the buttons that will show in the popup dialog box.

All the other options (closeOnEscape, draggalbe, etc.) on the jQueryUI dialog widget can be found in the jQeuryUI dialog API doucmentation.




Posted in JavaScript, Web Development | Tagged , , | Comments Off on Accept Terms and Conditions using jQuery Dialog

Anatomy of a Search Engine

Most search engines have three parts: a crawler, an index, and a search interface. Let’s
look at each part individually to get a better understanding of them. Each part has its
own role to play in the process, with all parts working together to make searches
possible.

1. The Crawler

Also known as a “spider” or “bot”, this part of the search engine wanders the Web,
following links and picking up information for its database. Crawlers do most of their
work at times of the day when search engines are less busy, typically visiting frequently
updated pages more often. This is something to keep in mind when you are working on your
pages.

Your site’s title and content are the most important thing to a crawler. One of the best ways
to raise your site’s search engine ranking for specific key words is to implement them
into your title and your content.

2. The Index

Once the crawler has collected all that text, it is then stored and indexed. This allows
people searching for keywords and phrases to get results relating to what they were
searching for – their search results, displayed on search engine result pages (SERP). To see this in action, go to a search engine and enter a search phrase. You’ll see some text on
the page saying something like “results 1-10 of 1,234,000”. This means that the search
engine’s index contains 1,234,000 pages it believes are related to the search phrase entered.

In order to understand rating systems more thoroughly, consider your own site. When you
place links on your site you generally do so to increase the understanding of web site visitors on the content of your site.

If every site in a particular field of interest links to one specific site, this site is
probably very important to that field and should, therefore, be listed highly in the
lists of search engine results. This is the basic ideology of how Google and other search engines display SERPs.

3. The Interface

Search engines provide a public interface for users who want to find information on the
Web. They type the word or phrase they’re searching for, and the interface will run an
algorithm to find the pages relevant to their search and display them.

These algorithms are an important part of the SEO (Search Engine Optimization) business. You’ll notice when the algorithms change, the rankings of your web site may change. No two search engines have the same algorithms. They all work differently, with their unique features, and they will all rank your web site in their own way.




Posted in Google, Search Engine Optimization | Tagged , | Comments Off on Anatomy of a Search Engine