Atlantic Business Technologies, Inc.

Author: Atlantic BT

  • Getting the Current Index Position of an Element in jQuery

    jQuery has quickly become one of the defacto JavaScript libraries for web developers. Its popularity has increased for many reasons including its ease of use, its built-in methods that aid in basic tasks, and its multitude of plug-ins that can be found to enhance its capabilities.

    However, when I was writing a function the other day, I came across a minor stumbling block in jQuery. I was trying to create universal ā€œcontinueā€ buttons throughout some user-interface tabs and I realized I needed a specific method that isn’t part of the jQuery library; some way to determine the current index of the element I was on.

    Having been to jQuery Docs several times, I didn’t recall ever seeing what I needed, but I was hoping I’d be lucky. Unfortunately, after a visit to the documentation, I found that I was right. There was no such method. Of course, the eq() method does exist, but that’s the direct opposite of what I was looking for—to move to a specific index position of the matched elements. Moreover, in using the eq() method you’d need to know which index you’d like to select!

    The eq() selection concept is much like the built-in ā€œselectā€ parameter that you can pass through the UI Tabs method I was hoping to use. For instance:

    $tabs.tabs(ā€˜select’, 1);

    This will select the first tab in the set. So, if I had a continue button at the bottom of each tab panel how would I know how to select the very next tab? I could, of course, make a special case for every instance of a panel’s continue button, but that poses a problem with extensibility. What if we added more tabs? Plus, it’s just ugly code. The fault here is that you’d have to know what each tab is named and how they relate to one another—creating a problem if the tabs were ever re-organized.

    Instead I’d need something a little more universal. I’d need a single function that would encompass all of the continue buttons and switch to the next tab based on its current index. But, as I discovered in the documentation, you can’t locate the current index with a simple method like eq().

    With all of my struggles aside, the good news is that the round-about way of getting the current index position is really not all that difficult. After a few minutes of thought and some idea bouncing (off of the smarter programmers here in the office) we came to the conclusion that I could simply count how many elements there are before the tab I’m on using the prevAll() and length methods built-in to jQuery. Thus, if there were 2 previous elements, I must be at the third item. The selection looks something like:

    var $tabs = $(ā€˜#tabs-area ul.ui-tabs-nav’).tabs({ fx: { opacity: ā€˜toggle’ } }); $(ā€˜#tabs-area a.tab-link’).click(function () { currentIndex = $(this).parent().prevAll().length; alert(currentIndex); return false; });

    Here I’m selecting the anchor elements with classes of ā€œtab-linkā€ which is what I called each ā€œcontinueā€ button. When they’re clicked, I store the number of ā€œui-tabs-panelsā€ before the current tab. Please note, that the parent() method is being used to traverse backwards to these ā€œui-tabs-panels.ā€ You’re path may vary depending on your HTML markup.

    Using ā€œcurrentIndexā€ I can check if it is larger than the length of the tabs array (meaning I’m not on the last tab yet) to prevent any possible tab selection errors by trying to move past the last tab. Then I can use currentIndex to select the next tab. This would make our little function look like this now:

    var $tabs = $(ā€˜#tabs-area ul.ui-tabs-nav’).tabs({ fx: { opacity: ā€˜toggle’ } }); $(ā€˜#tabs-area a.tab-link’).click(function () { currentIndex = $(this).parent().prevAll().length; if (currentIndex < $tabs.tabs(ā€˜length’)) { $tabs.tabs(ā€˜select’, currentIndex); } return false; });

    I also must mention that in this function I’m selecting currentIndex in the statement $tabs.tabs(ā€˜select’, currentIndex);. This may be confusing since the way the array indices and the ā€œselectā€ parameter work are based on a zero beginning index. But, when length is calculated it starts with 1. So, there’s a bit of an ā€œoff-by-one-bug.ā€ I can, of course, trim the length by 1 and adjust the if statement to be <=, but that would be equally confusing. Either way, rest assured that the currentIndex in the ā€œselectā€ statement will select the very next tab.

    In closing, it is quite easy to determine the current index position of an element in jQuery without using any built-in methods. All you need to do is count:

    currentIndex = $(this).parent().prevAll().length;

    This assignment is very easy to build upon (or adjust the index by subtracting 1—if you’re picky).

  • A Complete Guide to Sitemaps: Types and Resources

    Sitemaps are created to for web usability purposes and to notify search engines about a site’s page index.Ā  Most people are familiar with HTML and XML sitemaps, however there are multiple types of sitemaps that can provide benefits for your website.Ā  Here is a complete guide of sitemap types, sitemap resources, and how each of these sitemaps can benefit your site.

    HTML Sitemap
    A HTML sitemap is simply a hierarchical list of links on a web page that helps web visitors review in a quick glance a site’s index of pages, which helps promote site usability.Ā  A well built HTML sitemap will highlight pages of a site with great importance and diminish 2nd or 3rd tier pages, making it easy to search an entire website from one web page.

    Resource: HTML Sitemaps Guide

    googlebot1
    Image Credit: eVisibility

    XML Sitemap
    XML sitemaps are created for search engines to inform them about URLs that are available on a website to be crawled.Ā  For large sites or sites that have accessibility issues, can make it difficult for search engines to index all of its pages.Ā  By submitting a XML sitemap, it will help search engines find all of those pages that can be nested a few directories deep.Ā  See an example of a XML sitemap.

    Resource: SEOmoz – XML Sitemaps: Guideline on their Use

    ROR Sitemap
    A XML variant, ROR sitemaps are used to describe any object on a website.Ā  They are much more robust than XML because it supports multiple formats including URLs, products, articles, company bios, events, etc.

    To create a ROR sitemap try ROR Sitemap Generator or Cumbrowski’s Free ROR Sitemap Generator.

    Video Sitemap
    A Video sitemap contains links to a videos landing page, along with information that is essential for indexing the video to make it searchable for sites like Google Video. To submit a video sitemap to Google there are certain fields that are required including the video url, the video and video player location, a video thumbnail, and a video title and description.Ā  Google can crawl the following formats; .mpg, .mpeg, .mp4, .mov, .wmv, .asf, .avi, .ra, .ram, .rm, .flv.

    Geo Sitemap
    Google recognizes Geo Sitemaps that enable you to publish geo-content that can be searchable in Google Maps and Google Earth.Ā  Geo-content can be in KML or GeoRSS format.Ā  Be sure to add the attribution tag which appears in the Google search results for your content.

    News Sitemap
    News sitemaps allow webmasters to have more control over their content that gets submitted to Google News.Ā Ā  You can also add additional information about your news, like article title, publication date, and keywords.Ā  Using a news sitemap is perfect for websites that are new, have dynamic content, or large sites that can be hard to find content.Ā  Keep in mind that Google only allows you to submit content from the last three days.

    Mobile Sitemap
    Mobile sitemaps allow you to submit a list of URLs with content specifically designed for mobile devices and is used in the search engine’s mobile index.Ā  Searching the mobile web is different than the regular web, for instance it only displays sites that are “mobile friendly.”Ā  Using well-formed markup like WML, cHTML, XHTML Basic or XHTML MP formats will ensure your content gets crawled.Ā  See an example of a Mobile Sitemap.

    Recommended Sitemap Resources

    Google Sitemap Generator
    Allows you to create XML, News, Mobile, Geo, HTML, Text, ROR, and Video sitemaps. Unlike 3rd party sitemap generators, the Google Sitemap Generator will monitor your website content and update automatically.

    AuditMyPC – XML Sitemap Generator
    Create unlimited XML and HTML sitemaps.Ā  You must have Sun’s Java Runtime installed in order to create a sitemap.

    XML Sitemaps.com
    Allows you to create XML, ROR, Text and HTML sitemaps, up to 500 pages (Free Version) or Unlimited pages for the paid version.Ā  Paid version cost $19.99.

    Google XMLĀ  Sitemaps for WordPress
    This wordpress plug-in is by far the best sitemap generator.Ā  Nathan Rice has a great post on the Ultimate Guide to WordPress SEO that goes into great detail of the plugin and the process.

  • How To Know if a Site has been Penalized by Google

    Do you have a website that used to rank on the 1st page of Google for all of your primary keywords, then it suddenly vanishes out of the SERPs?Ā  It could be that Google has penalized your site.Ā  So you are probably wondering how can you tell if your site has been penalized, and why did it get penalized?Ā  There are a number of off-site and on-site factors that could be the reason.Ā  Unfortunately there is no easy way to tell if Google has penalized your site.Ā  However, there are indications you can look at to assume it has be penalized.

    Before you start to try and diagnose your site, it is best to understand the difference between Google penalizing your site and Google banning your site.Ā  When Google penalizes a website, they will decrease your site’s visibility by bumping your organic ranking down in the search engine results.Ā  Google has different levels of penalties based on the severity of what they feel is “unethical” or “malicious” SEO practices.

    When a site gets banned by Google, this means that your website is completely removed from their index.Ā  This happens only in extreme cases, when Google feels you are trying to deceive the search engines by tricking them into giving your site better search rankings without merit.Ā  Usually if your site gets banned, it can take anywhere from 6-12 months to get your site re-indexed (assuming you remove the problem).Ā  You can try re-submitting your url to Google once the issues have been fixed.

    Have you been Penalized? Use this checklist to find out!

    PageRank: The first thing you will want to do is check your PageRank and see if the bar is grayed out.Ā  That is theĀ  easiest way to know if your site is penalized.Ā  Unless your website is brand new, it will usually have at least a PR of 0.

    481220805_086e05ce16_o

    Search Query: Do a Google search for your company name.Ā  Does it show up?Ā  If you do not even come up for your company name, that is a sure sign that Google has penalized you.

    company-name

    Check Your Server: It is possible that if your website was offline the last time a GoogleBot crawled your site, that it removed it from the search results because it thought the site was no longer available.Ā  You can use some site monitoring software to make sure that your site is online.

    Hosting: If you are using a shared hosting account, you could indirectly be penalized from Google.Ā There could be other sites that share the same IP that are doing malicious or blackhat SEO tactics that could potentially penalize all of the other sites on that hosting account.Ā  Try doing a Reverse IP Lookup to see what other domains are sharing hosting.Ā  YouGetSignal will highlight sites in red that pose a problem.

    reverse-ip-domain-check

    Content: If you have lots of duplicate content that is scraped from other sources on the web, Google may penalize you for that too.Ā  Run your site link through a duplicate content checker like Copyscape, Virante, or Plagium.Ā  If you only have a few paragraphs that are duplicated, that will not be enough to get you penalized.Ā  Usually if an entire site is bootlegged content, that is when Google will take action.

    copyscape-search

    Links: If you are getting a lot of paid links or acquiring a lot of inbound links from “bad neighborhoods” that can also hurt your rankings.Ā  Try putting your site through Majestic’s Bad Neighborhood Checker to see if any of your links are coming from sites that may beĀ  link farms.Ā  You can also use any backlink analyzing tool to see all of the backlinks coming to your site.

    backlink1

    Blackhat SEO: If you are practicing any blackhat SEO tactics like cloaking links, doorway pages, keyword stuffing, hidden text, etc…you can be penalized by Google.

    Google does have a page called Safe Browsing Digosntic that allows you to enter your url and Google will give you some useful feedback on if they can detact any malicious activity.

    http://www.google.com/safebrowsing/diagnostic?site=mysite.com

    Make sure you add your website url to the end of this url where it says =mysite.com.

    safe-browsing

    There is also another Spam Decector tool that will analyze a website and point out any characteristics of a site that a search engine could consider spam.

    Related Posts:

    How Many Google Penalties Are There?

    How To Handle a Google Penality

    SEO 101: Google Penalities

  • Google Local Business Listings Now Have Analytics

    lbc_logo_en

    Google now incorporates local business listings on two levels: local-based searches and broad-based searches. Because of these new methods it is extremely important to have a complete and detailed local business profile.Ā  Similar to Google’s algorithm for ranking websites in the organic SERPs, there are a number of local search ranking factors that contribute to ranking well in the local business results.

    There use to be no easy way to know how much traffic you gain from your local business listing, until now!Ā  Google has just integrated basic analytics reporting within your local business center.Ā  Not only can you see the basic data like impressions, you can also see key actions people take on your local listing.

    Your local business profile has become much more relevant than ever before. We highlight 3 key benefits that make a world of difference.

    1. Google has defined a local business listing action as someone clicking for more info on the following: Maps, requesting driving directions, and clicking through to your website.

    google-local-business-analytics1

    2. You can easily see what keywords and phrases people are searching to find your local listing.

    top-search-queries

    3. Google has added the ability to track people who have requested driving directions from your local business listing.Ā  For brick-and-mortar stores, this could help you identify how far people are willing to drive to get to your location.Ā  In turn, if you are doing PPC advertising you can try to geo-target those locations.

    geo-location

    I’m sure that this is only a sign of things to come to better enhance the tracking capabilities for your local business listings.Ā  You may want to leverage this data by adding new content (videos, images, logos, business description) to your listing to see if it helps increase impressions, clicks, driving direction requests, etc.

    Sign up and verify your local business listing in Google, Yahoo, and MSN.Ā  You may also want to check out quick tips for local SEO, for some helpful guidelines on how to help your website rank higher for localized searches.

  • Beyond HTML 5 and CSS 3: Sample of Suggestions

    Since HTML 5 and CSS 3 are still in the working drafts, I thought I would propose a few ideas I’ve been cooking up that would make my life easier and perhaps add an edge to the constantly evolving standards. Although, I hope these ideas never become a piece of proprietary junk that Internet Explorer or Mozilla latches onto on their own. I would hate to aid non-standards.

    I realize some of my ideas may go beyond the so-called “scope” of the original intentions of CSS and HTML/XHTML. But my hope, like all “

    I’ll begin with HTML first, since semantic markup is the most important:

    1. Custom Elements

    I’ve read some of the working draft for HTML 5 and I must say that I’m impressed with some of the ideas that have been added. It’s going to give more meaning to HTML code, which is precisely what web developers need! However, I did cringe at the proposed “header” and “footer” elements. I understand their purpose, but aren’t the words header and footer presentational? For instance, what if at first I designed the footer to be at the bottom of the document. In the markup, perhaps it is. But later (for some odd reason) the client decides he/she wants that info to be moved to the top? Would this still be considered the “footer?” I’m sure there are several sides to the argument, but I’ve also read accounts where people like Andy Clarke have proposed the same. Footers should be “siteinfo” and headers should be “branding” or “masthead.” In contrast, Dan Cederholm and Andy Budd still use “header” and “footer” on their personal sites. But regardless of who uses what, I still feel these names are presentational and HTML is for content not for its appearance or layout.

    I really like most of the other elements like “menu,” “section,” “dialog,” “aside,” “datagrid,” etc. They really give more meaning to the markup in place of the generic div’s with id’s. This will definitely give more power to CSS and more meaning to the document at the same time. Specifically it allows you to separate your styles with semantic element names and giving them unique rules with really low specificity instead of making them arbitrary div’s. Simply put, this will give you more control with id’s when they’re needed.

    But what I’m proposing is that instead of giving set element names that will always be debated on their semantic merit, why not give that power over to the developer? If a developer could declare his/her own elements in the head of the document, he/she could have more control. I envision it working something like this:

    
    		<head>
    			<elements type="elements/text">
    				section : div;
    				dialog : div;
    				menu : ul;
    				masthead : div;
    				newelementname : baseelementbehavior;
    			</elements>
    		</head>
    
    				

    In this element named “elements” the code would be handled by the browser. It would read each line, separated by a semi-colon, and take note of the custom elements being declared and determine their base behavior off of the base element listed after the colon. For instance, the first custom item “section” would behave like a “div.” This would give ultimate control to the developer to make his/her document follow its purpose semantically. This will also open up the possibilities for more microformats! A developer could utilize this to create <tel> elements, <adr> elements, <product> elements, and more, replacing the annoying <div class=”product”> and more nested, loosely based “classitis.”

    2. Definition List Item

    I can’t recall where I saw the <di> element once, but I’ve been unable to relocate it through my web searches.XHTML 2’s working draft describes a definition list item, but I wonder why this element is still not supported well, if at all. And I didn’t see any proposed plans for it in the HTML 5 working drafts. I feel that this would be a good addition because it provides one more “hook” for styling and more meaning as well. The definition item would separate definition terms and their descriptions from others. If I was creating a list of definitions, each term and its description or descriptions should be separated logically from its siblings. Thus the <di> element would encase and separate each item.

    3. CSS Snap Declaration

    My third proposal is for a CSS 3 style declaration called “snap.” This can replace the need to use javascript to snap elements to non-parental elements. This “snapping” has been done via javascript on many old versions of dropdown menus. Now with CSS and better standards, the snap is no longer needed for menus. But the need for snap in other presentational ways is still warranted. What if I wanted to “snap” one element in the lower portion of the document to another element that was completely unrelated? I could simply add it to the style rule:

    
    		#snapping-element {
    			display: block;
    			width: 300px;
    			snap: #host-element;
    			left: 0; top: 10px;
    			…
    		}
    				

    In this example, the element with the id “snapping-element” will be snapped to the element with the id of “host-element.” Host-element, however, probably should be positioned relative; and the snapping-element’s position will be based off host-element’s relative state. Much like how absolute works, except that absolute is limited to basing itself off of ancestral elements.

    4. Column Hovers

    Placing a hover on a table row is a cinch. But what if I wanted to create a triangulation effect for the rows and columns with a different hover state color? I can’t! I’ve seen others mention it in posts, but I haven’t seen any plans to integrate this into CSS. Why not? This would provide another layer of accessibility/legibility to users with a simple col:hover rule. Of course the colgroup elements must all be declared in order for this to work.

    5. Javascript-type Psuedo-classes

    My last proposal to CSS 3 is probably the most CSS-scope-defying of them all. What if there were more pseudo-classes available other than just visited, hover, active, focus, etc? Why not onclick? I realize focus is currently a bit of a Mozilla proprietary state, but it’s a really good one! If javascript already handles onmouseover (hover) and onblur and onfocus (focus), why not onclick?! Man would this be powerful! All javascript toggling could be handled in CSS! But this event catching is a bit more daring for CSS’s scope of just styling. But why not, eh?

    Conclusion

    Perhaps some of this has been mentioned before me. I’m not sure. If not, then I’m glad to be able to provide some recommendations. If so, I apologize for assuming credit, that’s not my intention. I do however feel that these would provide a lot more meaning to HTML 5 and more power and control for the visual and presentational experience to CSS 3.

    Any comments, suggestions, critiques are happily welcomed. Just some food for thought.

  • CSS 2.1 Selector Specificity

    I’m probably the 100th person to write about CSS 2.1’s selector specificity, but I’m going to take a stab at it anyway since it seems to be such a stumbling block for so many people.

    I’m not writing this to take away from the brilliant explanations of Andy Clarke, Patrick Griffiths, Eric Meyer, or Molly E. Holzschlag, but to merely supplement their posts with, perhaps, another angle. Many people feel the need to re-explain this topic in layman’s terms rather than enduring W3C’s overly technical explanation about specificity.

    What is specificity?

    To be brief, it’s the applied calculation of the priorities of CSS selectors and how they cascade through a stylesheet. Simply put, selectors with a higher specificity will overrule other selectors in the cascading order.

    How it works

    There are two ways to determine specificity — the “right” way and the “quick and dirty” way. According to W3C, the specificity is officially calculated using four numbers concatenated, like: a, b, c, d . The “quick and dirty” technique is to assign values to each type of selector and add the values up. For example, general elements have a value of 1, classes have a value of 10, ID’s have a value of 100, and inline styles have a value of 1000. However, this value-based “quick addition” technique is a bit misleading because it presumes that 10 of any value will override the next highest selector. Following that logic if you have 10 ID’s in a style declaration those will override an inline style, because 10 ID’s are worth 100 x 10 which equals 1000 — inline styles being worth 1000. This statement is far from true. However, it can still be used as an easy way to get an idea of the specificity of a particular selector in a declaration; but it should never be fully relied upon.

    The W3C states that Concatenating the four numbers a-b-c-d (in a number system with a large base) gives the specificity. This is the correct method to rely on. The reason is because it separates the values into 4 categories: a, b, c, & d. The variable a is reserved for the number of inline styles and has the highest priority. While b is for the number of ID’s, c is for the number of other attributes (including class, but not ID’s) and pseudo-classes, and d is the number of elements. This is the correct order of specificity and pseudo-elements are to be ignored.

    Let’s focus on b and c since these are the subjects of confusion. ID selectors (b) are the most valuable asset to CSS, so they are given the second highest priority, next to inline styles (a). ID selectors are written with a # in front of the name given to the ID. So, #content is referencing <div id="content"> which has a value of 100 using the “quick and dirty” method. These selectors, like all selectors, can be used in combination with any other selectors. For instance, #main-area #content would add up to 200.

    Class selectors and other attribute selectors are assigned the variable c. These are each given a value of 10 using the “quick and dirty” method. Class selectors are denoted with a dot (.) before the name of the class, like .box. Attribute selectors are declared with the attribute name inside a set of brackets — a[rel="friend"]. It is not necessary to include the value of the attribute. Additionally, the = can be replaced with ~=, *=, ^=, or $= depending on how you’re equating the value. A better concept of these equations can be found on 456 Berea St’s CSS 3 selectors explained post.

    Note: Attribute selectors of CSS 2.1 are supported by most modern browsers, and when I say modern browsers I do not mean Internet Explorer 6.

    Initially what confused me about attribute selectors and their specificity was whether or not using class= or id= in the attribute selector made it behave like the # (ID) or . (class) of its CSS 2 predecessors. After doing some testing and reading, I found that the attribute selector has the exact same specificity as the class selector (.), regardless of whether it says id= within its little brackets. It will always have a value of 10. Thus, div[id="content"] is less specific than div#content.

    Here’s an easy way to visualize all of this (in a poorly misunderstood table element):

    exampleinline styleID selectorsclass/attribute selectorselement/type selectors“quick and dirty” value
    style=""1,0,0,01000
    p0,0,0,11
    p em
    0,0,0,22
    p.whatever0,0,1,111
    p[id="whatever"]0,0,1,111
    p[href="whatever"]0,0,1,111
    #whatever p0,1,0,1101
    #whatever p.whatever0,1,1,1111
    #whatever1 #whatever2 p.whatever0,2,1,1211

    If you haven’t seen any specificity charts before I hope my interpretation helped explain it further. Be sure to check out the other explanations too, because Andy Clarke has an awesome example using siths from Star Wars. Maybe I’ll make a diagram of my own someday.