Last active
December 16, 2015 09:49
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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' />"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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