Created
May 16, 2015 13:28
-
-
Save pafnuty/9fcfdb03df1eedfb4261 to your computer and use it in GitHub Desktop.
Псевдоссылки 2.0
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
// Псевдо-ссылки 2.0 | |
$(document) | |
// для открытия "ссылки" в текущем окне | |
.on('click', '[data-target-self]', function (e) { | |
var url = $(this).data('targetSelf'); | |
if (e.metaKey || e.ctrlKey || e.button === 1) { | |
window.open(url); | |
} else { | |
location = url; | |
} | |
}) | |
// для открытия "ссылки" в новом окне | |
.on('click', '[data-target-blank]', function () { | |
window.open($(this).data('targetBlank')); | |
}); | |
// Использование. | |
// Ctrl+Click по [data-target-self] откроет ссылку в новом окне (как будто это обычная ссылка) | |
// <span data-target-self="http://goo.gl">гугл</span> | |
// <span data-target-blank="http://goo.gl">гугл</span> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment