2
* @fileoverview A base JS object containing site-wide methods
4
* @author Canonical Web Team: Steve Edwards
8
template_dir = '/wp-content/themes/ubuntu-developer';
12
$(document).ready(function() {
14
base.positionNavArrow();
16
base.readyStepLinks();
17
base.readyAccordion();
19
base.readySmoothScrolling();
25
// Set the current page ID
26
base.setPageId = function() {
27
page_id = base.getPageId();
30
// Position the arrow under the active nav item
31
base.positionNavArrow = function() {
32
var item = $('.header-navigation li[class*="current"]');
33
if (item.length !== 0) {
34
var item_width = item.width();
35
var item_pos = item.offset();
36
var arrow = $('.arrow-nav');
37
var arrow_width = arrow.width();
39
arrow.css('left', (item_pos.left + item_width / 2 - (arrow_width / 2)) + 'px');
40
arrow.css('display', 'block');
44
// Ready the search box
45
base.readySearch = function() {
48
// Clear and re-populate
49
$('#input-search').bind({
51
if ($(this).val() == text) {
53
$(this).css('font-style', 'normal');
54
$(this).css('color', '#333');
58
if ($(this).val() == '') {
60
$(this).css('font-style', 'italic');
61
$(this).css('color', '#ccc');
66
// Enter key submits form
67
$('#input-search').keypress(function(e) {
69
// Handle empty searches for WP
70
if ($(this).val() == '') {
73
$('#form-search').submit();
79
// Ensure step box items are clickable
80
base.readyStepLinks = function() {
81
if (page_id != 'home' && page_id != 'gomobile') return false;
83
$('.box-steps li').click(function(e) {
84
console.log('clicked');
85
if(page_id == 'home') {
86
window.location.href = $(this).find('a').attr('href');
88
$(this).find('a').trigger('click');
94
base.readyAccordion = function() {
95
$('.accordion').accordion({
96
active: base.getAccordionActiveElement(),
100
// Set the active link text
101
base.setAccordionActiveLinkText();
104
// Ensure FAQ questions are clickable
105
base.readyFAQs = function() {
106
$('.faqs dt').bind('click', function(e) {
107
var description = $(this).next('dd');
108
if (description.css('display') == 'none') {
109
description.fadeIn('slow');
116
// Applies 'smooth scrolling' to anchor tags
117
base.readySmoothScrolling = function() {
118
$('a').each(function(i) {
119
if($(this).attr('href').charAt(0) == '#'){
120
$(this).click(function() {
121
var elementClicked = $(this).attr("href");
122
var destination = $(elementClicked).offset().top;
123
$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, 1500 );
131
base.getTweets = function() {
133
// Latest tweet from @ubuntuappdev
135
username: 'ubuntuappdev',
136
template: '{text}{time}',
139
$('.tweet').tweet(args);
142
/* Non-init methods */
144
// Get the current page ID
145
base.getPageId = function() {
146
return $('body').attr('class');
149
// Get the active accordion element by parsing the URL
150
base.getAccordionActiveElement = function() {
152
var current_page_lookup = $('.accordion .current_page_item a');
153
if (current_page_lookup.length < 1) {
156
var url = $('.accordion .current_page_item a')[0].toString();
157
var strings = $('.accordion h3 a').map(function(i, elem) {
158
var lookup = elem.toString();
162
// Look for a channel filter and compare it to the accordion headings
163
$.each(strings, function(i, string) {
164
var pattern = new RegExp(string.replace(/\s+/g, '-').replace('+', 'p'), 'i');
165
if (url == string || url.match(pattern)) {
173
// Set the accordion active link text
174
base.setAccordionActiveLinkText = function() {
175
var active_link = $('.accordion .current_page_item a');
176
var link_text = active_link.text();
177
active_link.text(link_text + ' ›');