I wrote this Jqeury to make it work with asp.net update panel. I know i do little bit of hacking to make it work just. I want to get some help in how to optimize and remove the hacks from my script.
<script type="text/javascript">
//get all elemnt with class .resource-download
$.each($(".resource-download"), function () {
var fileExtension = getFileExtension(this.href);
if (fileExtension == "" || fileExtension != "pdf") {
$(this).addClass("hideLinke");
}
});
//load script agine
function init() {
$.each($(".resource-download"), function () {
var fileExtension = getFileExtension(this.href);
if (fileExtension == "" || fileExtension != "pdf") {
$(this).addClass("hideLinke");
}
});
}
// getFileExtension
function getFileExtension(fileURL) {
if (fileURL.indexOf('.') === -1) { return ""; } //check for no extension
return fileURL.split('.').pop();
}
//loadGridLayout
function loadGridLayout() {
$('#grid-wrapper').masonry();
$('.selectpicker').selectpicker();
$('.btn-hamburger').click(function () {
$('.lts-nav').toggleClass('expanded');
$('.wrapper').toggleClass('wrapper-expanded');
});
/* iPhone Site Search Styling */
var searching = false;
$('.search-add-on').click(function () {
if ($(window).width() < 480) {
$('.section-1 .search-hideable').toggle();
$('.section-1 .site-search').focus();
searching = true;
}
});
$('.site-search').blur(function () {
if ($(window).width() < 480) {
$('.section-1 .search-hideable').toggle();
searching = false;
}
});
$(window).resize(function () {
if ((searching || !$('.site-search').is(':visible')) && $(window).width() > 480) {
$('.section-1 .search-hideable').toggle(true);
$('.section-1 .search-hideable').removeAttr('style');
searching = false;
}
});
}
//add script to script manager
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_endRequest(init);
prm.add_endRequest(loadGridLayout);
</script>