Skip to content

Instantly share code, notes, and snippets.

@birkir
Last active November 23, 2018 14:22
Show Gist options
  • Save birkir/b3f6122ed0f9beaa818f1ceef636da82 to your computer and use it in GitHub Desktop.
Save birkir/b3f6122ed0f9beaa818f1ceef636da82 to your computer and use it in GitHub Desktop.
How things were done back in 2012
/**
* Islandsbanki 2.0
* @copyright Islandsbanki (c) 2013
* @author Birkir Gudjonsson (birkir.gudjonsson@gmail.com)
*/
var Islandsbanki = function() {
$(".allownumericwithdecimal")
.on("keypress keyup blur", function(event) {
//this.value = this.value.replace(/[^0-9\.]/g,'');
$(this)
.val($(this)
.val()
.replace(/[^0-9\.]/g, ''));
if ((event.which != 46 || $(this)
.val()
.indexOf('.') != -1) && (event.which < 48 || event.which > 57)) {
event.preventDefault();
}
});
$(".allownumericwithoutdecimal")
.on("keypress keyup blur", function(event) {
$(this)
.val($(this)
.val()
.replace(/[^\d].+/, ""));
if ((event.which < 48 || event.which > 57)) {
event.preventDefault();
}
});
$('#compare_expand_btn')
.click(function() {
var btn = $(this);
$('.morerows')
.toggle();
btn.parent()
.remove();
});
$('.hidemail')
.click(function() {
$(this)
.attr('href', $(this)
.attr('href')
.replace('[hjá]', '@'))
});
$.support.cors = true;
var windowheight = $(window)
.height();
var sidetop = (windowheight - 343) / 2;
$('.sidelinks-wrapper')
.css('top', sidetop);
setTimeout(function() {
$("#netspjall-open")
.trigger("click");
}, 40000);
$("#netspjall-open")
.click(function() {
$(".netspjall-side")
.animate({
width: "300px",
"margin-left": "-262px"
}, 700, function() {});
$('.netspjall-side .vantar-thig-adstod')
.css('display', 'block');
$('.netspjall-side .netspjall-btn')
.css('display', 'block');
$('.netspjall-side .close')
.css('display', 'block');
});
$("#netspjall-close")
.click(function() {
$(".netspjall-side")
.animate({
width: "38px",
"margin-left": "0"
}, 700, function() {});
$('.netspjall-side .vantar-thig-adstod')
.css('display', 'none');
$('.netspjall-side .netspjall-btn')
.css('display', 'none');
$('.netspjall-side .close')
.css('display', 'none');
});
$(".nettalk-mobile.btn.btn-primary.btn-large.hidden-print")
.on("touchend", function(event) {
OpenSeWinDOO();
});
// scope (used internaly)
var isb = {};
// handle panels
// -------------
isb.panels = (function() {
// live event for panel bodies
$(document)
.on('show', '.panel-body, .accordion-body', function() {
// add open class to its parent
$(this)
.parents('.panel-collapse, .accordion-group')
.addClass('open');
})
.on('hide', '.panel-body, .accordion-body', function() {
// remove open class to its parent
$(this)
.parents('.panel-collapse, .accordion-group')
.removeClass('open');
});
}());
// Set Email Confirmation Forms
// -------------------
isb.emailconfirm = (function() {
function ValidateEmails() {
if (validateEmail($('.emailfield')
.val())) {
$('.emailfield')
.parent()
.find('.emailCheck')
.show();
$('.emailfield')
.parent()
.find('.emailFail')
.hide();
} else {
$('.emailfield')
.parent()
.find('.emailCheck')
.hide();
$('.emailfield')
.parent()
.find('.emailFail')
.show();
}
if (validateEmail($('.emailfield')
.val()) && ($('.emailfield')
.val() === $('.emailconfirmfield')
.val())) {
$('.emailconfirmfield')
.parent()
.find('.emailCheck')
.show();
$('.emailconfirmfield')
.parent()
.find('.emailFail')
.hide();
} else {
$('.emailconfirmfield')
.parent()
.find('.emailCheck')
.hide();
$('.emailconfirmfield')
.parent()
.find('.emailFail')
.show();
}
}
$(".emailconfirm")
.submit(function(event) {
var email = $(this)
.find(".emailfield");
var confirm = $(this)
.find(".emailconfirmfield");
if (email.val() !== confirm.val()) {
confirm.focus();
$(".listobject-form")
.find('.errors')
.remove();
$(".listobject-form")
.prepend($('<div class="errors"></div>')
.append($('<ol></ol>')
.append($('<li></li>')
.html('Staðfestingar netfang er ekki rétt.'))));
event.preventDefault();
}
if (!ValidateEmail(email) && !ValidateEmail(confirm)) {
$(".listobject-form")
.find('.errors')
.remove();
$(".listobject-form")
.prepend($('<div class="errors"></div>')
.append($('<ol></ol>')
.append($('<li></li>')
.html('Netfang er ekki á réttu formi.'))));
event.preventDefault();
}
});
$('.emailfield,.emailconfirmfield')
.bind('keyup focus focusout change', function() {
ValidateEmails();
});
}());
// handle tablet
// -------------
isb.tablet = (function() {
// find side menu open button
$('.page-header .btn.visible-tablet')
.on('click', function() {
// toggle active class to btn
$(this)
.toggleClass('active');
// toggle active class to sidebar
$('.page .sidebar')
.toggleClass('active')
.css({
left: $(this)
.offset()
.left
});
});
}());
// handle phone
// ------------
isb.phone = (function() {
// loop through tables
$('table')
.each(function() {
// define table
var table = $(this);
// when table has table-draggable class
if (table.hasClass('table-draggable')) {
// wrap table with table-wrap class
table.wrap($('<div/>', {
'class': 'table-wrap'
}));
}
// when table has table-sort class
if (table.hasClass('table-sort')) {
// attach table sorter
table.tablesorter({
cssAsc: 'table-sort-asc',
cssDesc: 'table-sort-desc',
cssHeader: 'table-sort-header'
});
}
});
}());
// form controls
// -------------
isb.form = function() {
// detect operating systems
var ua = navigator.userAgent.toLowerCase(),
noStyles = ((ua.match(/iPhone/i) || ua.match(/iPad/i) || ua.match(/iPod/i) || ua.match(/android/i)) ? '.noStyles' : '');
// sliders input>[type= range]
$('input[type=range]' + noStyles)
.each(function() {
if ($(this)
.hasClass('initialized')) return;
var range = $(this),
prefix = range.data('prefix') !== undefined ? range.data('prefix') : '',
suffix = range.data('suffix') !== undefined ? range.data('suffix') : '',
slider = $('<div />')
.attr('class', range.attr('class'))
.on('slide', function(event, ui) {
$(ui.handle)
.find('.tooltip-inner')
.text(prefix + ui.value + suffix);
range.val(ui.value);
})
.slider({
create: function() {
$(this)
.find('.ui-slider-handle')
.html('<div class="tooltip fade top in" style=""><div class="tooltip-arrow"></div><div class="tooltip-inner" style="white-space: nowrap;">' + prefix + range.val() + suffix + '</div></div>');
},
value: parseInt(range.val(), 0),
min: range.attr('min') !== undefined ? range.attr('min') : 0,
max: range.attr('max') !== undefined ? range.attr('max') : 10,
step: range.attr('step') !== undefined ? range.attr('step') : 1
});
range.addClass('initialized')
.hide()
.before(slider)
.on('change', function() {
slider.slider('value', parseInt(range.val(), 0));
slider.trigger('slide');
});
});
// select dropdowns
$('select:not(.normal)' + noStyles)
.select2({
minimumResultsForSearch: 25
});
//select box get rid of extra bottom border on load
$(".select2-drop.select2-display-none")
.each(function() {
$(".select2-drop")
.css('display', 'none');
});
// select input field bind
$('select[data-bind]')
.bind('change', function() {
$(this)
.parents('form')
.find('[name = "' + $(this)
.data('bind') + '"]')
.val($(this)
.find('option:selected')
.data('bind'));
})
.trigger('change');
// money fields
$('input.money')
.maskMoney({
thousands: '.',
precision: 0,
allowZero: true
});
// percent fields
$('input.percent')
.each(function() {
$(this)
.on('keypress', function(e) {
var k = e.keyCode || e.which,
v = $(this)
.val(),
n = v.replace(/[A-Za-z$]/g, '');
if (v !== n) $(this)
.val(n);
if (!v.match(/\,|\./g) && (k == 44 || k == 46)) return true;
if (!v.match(/\-/g) && k == 45) return true;
if ((k >= 48 && k <= 57)) return true;
return false;
})
.on('keyup', function(e) {
var o = $(this)
.val(),
n = $(this)
.val()
.replace(/\./g, ',');
if (o !== n) $(this)
.val(n);
})
.on('copy, paste', function(e) {
e.preventDefault();
});
});
// datepicker fields
$('.datepicker')
.each(function() {
$(this)
.datepicker({
format: $(this)
.data('format') || 'dd.mm.yyyy',
weekStart: 1,
language: $(this)
.data('lang') || 'is'
});
});
$('[data-toggle="tooltip"]')
.tooltip({
animation: false,
delay: {
show: 100,
hide: 100
}
});
// tooltips
$('a[title].tip')
.tooltip({
animation: false,
delay: {
show: 100,
hide: 100
}
});
$('img#attachment-link.tip')
.tooltip({
animation: false,
delay: {
show: 100,
hide: 100
}
});
$('img#video-link.tip')
.tooltip({
animation: false,
delay: {
show: 100,
hide: 100
}
});
// /einstaklingar/sparnadur/skattfrjals-radstofun/
$('.personal-pension-application-form .ajax-submit')
.click(function() {
$('.ajax-loader')
.show();
var pageid = $(this)
.attr('data');
var str = $(this)
.parent()
.parent()
.serialize();
$.ajax({
url: '/default.aspx?pageid=' + pageid + '&' + str,
success: function(data) {
$('.personal-pension-application-form')
.html('<div class="success-msg" style="margin-top:80px; text-align:center;"><h2>Takk fyrir.</h2><p>Ráðgjafi mun hafa samband við þig bráðlega.</p></div>');
}
});
return false;
});
var nowTemp = new Date();
var now = new Date(nowTemp.getFullYear(), nowTemp.getMonth(), nowTemp.getDate(), 0, 0, 0, 0);
var checkin = $('#dp1')
.datepicker({
format: $(this)
.data('format') || 'dd-mm-yyyy',
weekStart: 1,
language: $(this)
.data('lang') || 'is',
onRender: function(date) {
return date.valueOf() < now.valueOf() ? 'disabled' : '';
}
})
.on('changeDate', function(ev) {
if (ev.date.valueOf() > checkout.date.valueOf()) {
var newDate = new Date(ev.date)
newDate.setDate(newDate.getDate() + 1);
checkout.setValue(newDate);
}
checkin.hide();
$('#dp2')[0].focus();
})
.data('datepicker');
var checkout = $('#dp2')
.datepicker({
onRender: function(date) {
return date.valueOf() <= checkin.date.valueOf() ? 'disabled' : '';
}
})
.on('changeDate', function(ev) {
checkout.hide();
})
.data('datepicker');
};
// create alert
// ------------
isb.alert = function(title, message, classes, closeBtn) {
// create container div
var alert = $('<div/>', {
'class': 'alert ' + classes
});
// attach close button
if (closeBtn !== false) {
alert.append($('<button/>', {
'type': 'button',
'class': 'close',
'data-dismiss': 'alert'
})
.html('&times;'));
}
// attach alert title
alert.append($('<h3/>')
.html(title));
// attach message to alert
alert.append(message);
// ready to attach the dom!
return alert;
};
// helpful form
// ------------
isb.helpful = (function() {
// find helpful forms
$('.helpful')
.each(function() {
// get container, buttons and form
var helpful = $(this),
noBtn = helpful.find('a.btn-no'),
yesBtn = helpful.find('a.btn-yes'),
form = helpful.find('form');
// post function
helpful.send = function() {
return $.ajax({
url: '/api/helpful',
type: 'POST',
data: form.serialize()
});
};
// set user agent
form.find('#formHelpfulAgent')
.val(navigator.userAgent);
// attach events to form
form.on('show hide', function() {
// toggle btn class
noBtn.toggleClass('active');
// set correct answer to input field
form.find('#formHelpfulAnswer')
.val(noBtn.hasClass('active') ? 'No' : 'Yes');
})
.on('submit', function() {
var checkInput = $('#mustBeEmpty')
.val();
if (checkInput === "") {
// do ajax request
var response = helpful.send();
response.done(function() {
helpful.hide()
.after(isb.alert('Takk fyrir!', 'Ábending þín er móttekin.', 'alert-success alert-block'));
});
response.fail(function() {
helpful.before(isb.alert('Villa kom upp!', 'Því miður kom villa upp við að senda þessa ábendingu. Hafðu samband við vefstjori@islandsbanki.is með tölvupóst.', 'alert-error alert-block'));
noBtn.removeClass('active');
yesBtn.removeClass('active');
});
}
return false;
});
// attach click handler to yes button
yesBtn.on('click', function() {
// set button to active while we do ajax request
$(this)
.addClass('active');
// make sure we have yes for answer
form.find('#formHelpfulAnswer')
.val('Yes');
// very nice
var hadIn = form.hasClass('in') ? form.collapse('hide') : false;
// trigger form submit
form.trigger('submit');
return false;
});
});
}());
// navbar functions
// ----------------
isb.navbar = (function() {
// toggle class on netbanki click
$('.btn-netbanki a.btn')
.on('click', function() {
// check if main navigation is open
if ($('.navbar.navbar-isb')
.hasClass('open')) {
// hide main navigation
$('.navbar.navbar-isb .btn-navbar')
.trigger('click');
}
});
// attach click handler to nodes
$('.navbar li a b')
.on('click', function() {
// remove all backing elements
$('.navbar .backing')
.removeClass('backing');
// find node
var li = $(this)
.parent('a')
.parent('li');
// if node is back node
if (li.hasClass('back')) {
// add backing class, remove forward and open classes
li.parent('ul')
.addClass('backing')
.parent('li')
.removeClass('forward')
.parent('ul.open')
.removeClass('open');
} else if (li.children('ul')
.length > 0) {
// add forward and open classes
li.addClass('forward')
.parent('ul')
.addClass('open');
}
// calculate height of menu
if (li.children('ul')
.length > 0 || li.hasClass('back')) {
$('.navbar .nav-collapse')
.css('height', 50 + (li.hasClass('back') ? li.parent('ul')
.parent('li')
.parent('ul')
.height() : li.children('ul')
.height()));
}
if ($.browser.msie)
$('.navbar-inner')
.css('height', $('.navbar .nav-collapse')
.height() + $('.navbar-inner .form-search')
.height() + 10);
return false;
});
// attach click handler to open menu button
$('.navbar .btn-navbar')
.on('click', function() {
// toggle navigatioon
$('.navbar-isb')
.toggleClass('open');
// if menu has never been open
if (this.firstOpen === undefined) {
if ($.browser.msie)
$('.navbar .nav-collapse li a')
.css('padding-bottom', '0');
// height getter
var height = $('.forward:last')
.children('ul')
.length === 0 ? $('.forward:last')
.parent('ul') : $('.forward:last')
.children('ul');
// set its height
$('.navbar .nav-collapse')
.css('height', 50 + height.height());
// only on runtime
this.firstOpen = false;
}
if (!$('.navbar-isb')
.hasClass('open') && $.browser.msie)
$('.navbar-inner')
.css('height', '40px');
else if ($.browser.msie)
$('.navbar-inner')
.css('height', $('.navbar .nav-collapse')
.height() + $('.navbar-inner .form-search')
.height() + 10);
//fjárfestingaráðgjöf menu fix
$('.navbar .nav-collapse.nav-fjarfestingaradgjof')
.css('height', 750);
});
}());
// proxy tabcontrol
// ----------------
isb.tabs = function() {
// find all tab controls
$('.tabcontrol')
.each(function() {
// collect parameters
var tabcontrol = this,
selectedIndex = $(this)
.find('.tabs .current')
.index(),
tabs = $(this)
.find('.tabs li a'),
identifier = 'navtab-';
// build tab identifier
tabs.each(function() {
identifier += $(this)
.attr('href')
.replace('#', '');
});
// check if selected index was found in localstorage
//Does not work in IE10 - Script error!
if (window.location.hash !== '') {
selectedIndex = tabs.filter('[href=' + window.location.hash + ']')
.parent()
.index();
} else if (localStorage.getItem(identifier) > -1) {
selectedIndex = localStorage.getItem(identifier);
}
// add tabbable to tabcontrol
$(this)
.addClass('tabbable')
.removeClass('tabcontrol')
// wrap with tab content
.wrapInner('<div class="tab-content" />')
// move tabs to outside tab control
.find('.tabs')
.prependTo(tabcontrol)
.addClass('nav nav-tabs')
// find all tab items
.find('li > a')
.each(function() {
// attach data-toggle for bootstrap and remove classes
$(this)
.attr('data-toggle', 'tab')
//.data('href', $(this).attr('href').replace('#', ''))
.data('href', $(this)
.attr('href')
.split('#')[1])
.attr('class', '')
.parent('li')
.attr('class', '');
// fix tab panes
$(tabcontrol)
.find('.tabpane.' + $(this)
.data('href'))
.attr('id', $(this)
.data('href'))
.attr('class', 'tab-pane');
})
// show selected tab(or first tab)
.eq(selectedIndex)
.tab('show');
});
$('.tabbable')
.responsiveTabs({
slideTime: 0
});
$(".sparnadurTafla ul li:nth-child(odd)")
.addClass("odd");
};
isb.sparnadurTabs = (function() {
var device = navigator.userAgent.toLowerCase();
var ios = device.match(/(iphone|ipod|ipad)/);
if (!ios) {
$(".sparnadurTabs .nav-tabs > li")
.mouseover(function() {
var a = $(this)
.find("a");
$(this)
.addClass("active");
$(this)
.siblings("li.active")
.removeClass("active");
$(a.attr("href"))
.addClass("active");
$(a.attr("href"))
.siblings("div.tab-pane.active")
.removeClass("active");
})
.mouseout(function() {
//nothing
});
}
});
// item filter
// -----------
isb.itemFilter = function() {
var list = $($(this)
.data('bind')),
sortKey,
sortOrder,
sortFn = function(a, b) {
if (sortOrder === 'ascending' || sortOrder === 'asc')
return parseInt(a.attributes['data-date'].textContent, 0) > parseInt(b.attributes['data-date'].textContent, 0) ? 1 : -1;
else
return parseInt(a.attributes['data-date'].textContent, 0) < parseInt(b.attributes['data-date'].textContent, 0) ? 1 : -1;
};
$(this)
.on('change', function() {
var filter = $(this)
.find('option:selected');
sortKey = filter.data('sort');
sortOrder = filter.data('order');
list.children()
.sort(sortFn)
.appendTo(list);
});
};
// sticky footer
// -------------
$(window)
.scroll(function() {
if ('#footertest.sticky-footer') {
$('#footertest.sticky-footer')
.css('display', 'block');
$('#footertest.sticky-footer')
.css('position', 'fixed');
$('#footertest.sticky-footer')
.css('bottom', '0');
if ($(window)
.scrollTop() + $(window)
.height() == $(document)
.height()) {
//$('#footertest.sticky-footer').css('position', 'relative');
$('#footertest.sticky-footer')
.css('display', 'none');
}
}
});
// carousels
// ---------
isb.carousels = function() {
// Frontpage carousel
$('.carousel-frontpage.slide')
.carousel({
interval: 15000
});
$('.carousel-ferli.slide')
.carousel({
interval: 999999999
});
$('.carousel-ferli.slid')
.carousel({
interval: false,
pause: true
});
// video list scrolling (responsive)
$('ul.inline.tv')
.each(function() {
var carousel = $(this);
carousel.carouFredSel({
width: '100%',
height: 'variable',
responsive: 'true',
padding: null,
auto: false,
circular: false,
scroll: {
fx: 'crossfade',
easing: 'linear',
duration: 110
},
items: {
width: '300',
visible: {
min: 5,
max: 5
}
},
}, {
transition: true
}
);
carousel.parent()
.parent()
.find('.prev, .next')
.on('click', function() {
carousel.trigger($(this)
.hasClass('prev') ? 'prevPage' : 'nextPage');
return false;
});
});
$('ul.inline.tv.vimeo')
.each(function() {
var carousel = $(this);
carousel.carouFredSel({
width: '100%',
height: 'variable',
responsive: 'true',
padding: null,
auto: false,
circular: false,
scroll: {
fx: 'crossfade',
easing: 'linear',
duration: 110
},
items: {
height: '200',
width: 'auto',
visible: {
min: 5,
max: 5
}
},
}, {
transition: true
}
);
});
$('.featured-tv-carousel')
.each(function() {
var carousel = $(this);
carousel.carouFredSel({
width: '100%',
height: 'variable',
responsive: true,
auto: false,
scroll: {
fx: 'crossfade',
easing: 'linear',
duration: 300,
},
items: {
width: '1100',
visible: {
min: 1,
max: 5
}
}
}, {
transition: true,
});
carousel.parent()
.parent()
.find('.prev, .next')
.on('click', function() {
carousel.trigger($(this)
.hasClass('prev') ? 'prevPage' : 'nextPage');
return false;
});
});
// loop through found carousels
$('.carousel')
.each(function() {
// setup carousel config
var carousel = $(this),
inner = carousel.find('.carousel-inner'),
config = {};
// frontpage fullscreen carousel
if ($(this)
.hasClass('carousel-frontpage')) {
// setup config
config = {
responsive: true,
scroll: {
fx: 'crossfade',
duration: 125,
},
auto: false,
items: {
visible: 1,
height: 'variable'
},
width: '100%',
};
// activate next/prev controls
carousel.find('.carousel-control.left, .carousel-control.right')
.on('click', function() {
inner.trigger('play');
inner.trigger($(this)
.hasClass('.left') ? 'prevPage' : 'nextPage');
return false;
});
}
if ($(this)
.hasClass('carousel-appsida')) {
// setup config
config = {
responsive: true,
scroll: {
fx: 'crossfade',
duration: 125,
},
auto: false,
items: {
visible: 1,
height: 'variable'
},
width: '100%',
};
// activate next/prev controls
carousel.find('.carousel-control.left, .carousel-control.right')
.on('click', function() {
inner.trigger('play');
inner.trigger($(this)
.hasClass('.left') ? 'prevPage' : 'nextPage');
return false;
});
}
if ($(this)
.hasClass('carousel-ferli')) {
// setup config
config = {
responsive: true,
interval: false,
scroll: {
fx: 'crossfade',
duration: 125,
},
auto: {
play: false,
delay: 100000000000
},
//auto: false,
items: {
visible: 1,
height: 'variable'
},
width: '100%',
pause: true,
};
}
if ($(this)
.hasClass('carousel-ferli2')) {
// setup config
config = {
responsive: true,
scroll: {
fx: 'crossfade',
duration: 125,
},
auto: {
play: false
},
//auto: false,
items: {
visible: 1,
height: 'variable'
},
width: '100%',
};
}
// subfrontpage carousels
if ($(this)
.hasClass('well-banner-carousel')) {
// setup config
config = {
responsive: true,
height: 'variable',
scroll: {
fx: 'crossfade',
duration: 400,
onBefore: function(data) {
inner.trigger("currentPosition", function(pos) {
carousel.find('.bullets li')
.removeClass('active')
.eq(pos)
.addClass('active');
});
}
},
auto: {
play: true,
delay: 1000000,
timeoutDuration: 1000000,
pauseOnEvent: true
},
items: {
visible: 1,
height: 'variable'
}
};
// activate next/prev controls
carousel.find('.arrow-left, .arrow-right')
.on('click', function() {
inner.trigger('play');
inner.trigger($(this)
.hasClass('arrow-left') ? 'prevPage' : 'nextPage');
return false;
});
carousel.find('.bullets a')
.on('click', function() {
inner.trigger('slideTo', $(this)
.parent()
.index());
});
}
if ($(this)
.hasClass('carousel-gallery')) {
config = {
responsive: true,
auto: {
play: false,
delay: 1000
},
items: {
visible: {
min: 1,
max: 10
}
},
prev: '.prev',
next: '.next'
};
}
// attach to caroufredsel
inner.carouFredSel(config);
});
};
// Subpagebanner w/video
// ---------------------
isb.videoBanners = function() {
function onPause(id) {
hide();
}
function onFinish(id) {
hide();
}
function onPlayProgress(data, id) {}
function hide() {
$(".banner-wrapper")
.css("z-index", "11");
$('#vimeoPlayer')
.css({
"position": "absolute"
});
$('.subpage-banner')
.css({
"height": "500px"
});
$(".banner-wrapper")
.fadeIn("slow", function() {});
$(".panel-mobile")
.hide();
}
var iframe = $('#vimeoPlayer')[0];
var player = iframe ? $f(iframe) : '';
// When the player is ready, add listeners for pause, finish, and playProgress
if (player) {
player.addEvent('ready', function() {
player.addEvent('pause', onPause);
player.addEvent('finish', onFinish);
player.addEvent('playProgress', onPlayProgress);
});
}
$(".image-container .player")
.click(function() {
$(".banner-wrapper")
.fadeOut("slow", function() {
$(this)
.css("z-index", "-1");
$('#vimeoPlayer')
.css({
"position": "relative",
"display": "block",
"float": "left"
});
$('.subpage-banner')
.css({
"height": "auto"
});
$('.panel-mobile')
.fadeIn("slow", function() {})
.css({
"position": "relative",
"display": "block",
"float": "left"
});
player.api("play");
});
});
};
// currency converter
// ------------------
isb.currencies = function() {
$('.iskinput')
.focusout(function() {
$('.iskinput')
.mask('000.000.000.000.000', {
reverse: true
});
})
.focus(function() {
$('.iskinput')
.unmask();
});
//GetDateofRender
var date = new Date();
$('#currencydate')
.html(date.toLocaleString());
// loop through currency tables
$('.table-currency')
.each(function() {
// analytics - set table name
var tableName = $('.currency .tabs>li>a[href="#' + $(this)
.parents('.tab-pane')
.attr('id') + '"]')
.text();
// find all input fields
var inputs = $(this)
.find('input');
// find all input fields
inputs.on('keyup', function(e) {
if ((e.keyCode > 8 && e.keyCode < 46) || (e.keyCode > 57 && e.keyCode < 96)) {} else {
// collect parameters
var that = $(this),
base = parseFloat((that.val() + '')
.replace(/\,/g, '.')),
val = isNaN(base) ? 0 : base,
tr = that.parent('td')
.parent('tr'),
type = tr.data('currency'),
sale = parseFloat((tr.data('sale') + '')
.replace(/\,/g, '.'));
// loop through inputs
inputs.not(that[0])
.each(function(i, item) {
// get table row
var row = $(this)
.parent('td')
.parent('tr'),
calc = (val * sale) / parseFloat((row.data('sale') + '')
.replace(/\,/g, '.')),
ts = new RegExp('(-?[0-9]+)([0-9]{3})'),
calcFixed = (calc.toFixed(2) + '')
.replace(/\./g, ',');
while (ts.test(calcFixed))
calcFixed = (calcFixed + '')
.replace(ts, '$1.$2');
// set value
$(this)
.val(calcFixed);
});
}
// disable visuality of characters with keypress
})
.on('keypress', function(e) {
ga('send', 'event', 'Gjaldmiðlar', 'Reikna', $(e.target)
.attr('name'));
if (function(input) {
if (typeof input.selectionStart == "number") {
return input.selectionStart === 0 && input.selectionEnd == input.value.length;
} else if (typeof document.selection != "undefined") {
input.focus();
return document.selection.createRange()
.text == input.value;
}
}(this)) $(this)
.val('');
$(this)
.val($(this)
.val()
.replace(/\./, ''));
// get requested char code
var key = e.which ? e.which : e.keyCode,
val = $(this)
.val();
// only one comma
if ((val.indexOf(',') > 0 && key === 44) || (key !== 44 && (key > 31 && (key < 48 || key > 57)))) {
return false;
}
return true;
})
.on('focus', function(e) {
$(this)
.select();
$(this)
.attr('data-amount-before', $(this)
.val());
})
.on('mouseup', function(e) {
e.preventDefault();
})
.on('focusout', function(e) {
if ($(this)
.val() !== $(this)
.attr('data-amount-before')) {
console.log('amount changed');
}
})
// trigger key up on first element
.eq(0)
.trigger('keyup');
});
};
isb.ToggleBrowserWarning = function() {
var ua = navigator.userAgent.toLowerCase();
if (ua.indexOf("windows nt 5.1") != -1) {
$("#browserwarning")
.delay(500)
.slideDown(2000);
$("#browserwarningclose")
.click(function() {
$("#browserwarning")
.delay(200)
.slideUp(2000);
});
$("#browserwarningclose")
.hover(function() {
$(this)
.css('color', '#898989');
}, function() {
$(this)
.css('color', 'White');
});
}
};
// card compare
// ------------
isb.cardCompare = function() {
// build parameters
var compare = $(this),
cards = [];
// populate cards from first list
compare.find('select[name=compare_a_card] option')
.each(function() {
// push to cards array
cards.push({
name: $(this)
.text(),
value: $(this)
.val(),
type: $(this)
.data('type')
});
});
// attach change event handler
compare.find('input[name=compare_a_type], input[name=compare_b_type]')
.on('change', function() {
// get selected type
var type = compare.find('input[name=' + $(this)
.attr('name') + ']:checked')
.val();
// find its select box
compare.find('select[name=' + ($(this)
.attr('name'))
.replace('_type', '_card') + ']')
.each(function() {
// remove all options
$(this)
.find('option')
.remove();
// loop through cards
for (var x = 0; x < cards.length; x++) {
// if card type matches
if (cards[x].type === type) {
// append to select options list
$(this)
.append($('<option/>', {
value: cards[x].value,
text: cards[x].name
}));
}
}
// trigger change on select
$(this)
.trigger('change');
})
// attach change event
.on('change', function() {
// get select box side
var side = '.card-' + $(this)
.attr('name')
.replace('compare_', '')
.replace('_card', '');
// show and hide
compare.find(side)
.find('.card-display')
.addClass('hidden');
compare.find(side)
.find('.card-display.card-' + $(this)
.val())
.removeClass('hidden');
});
})
// trigger change event onload
.trigger('change');
$('input[name=compare_a_type]')
.change();
$('input[name=compare_b_type]')
.change();
var compDef = 'c7a534f4-e9ec-11e5-bb50-b56a16f11c73';
var persDef = '277204e0-a224-11e4-8452-005056b00087';
var currDef = '';
if ($('option[value="c7a534f4-e9ec-11e5-bb50-b56a16f11c73"]')
.length) {
currDef = compDef;
} else {
currDef = persDef;
}
$('select[name=compare_b_card]')
.val(currDef)
.change();
};
// house mortage calculator
// ------------------------
isb.calculatorMortgage = function() {
// scope (used internaly)
var calc = $(this);
// calculate results
// -----------------
calc.result = function(items) {
Handlebars.registerHelper('titlevalue', function(key) {
if (key === 'selectedAverage') {
}
})
// register calcSum helper
Handlebars.registerHelper('gettitle', function() {
return items.result[0].VerdbolguTexti;
});
Handlebars.registerHelper('calcSum', function(key, where) {
// setup variables
var suffix = ' kr.',
intr = items.interests,
ret = key;
// nothing for third field
if ((key === 'ArlegHlutfallstalaKostnadar' || key === 'FjoldiGjalddaga' || key === 'ManudirMilliGjalddaga') && where === 'ab') {
return '';
}
// set months between payments
if (key === 'ManudirMilliGjalddaga') {
return '1';
}
if (key === 'Indexation') {
if (items.result[0].Verdbolga === 0) {
return null;
}
}
// get interests
if (key === 'Interests') {
ret = (where === 'a' ? intr[0] : (where === 'b' ? intr[1] : intr[2]));
}
// process bill cost
else if (key === 'BillCost') {
ret = $('input[name=billcost]')
.val();
if (where === 'ab') ret = ret * 2;
}
// process total cost
else if (key === 'HeildarUpphaed') {
var a = parseInt(items.result[0].HeildarLantokukostnadur, 0) + parseInt(items.result[0].UtborgudFjarhaed, 0);
var b = parseInt(items.result[1].HeildarLantokukostnadur, 0) + parseInt(items.result[1].UtborgudFjarhaed, 0);
if (where === 'a') ret = a;
if (where === 'b') ret = b;
if (where === 'ab') ret = a + b;
}
//average payments
else if (key === 'MedalgreidslaLans') {
var a = parseInt(items.result[0].MedalgreidslaLans, 0);
var b = parseInt(items.result[1].MedalgreidslaLans, 0);
//var c = parseInt(items.result[0].TotalAveragePayment,0);
if (where === 'a') ret = a;
if (where === 'b') ret = b;
if (where === 'ab') ret = a + b;
}
// other fields
else if (where === 'a') ret = items.result[0][key];
else if (where === 'b') ret = items.result[1][key];
else if (where === 'ab') ret = parseFloat(items.result[0][key], 0) + parseFloat(items.result[1][key], 0);
// no suffix for payments per year
if (key === 'FjoldiGjalddaga') {
suffix = '';
}
// set correct suffix for percentage
if (key === 'Interests' || key === 'ArlegHlutfallstalaKostnadar' || key == 'Indexation') {
suffix = '%';
ret = (ret + '')
.replace(/,/g, '.');
ret = parseFloat(ret)
.toFixed(2);
}
// process money fields
else {
ret = isb.tools.number_format(ret, 0, '', '.');
}
return ret + '' + suffix;
});
// get result template
var source = $('#mortgageResult')
.html();
// compile template
var template = Handlebars.compile(source);
// setup storage for handlebars
var storage = {
loan1: {
interest: (parseFloat((items.interests[0])
.replace(',', '.'))
.toFixed(2) + '')
.replace('.', ',')
},
loan2: {
interest: (parseFloat((items.interests[1])
.replace(',', '.'))
.toFixed(2) + '')
.replace('.', ',')
},
result: [{
key: 'Hofudstoll',
value: 'Höfuðstóll'
},
{
key: 'UtborgudFjarhaed',
value: 'Útborguð fjárhæð',
bold: true
},
{
key: 'Lantokugjald',
value: 'Lántökugjald'
},
{
key: 'Stimpilgjald',
value: 'Stimpilgjald'
},
{
key: 'ThinglysingargjaldBreytilegt',
value: 'Þinglýsingargjald'
},
{
key: 'Afgreidslugjald',
value: 'Útbúið skuldabréf'
},
{
key: 'Greidslumat',
value: 'Greiðslumat'
},
{
key: 'VedbandaYfirlit',
value: 'Veðbandayfirlit'
},
{
key: 'LanaYfirlit',
value: 'Lánayfirlit'
},
{
key: 'Interests',
value: 'Nafnvextir'
},
{
key: 'Indexation',
value: 'Verðbólga',
indexation: true,
val: 'Verðbólga',
ShowIndex: isb.showIndex(items)
},
{
key: 'BillCost',
value: 'Tilkynningar- og greiðslugjald'
},
{
key: 'HeildarLantokukostnadur',
value: 'Heildarlántökukostnaður'
},
{
key: 'HeildarUpphaed',
value: 'Heildarupphæð til greiðslu',
bold: true
},
{
key: 'MedalgreidslaLans',
value: 'Meðalgreiðsla',
bold: true
},
{
key: 'ArlegHlutfallstalaKostnadar',
value: 'Árleg hlutfallstala kostnaðar'
},
{
key: 'FjoldiGjalddaga',
value: 'Fjöldi afborgana'
},
{
key: 'ManudirMilliGjalddaga',
value: 'Mánuðir milli gjalddaga'
}
]
};
// set some handlebars with storage
$('#mortgageResultContainer')
.html(template(storage))
// add click handler to payments btn
.on('click', '.btn-payments', function() {
// calc payments
calc.payments(items, $(this)
.parents('td')
.index() - 1);
return false;
})
// toggle indexation for loan b
.on('change', '.loantypeb', function() {
calc.find('.tab-pane.active input[name=loantypeb]')
.val($(this)
.find('option:selected')
.data('type'));
if ($(this)
.find('option:selected')
.data('type') === 'Insured') {
$('.indexationbValue')
.hide();
calc.find('.tab-pane.active form')
.trigger('submit');
} else {
$('.indexationbValue')
.show();
calc.find('.tab-pane.active form')
.trigger('submit');
}
})
// submit form on blur
.on('blur', '.indexationb', function() {
calc.find('.costForm input[name=indexationb]')
.val($(this)
.find('input')
.val());
calc.find('.tab-pane.active form')
.trigger('submit');
});
// remove loan b
if (items.singleloan) {
$('#mortgageResultContainer')
.find('table.table')
.addClass('no-loanb');
} else if (items.result[0].Verdbolga != '0') {
$('#indexationTitle')
.html(items.result[0].VerdbolguTexti);
$('#indexationaValue')
.html(((items.result[0].Verdbolga * 100)
.toFixed(2) + '')
.replace('.', ',') + '%');
$('#indexationbValue')
.html(((items.result[0].Verdbolga * 100)
.toFixed(2) + '')
.replace('.', ',') + '%');
$('#indexationallValue')
.html(((items.result[0].Verdbolga * 100)
.toFixed(2) + '')
.replace('.', ',') + '%');
}
isb.form();
// parse loanb vaxtaprosenta to selected
$('#mortgageResultContainer select.loantypeb')
.select2('val', items.interests[1]);
};
// payment schedule
// ----------------
calc.payments = function(items, mortgage) {
// register displayRow helper
Handlebars.registerHelper('displayRow', function(number) {
if (number > 5 && number < (items.payments.rows[mortgage].length) - 6) return ' class=hidden';
return '';
});
var withIndex = items.payments.rows[mortgage][0][2] != '0';
// register showNumber helper
Handlebars.registerHelper('showNumber', function(number) {
number = (number + '')
.replace(/,/, '.');
return isb.tools.number_format(number, 0, ',', '.');
});
// get result template
var source = $('#mortgagePayments')
.html();
// compile template
var template = Handlebars.compile(source);
// load payment schedule with templates and etc.
var storage = {
items: items.payments.rows[mortgage],
withIndex: withIndex
};
// show more rows
var moreRow = $('<tr/>')
.append($('<td/>', {
colspan: withIndex === true ? 8 : 7,
'class': 'text-center'
})
.append($('<a/>', {
'href': '#',
'class': 'btn btn-link',
html: 'Sýna allar greiðslur'
})
.on('click', function() {
$(this)
.parents('tr')
.parent()
.find('tr.hidden')
.removeClass('hidden');
$(this)
.parents('tr')
.remove();
return false;
})));
$('#mortgagePaymentsContainer')
.html(template(storage))
.find('tr:eq(5)')
.after(moreRow);
$('html, body')
.stop()
.animate({
scrollTop: $('#mortgagePaymentsContainer')
.offset()
.top - 75
}, 750);
};
// attach submit event handler to forms
calc.find('form')
.on('submit', function() {
calc.addClass('loading');
// build ajax request
var request = $.ajax({
url: $(this)
.attr('action'),
data: calc.find('.tab-pane.active form')
.serialize() + '&' + calc.find('#costCollapse form')
.serialize(),
dataType: 'json'
});
// always hide loading
request.always(function() {
calc.removeClass('loading');
})
// successful response
request.done(function(response) {
// empty results
$('#mortgageResultContainer, #mortgagePaymentsContainer')
.empty();
// empty alerts
calc.children('.alert')
.remove();
// result
if (response.status === 'success') {
calc.result(response.message);
// scroll down to mortgageResultContainer
$('html, body')
.stop()
.animate({
scrollTop: $('#mortgageResultContainer')
.offset()
.top - 75
}, 750);
} else {
calc.prepend(isb.alert('Villa kom upp!', response.message[0].message, 'alert-warning'));
}
});
// did not complete
request.fail(function(xhr, textStatus, errorThrown) {
isb.alert('Villa kom upp!', errorThrown, 'alert-warning');
});
return false;
});
};
// employee search controller
// ----------------------
isb.searchEmployee = function() {
var search = $(this);
// attach submit handler to form
search.on('submit', function() {
// call api
$.getJSON('/api/employees?q=' + search.find('input[type = search]')
.val(),
function(request) {
// clear output
$('#searchEmployeeResultOutput')
.empty();
// get handlebars template
var source = $('#searchEmployeeResult')
.html(),
template = Handlebars.compile(source),
storage = {
error: request.status === 'error',
items: request.response,
empty: request.response.length === 0,
pager: request.response.length > 10 ? true : false
};
// Add pager
$('#searchEmployeeResultOutput')
.html(template(storage))
.find('table.table-sortable')
.bind('pagerChange pagerInitialized', function(table, pager) {
var next = pager.container.children('.next'),
curr = pager.page,
max = pager.filteredPages,
renderItems = function(from, to) {
for (var i = from; i <= to; i++) {
var li = $('<li/>')
.addClass('p');
if ((curr + 1) === i) li.addClass('active');
next.before(li.append($('<a/>', {
href: '#',
text: i
})));
}
};
pager.container.find('.p')
.remove();
if (max < 13) renderItems(1, max);
else if (curr < 9) renderItems(1, 10);
else if (curr > max - 8) renderItems(max - 9, max);
else renderItems(curr - 3, curr + 5);
pager.container.find('.p a')
.on('click', function() {
$('#searchEmployeeResultOutput table.table-sortable')
.trigger('pageSet.pager', parseInt($(this)
.text(), 0));
});
})
.tablesorter({
cssAsc: 'table-sort-asc',
cssDesc: 'table-sort-desc',
cssHeader: 'table-sort-header'
})
.tablesorterPager({
container: $('.pager'),
cssPrev: '.pagerPrev',
cssNext: '.pagerNext'
});
});
return false;
});
};
// process google maps
// ---------------------
isb.map = function() {
// loop through all maps
$('.google-map')
.each(function() {
var _this = this,
lastOpen = null;
// base map options
this.options = {
zoom: 6,
center: new google.maps.LatLng(64.661517, -18.874512),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
if ($(this)
.data('hide-controls')) {
this.options.disableDefaultUI = true;
}
this.bounds = new google.maps.LatLngBounds();
// map constructor
this.map = new google.maps.Map(this, this.options);
if ($(this)
.data('getlocation') && navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
var pos = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
_this.map.panTo(pos);
_this.map.setZoom(12);
var yourlocation = new google.maps.Marker({
position: pos,
map: _this.map,
title: 'Þú ert hér'
});
});
}
// bind table with markers
if ($(this)
.data('bind-table')) {
var bindView = $(this)
.data('bind-view');
$($(this)
.data('bind-table'))
.find('tr[data-lat][data-lng]')
.each(function(i, item) {
var __this = this;
if ($(__this)
.find('.infowindow')
.length === 1) {
this.infowindow = new google.maps.InfoWindow({
content: $(__this)
.find('.infowindow')
.html()
});
}
__this.marker = new google.maps.Marker({
position: new google.maps.LatLng($(__this)
.data('lat'), $(__this)
.data('lng')),
map: _this.map,
icon: $(__this)
.data('icon'),
title: $(__this)
.data('title'),
animation: google.maps.Animation.DROP
});
_this.bounds.extend(__this.marker.position);
google.maps.event.addListener(__this.marker, 'click', function() {
if (bindView) {
$(bindView)
.html($(__this)
.find('.view')
.html());
}
if ($(__this)
.find('.infowindow')
.length === 0) return;
if (lastOpen) lastOpen.infowindow.close();
if (lastOpen === __this) return;
__this.infowindow.open(_this.map, __this.marker);
lastOpen = __this;
});
})
.on('mouseover', function() {
this.marker.setAnimation(google.maps.Animation.BOUNCE);
})
.on('mouseout', function() {
this.marker.setAnimation(null);
})
.on('click', function() {
google.maps.event.trigger(this.marker, 'click');
$('html, body')
.stop()
.animate({
scrollTop: $(_this)
.offset()
.top - 100
}, 330);
});
_this.map.fitBounds(_this.bounds);
var listener = google.maps.event.addListener(_this.map, 'idle', function() {
if (_this.map.getZoom() > 17) _this.map.setZoom(17);
google.maps.event.removeListener(listener);
});
}
});
};
// google maps initializer
// ----------------------
isb.maps = (function() {
// check for map containers in body
if ($('.google-map')
.length === 0)
return;
// load google maps library on-demand
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "https://maps.googleapis.com/maps/api/js?sensor=false&callback=map";
document.body.appendChild(script);
}());
// offers stacking with masonry
// ----------------------
isb.offersList = function() {
var that = $(this),
els = that.find('.item.span4');
that.imagesLoaded(function() {
that.masonry({
columnWidth: '.grid-sizer',
gutter: 10,
itemSelector: '.item'
});
});
$('.offer-filter > a')
.on('click', function() {
$('.offer-filter > a')
.removeClass('active')
.filter(this)
.addClass('active');
els.show();
that.masonry('layout');
var sel = $(this)
.data('id');
if (sel === '') els.show();
else els.hide()
.filter('[data-categories~=' + sel + ']')
.show();
that.masonry('layout');
return false;
});
};
// window resize function (call it if needed)
// ----------------------
isb.resize = function() {
$('.well.well-aside')
.each(function() {
var wac = $('.well-aside-content')[0] || $('<div/>', {
'class': 'span3 pull-right well-aside-content hidden-phone'
})
.prependTo($('.content'))[0];
$(wac)
.css({
height: $(this)
.height()
});
});
};
// fix lisa area dom changes
// -------------------------
isb.lisa = function() {
$('.LisaArea')
.on('click', '.tabcontrol a', function() {
isb.tabs();
$(this)
.tab('show');
});
};
// islandsbanki js tools (phpjs)
// ---------------------
isb.tools = {
number_format: function(number, decimals, dec_point, thousands_sep) {
number = (number + '')
.replace(/[^0-9+\-Ee.]/g, '');
var n = !isFinite(+number) ? 0 : +number,
prec = !isFinite(+decimals) ? 0 : Math.abs(decimals),
sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,
dec = (typeof dec_point === 'undefined') ? '.' : dec_point,
s = '',
toFixedFix = function(n, prec) {
var k = Math.pow(10, prec);
return '' + Math.round(n * k) / k;
};
s = (prec ? toFixedFix(n, prec) : '' + Math.round(n))
.split('.');
if (s[0].length > 3) {
s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep);
}
if ((s[1] || '')
.length < prec) {
s[1] = s[1] || '';
s[1] += new Array(prec - s[1].length + 1)
.join('0');
}
return s.join(dec);
}
};
isb.toggleCurrency = (function(toggle) {
if (toggle == 'loading') {
$('#currencytable')
.hide();
$('#loader')
.show();
} else {
$('#loader')
.hide();
$('#currencytable')
.fadeIn();
}
});
isb.showIndex = function(items) {
if ($.trim(items.result[0].Verdbolga) === '0' || items.result[0].Verdbolga === undefined) {
return false;
} else {
return true;
}
};
isb.AttachLightbox = function() {
$('.lightbox')
.lightBox({
overlayBgColor: '#000000',
overlayOpacity: 0.6,
imageLoading: '/library/Template/Lightbox/lightbox-ico-loading.gif',
imageBtnClose: '/library/Template/Lightbox/x_close_red.png',
imageBtnPrev: '/library/Template/Lightbox/prev_active.png',
imageBtnNext: '/library/Template/Lightbox/next_active.png',
txtImage: 'Mynd',
txtOf: 'af'
});
$('.lightbox.en')
.lightBox({
overlayBgColor: '#000000',
overlayOpacity: 0.6,
imageLoading: '/library/Template/Lightbox/lightbox-ico-loading.gif',
imageBtnClose: '/library/Template/Lightbox/x_close_red.png',
imageBtnPrev: '/library/Template/Lightbox/prev_active.png',
imageBtnNext: '/library/Template/Lightbox/next_active.png',
txtImage: 'Image',
txtOf: 'of'
});
};
isb.ListObjectValidation = function() {
$('input')
.keydown(function(e) {
//e = e || window.event;
//console.log('char' + e.charCode + ' key' + e.keyCode + ' fromstring : ' + String.fromCharCode(e.keyCode));
var charCode = e.charCode || e.keyCode;
var classname = e.target.className.split(" ")[0];
//If string textbox
if (classname === 'stringinput') {
if (charCode > 7 && charCode < 106) {} else {
e.preventDefault();
}
//If Integer textbox
} else if (classname === 'intinput') {
if ((charCode > 7 && charCode < 65) || (charCode > 93 && charCode < 106)) {} else {
e.preventDefault();
}
//If float textbox
} else if (classname === 'floatinput') {
if ((charCode > 7 && charCode < 65) || (charCode > 93 && charCode < 106) || (charCode === 190)) {} else {
e.preventDefault();
}
//if email textbox
} else if (classname === 'emailinput') {
if ((charCode > 7 && charCode < 106) || (charCode == 190)) {} else {
e.preventDefault();
}
}
});
}
isb.UseMaps = function() {
$('img[usemap]')
.rwdImageMaps();
};
isb.QuestionsAndAnswers = function() {
$('.expandcollapse')
.on('click', function() {
if ($(this)
.hasClass('expand')) {
if ($(this)
.hasClass('english')) {
$(this)
.removeClass('expand')
.html('<i class="ico-collapse"></i>Close all');
} else {
$(this)
.removeClass('expand')
.html('<i class="ico-collapse"></i>Loka öllu');
}
$('.accordion .collapse')
.each(function() {
$(this)
.collapse('show');
});
} else {
if ($(this)
.hasClass('english')) {
$(this)
.addClass('expand')
.html('<i class="ico-expand"></i>Open all');
} else {
$(this)
.addClass('expand')
.html('<i class="ico-expand"></i>Opna allt');
}
$('.accordion .collapse')
.each(function() {
$(this)
.collapse('hide');
});
}
});
// Q and A Search form
$('.accordion form')
.submit(function() {
var searchTerm = $(this)
.find('input[type="text"]')
.val();
if (searchTerm !== '') {
// Initialize: Hide all Q and A's
$(this)
.parent()
.find('.collapse')
.each(function() {
if ($(this)
.hasClass('in')) {
$(this)
.collapse('hide');
}
});
// Case sensitive workaround
jQuery.expr[':'].icontains = function(a, i, m) {
return jQuery(a)
.text()
.toUpperCase()
.indexOf(m[3].toUpperCase()) >= 0;
};
var foundin = $('.accordion-group:icontains(' + searchTerm + ')');
if (foundin.length >= 1) {
$(foundin)
.each(function() {
$(this)
.find('.collapse')
.collapse('toggle');
});
$(this)
.find('.no-match')
.hide();
} else {
$(this)
.find('.no-match')
.show()
.find('span')
.text('"' + searchTerm + '"');
}
return false;
}
});
};
isb.BootstrapTabsExt = function() {
$('area[data-toggle="tab"]')
.click(function(e) {
var target = this.href.split('#');
$('.nav a')
.filter('a[href="#' + target[1] + '"]')
.tab('show');
});
isb.JPages = function() {
$('.news-container')
.jPages({
containerID: "newsitems",
first: false,
last: false,
previous: "",
next: "",
perPage: 8
});
},
isb.HousingLoanCalculator = function() {
// Functions taken from previous lib file included in DefaultTemplate
// Rrequired for caluclator to work
function SetInputFilter(filter, type) {
if (type === 'onlynumbers') {
$(filter)
.keypress(function(evt) {
var charCode = (evt.which) ? evt.which : evt.keyCode;
if ($(this)
.val()
.indexOf(',') > 0 && charCode === 44) {
return false;
}
if (charCode !== 44 && (charCode > 31 && (charCode < 48 || charCode > 57))) {
return false;
}
});
} else if (type === 'numncomm') {
$(filter)
.keypress(function(evt) {
var charCode = (evt.which) ? evt.which : evt.keyCode;
if (charCode !== 44 && (charCode > 31 && (charCode < 48 || charCode > 57))) {
return false;
}
});
}
}
},
isb.FundsToggles = function() {
srcPlus = '/library/Template/Buttons/plus_hover.png';
srcMinus = '/library/Template/Buttons/minus_hover.png';
$('.togglebutton')
.click(function() {
var toggleElement = $(this)
.data('toggle');
if ($(toggleElement)
.is(':visible')) {
$(toggleElement)
.hide();
$(this)
.attr('src', srcPlus);
} else {
$(toggleElement)
.show();
$(this)
.attr('src', srcMinus);
}
})
},
$('a[data-toggle="tab"]')
.click(function(e) {
var target = this.href.split('#');
$('.nav a')
.filter('a[href="#' + target[1] + '"]')
.tab('show');
});
};
// initializer
// -----------
isb.initialize = (function() {
// global methods
isb.tabs();
isb.sparnadurTabs();
isb.currencies();
isb.carousels();
isb.videoBanners();
isb.lisa();
isb.form();
isb.resize();
isb.AttachLightbox();
isb.BootstrapTabsExt();
isb.UseMaps();
isb.QuestionsAndAnswers();
isb.JPages();
isb.HousingLoanCalculator();
// isb.ListObjectValidation();
isb.FundsToggles();
isb.ToggleBrowserWarning();
// item filters
$('.itemFilter')
.each(isb.itemFilter);
// trigger resize
$(window)
.trigger('resize');
// just to make sure
setTimeout(function() {
$('.carousel-inner')
.trigger('updateSizes');
}, 330);
// page specific
// reload form controls
$('.mortgage-calculator')
.each(isb.calculatorMortgage);
$('.card-compare')
.each(isb.cardCompare);
$('#searchEmployee')
.each(isb.searchEmployee);
$('#offersList')
.each(isb.offersList);
// fix content height when sidebar
$('.page.with-sidebar')
.css({
minHeight: $('.sidebar > ul')
.height() + 25
});
}());
};
// document ready method
$(document)
.on('ready', Islandsbanki);
// window resize method
$(window)
.on('resize', Islandsbanki.resize);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment