$('#listLeft ul li a').live("click", function() {
if ($(this).hasClass("listLeftSelected")) {
return false;
}
$('.listLeftSelected').removeClass("listLeftSelected");
$(this).addClass('listLeftSelected');
var objId = $(this).attr("data-id");
var tab = $('.innerSelected').attr("data-slug");
var formData = getSearchFormJSON();
formData.object_id = objId;
var urlString = JSONtoQueryString(formData);
History.pushState(formData, "", urlString);
$.getJSON("/m/get_details", {
'tab': tab,
'object_id': objId
}, function(data) {
$('#imageInside').css({'backgroundImage': 'url(' + data.main_image.thumb + ')'});
$('#textRight').text(data.title).formatTitle();
var searchTerm = $('.searchListField').val();
var html = data.html;
if (searchTerm != '') {
html = highlightWordsNoCase(html, searchTerm);
// html = html.replace(searchTerm, "" + searchTerm + "");
}
$('#bottomRight').html(html);
// console.log(data);
});
return false;
});
$('.thumbsDetails').live("click", function(e) {
// alert($(this).attr("data-bigimage"));
var bigImage = $(this).attr("data-bigimage");
var $img = $('').attr("src", bigImage);
$('#lightbox, #lightboxPanel').fadeIn(400);
$('#lightboxPanel').empty().append($img);
});
$('.toggleNext').live("click", function(e) {
e.preventDefault();
var $next = $(this).next();
if (!$next.is(":visible")) {
$next.slideDown();
} else {
$next.slideUp();
}
});
function highlightWordsNoCase(data, word)
{
var regex = new RegExp("(" + word + ")", "gi");
return data.replace(regex, "$1");
}
/* Get a jquery ').val(s.operator + s.field_name).text(s.friendly_name);
}
/* Get a Jquery List Row object for an item - requires item.id and item.title*/
function getLi(item) {
var titleLength = 30;
var $li = $('
').addClass("tabListItem");
var $a = $('').attr("href", '#').attr("data-id", item.id).appendTo($li);
// console.log(item.title.length);
var $span = $('').text(item.title).appendTo($a);
return $li;
}
$(function() {
$('#lightbox').click(function() {
$('#lightbox, #lightboxPanel').fadeOut(400);
});
/* search button toggle */
$('.searchInnerField').hide();
$('#searchInner').toggle(function() {
$('.searchInnerField').slideDown();
}, function() {
$('.searchInnerField').slideUp();
});
/* search button end */
// $('#listLeft ul li a').eq(0).click();
// alert("hi");
$('.tabCategory').click(function() {
var $this = $(this);
if ($this.hasClass('.innerSelected')) {
return false;
}
$('.innerSelected').removeClass("innerSelected");
$this.addClass("innerSelected");
$('.displayedTab').removeClass("displayedTab");
var tab = $this.attr("data-slug");
var tabId = $this.attr("data-id");
$('#tabText_' + tabId).addClass("displayedTab");
doListLoading();
$.getJSON("/m/get_tab", {
'tab': tab,
// 'page_no': 1
}, function(data) {
// $('#loadingList').hide();
// stopListLoading(data.page);
/* begin if for has_list, ideally make into separate render function */
if (data.has_list) {
/* handle sort options on list */
$select = $('#orderBySelect');
$select.empty();
var sorts = data.sorts;
if (sorts.length == 0) { $select.hide(); } else { $select.show(); }
for (var j=0; j>>var foo = {'var1': 'bar', 'var2': 'baz'}
>>> JSONtoQueryString(foo);
'?var1=bar&var2=baz'
*/
function JSONtoQueryString(obj) {
var s = "?";
for (var o in obj) {
if (obj.hasOwnProperty(o)) {
s += o + "=" + obj[o] + "&";
}
}
return s.substring(0, s.length - 1);
}
/*
>>>var foo = "/something/bla/?var1=bar&var2=baz";
>>>QueryStringToJSON(foo);
{'var1': 'bar', 'var2': 'baz'}
*/
function QueryStringToJSON(qstring) {
if (qstring.indexOf("?") == -1) {
return {};
}
var q = qstring.split("?")[1];
var args = {};
var vars = q.split('&');
// console.log(vars);
for (var i=0; i 0) {
$a.click();
} else {
$('#listLeft ul li a').eq(0).click();
}
}
}
function doListLoading() {
$('.tabListItem').remove();
$('#loadingList').show();
}
function stopListLoading(page) {
$('#currPageNo').text(page.page_no);
$('#totalPages').text(page.num_pages);
$('#loadingList').hide();
if (page.page_no == 1) {
$('#triangleUp').hide();
} else {
$('#triangleUp').show();
}
if (page.page_no == page.num_pages) {
$('#triangleDown').hide();
} else {
$('#triangleDown').show();
}
}
function goNextPage() {
var currPage = parseInt($('#currPageNo').text());
var totalPages = parseInt($('#totalPages').text());
if (currPage < totalPages) {
getPage(currPage + 1);
}
}
function goPreviousPage() {
var currPage = parseInt($('#currPageNo').text());
if (currPage > 1) {
getPage(currPage - 1);
}
}
function getPage(pageNo) {
$('#page_no').val(pageNo);
$('#listForm').submit();
/*
doListLoading();
$.getJSON("/m/get_list", {
'tab_id': $('.innerSelected').attr("data-id"),
'page': pageNo,
'sort': $('#orderBySelect').val()
}, function(page) {
stopListLoading(page);
displayList(page.items);
});
*/
}
function getNoListHtml(items) {
var $rhs = $('');
for (var i=0; i').addClass("noListItem");
var $title = $("").addClass("noListTitle").appendTo($ret);
var $a = $('').attr("href", item.url).addClass("orangeLink").text(item.text).appendTo($title);
var $text = $("").addClass("noListText").html(item.text).appendTo($ret);
} else {
var $ret = $('').addClass("noListItem").addClass("collapsible");
var $title = $("").addClass("orange").addClass("toggleNext").text(item.title).appendTo($ret);
var $text = $("").addClass("noListText").addClass("hidden").html(item.text).appendTo($ret);
}
return $ret;
}
function getSearchFormJSON() {
return {
'tab': $('.innerSelected').attr("data-slug"),
'sort': $('#orderBySelect').val() != '' ? $('#orderBySelect').val() : '',
'search': $('#searchList').val(),
'page': $('#page_no').val(),
'object_id': $('#object_id').val()
}
}
jQuery.fn.formatTitle = function() {
var txt = $(this).text();
var fontSize;
// alert(txt.length);
if (txt.length < 32) {
fontSize = 50;
} else if (txt.length < 60) {
fontSize = 40;
} else if (txt.length < 100) {
fontSize = 30;
} else {
fontSize = 20;
}
this.css({'fontSize': fontSize + "px"});
}
jQuery.fn.selectOption = function(value) {
var that = this;
var options = that.find('option');
options.each(function() {
if ($(this).attr("value") == value) {
$(this).attr("selected", "selected");
return;
}
});
}