Skip to content

Instantly share code, notes, and snippets.

@stephandesouza
Last active December 16, 2015 09:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stephandesouza/5415773 to your computer and use it in GitHub Desktop.
Save stephandesouza/5415773 to your computer and use it in GitHub Desktop.
Better jQuery Support on ML Advert Wordpress Plugin http://wordpress.org/extend/plugins/ml-adverts
<?php
/*
* With this we remove all not necessary HTML Tags for the URL and use the Title attr, also add a "ml-advert" metada for jQuery on() control
Where:
$ret_val = "<a" .
" href='" . MLA_BASE_URL . "out.php?id=" . $this->get_advert_id() . "'" .
" onmouseover='maskLink(this,event,\"" . $url_mask . "\")'" .
" onclick='maskLink(this,event,\"" . $url_mask . "\")'" .
" onmouseout='maskLink(this,event,\"" . $url_mask . "\")'" .
" rel='nofollow'" .
" nopin='nopin'" .
" target='_blank' />";
Change To:
*/
$ret_val = "<a" .
" href='" . MLA_BASE_URL . "out.php?id=" . $this->get_advert_id() . "'" .
" title='" . $url_mask . "'" .
" data-mladvert='" .$this->get_advert_id() . "'" .
" rel='nofollow'" .
" nopin='nopin'" .
" target='_blank' />";
<?php
/*
* Put it on bottom, better Front-end performance
Where:
wp_enqueue_script( 'ml_adverts_public_js', MLA_JS_URL . 'public.js', array( 'jquery' ), MLA_VERSION );
Change To:
*/
wp_enqueue_script( 'ml_adverts_public_js', MLA_JS_URL . 'public.js', array( 'jquery' ), MLA_VERSION, true );
/**
* Better jQuery Support
Where:
function maskLink(el,e,mask){
e = e || event;
el.originalHref = el.originalHref || el.href;
if (/click|out/i.test(e.type)){
return el.href = el.originalHref;
} else {
el.href = mask;
}
}
Change To:
*/
(function($, window, document, undefined) {
function maskLink(e) {
this.originalHref = this.originalHref || this.href;
if (/click|out/i.test(e.type)) {
return this.href = this.originalHref;
} else {
this.href = this.title;
}
}
$(function() {
$(document).on('mouseover', 'a[data-mladvert]', maskLink)
.on('click', 'a[data-mladvert]', maskLink)
.on('mouseout', 'a[data-mladvert]', maskLink);
});
})(jQuery, window, document);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment