Tuesday, November 22, 2016

Find all Internal Links

Find all links that start with the sites domain, a slash, relative file path, or a hashtag.
var siteURL = "http://" + top.location.host.toString();

var $internalLinks = $("a[href^='"+siteURL+"'], a[href^='/'], a[href^='./'], a[href^='../'], a[href^='#']");

Draggable without jQuery UI

It doesn't have all the fancy callbacks and options, but hey, it makes things draggable (and with a specified handle optionally).
(function($) {
    $.fn.drags = function(opt) {

        opt = $.extend({handle:"",cursor:"move"}, opt);

        if(opt.handle === "") {
            var $el = this;
        } else {
            var $el = this.find(opt.handle);
        }

        return $el.css('cursor', opt.cursor).on("mousedown", function(e) {
            if(opt.handle === "") {
                var $drag = $(this).addClass('draggable');
            } else {
                var $drag = $(this).addClass('active-handle').parent().addClass('draggable');
            }
            var z_idx = $drag.css('z-index'),
                drg_h = $drag.outerHeight(),
                drg_w = $drag.outerWidth(),
                pos_y = $drag.offset().top + drg_h - e.pageY,
                pos_x = $drag.offset().left + drg_w - e.pageX;
            $drag.css('z-index', 1000).parents().on("mousemove", function(e) {
                $('.draggable').offset({
                    top:e.pageY + pos_y - drg_h,
                    left:e.pageX + pos_x - drg_w
                }).on("mouseup", function() {
                    $(this).removeClass('draggable').css('z-index', z_idx);
                });
            });
            e.preventDefault(); // disable selection
        }).on("mouseup", function() {
            if(opt.handle === "") {
                $(this).removeClass('draggable');
            } else {
                $(this).removeClass('active-handle').parent().removeClass('draggable');
            }
        });

    }
})(jQuery);

Usage
$('div').drags();

Display Browser and Version

This is jQuery specific, and contains a bit of a hack/fix for dealing with Chrome. This works between jQuery 1.5.1 and jQuery 1.8.3. It's gone in jQuery 1.9. Presumably because it was used too improperly too frequently and it was hurting the web. Better to feature detect when possible.
var userAgent = navigator.userAgent.toLowerCase(),
    browser   = '',
    version   = 0;

$.browser.chrome = /chrome/.test(navigator.userAgent.toLowerCase());

// Is this a version of IE?
if ($.browser.msie) {
  userAgent = $.browser.version;
  userAgent = userAgent.substring(0,userAgent.indexOf('.')); 
  version = userAgent;
  browser = "Internet Explorer";
}

// Is this a version of Chrome?
if ($.browser.chrome) {
  userAgent = userAgent.substring(userAgent.indexOf('chrome/') + 7);
  userAgent = userAgent.substring(0,userAgent.indexOf('.')); 
  version = userAgent;
  // If it is chrome then jQuery thinks it's safari so we have to tell it it isn't
  $.browser.safari = false;
  browser = "Chrome";
}

// Is this a version of Safari?
if ($.browser.safari) {
  userAgent = userAgent.substring(userAgent.indexOf('safari/') + 7); 
  userAgent = userAgent.substring(0,userAgent.indexOf('.'));
  version = userAgent; 
  browser = "Safari";
}

// Is this a version of Mozilla?
if ($.browser.mozilla) {
 //Is it Firefox?
 if (navigator.userAgent.toLowerCase().indexOf('firefox') != -1) {
  userAgent = userAgent.substring(userAgent.indexOf('firefox/') + 8);
  userAgent = userAgent.substring(0,userAgent.indexOf('.'));
  version = userAgent;
  browser = "Firefox"
 }
 // If not then it must be another Mozilla
 else {
   browser = "Mozilla (not Firefox)"
 }
}

// Is this a version of Opera?
if ($.browser.opera) {
 userAgent = userAgent.substring(userAgent.indexOf('version/') + 8);
 userAgent = userAgent.substring(0,userAgent.indexOf('.'));
 version = userAgent;
 browser = "Opera";
}

// Now you have two variables, browser and version
// which have the right info

Check if Event was Triggered or Native

$('button').click(function(event, wasTriggered) {
    if (wasTriggered) {
        alert('triggered in code');
    } else {
        alert('triggered by mouse');
    }
});

$('button').trigger('click', true);

Check if jQuery is Loaded

if (typeof jQuery == 'undefined') {

    // jQuery IS NOT loaded, do stuff here.

}

Tuesday, October 18, 2016

Transparent Circular Loader

<div class="util-bar">
 <label for="">Change Background: </label>
  <button class="green"></button>
  <button class="teal"></button>
  <button class="blue"></button>
  <button class="pink"></button>
  <button class="red"></button>
  <button class="orange"></button>
  <button class="abstract"></button>
  <button class="nature"></button>
  <button class="food"></button>
</div>
<div class="loader">
  <span class="spinner"></span>
  Loading
</div>
Test here

Autofill submit button

<span>Required:</span> <input required=required type="text"> <br>
<span>Required:</span> <input required=required type="text"> <br>
<span>Required:</span> <input required=required type="text"> <br>
<span>Required:</span> <input required=required type="text"> <br>
<div>
  <button>Send</button>
</div>

Test here

How to Put Google Adsense Below Post Title in Blogger?

Adsense is used by  majority  of expert bloggers for their website monetization because it is a cookie based contextual advertising syste...