Showing posts with label Javascript. Show all posts
Showing posts with label Javascript. Show all posts

How to Open all external links in a new window

$('a').each(function() {
// The link's href
var theHref = $(this).attr('href').toLowerCase();
// The current domain
var currentDomain = window.location.host;
    // Kill any subdomains
    var noSubDomain = currentDomain.match(/[^\.]*\.[^.]*$/)[0];
    // Create a new (case insensitive) regex from the clean domain
var theDomain = new RegExp(noSubDomain, 'gi');

if(/^https?/gi.test(theHref)) {
// This link is using HTTP/HTTPs and is probably external
if(theDomain.test(theHref)) {
// Do nothing. For some reason, this site is using absolute internal links        
        } else {
$(this).attr('target', '_blank');
}
}
});

How to Add "Post to Diigo" button on website

<a href="#" onclick="window.open('https://www.diigo.com/post?url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title), '_blank', 'menubar=no,height=580,width=608,toolbar=no'); return false;">
  <img src="https://lh4.ggpht.com/PaV4x6Q92xFbKHOyS-FpZ7jzWDdAWrnhOAb0d8t_SODgsXWHhO8PNCvLkQWU-k3vwPQO=w50" height="16" width="16" alt="Diigo"> Post to Diigo
</a>

Get Viewport width. jQuery

function viewportWidth() {
    var $body = $('body'),
        viewPortWidth = $body.css('overflow', 'hidden').width();
   
    $body.css('overflow', '');

    return viewPortWidth;
}

Position Expression to place a layer on edge of solid

l = thisComp.layer("bar") //the control layer
startX = l.transform.position[0]; //the position of the control layer
s = l.transform.scale[0]/100; //the scale divided by 100 to get a decimal

//This checks the index of the layer and uses it to flip the sign
halfWidth = l.width/2;
if(index%2!=0){
halfWidth *= -1;
}

posX = startX + (-halfWidth*s); // the original pos + half the width * the scale

[posX, value[1]]; // setting the value