if (!window.console) console = {}; console.log = console.log || function(){}; console.warn = console.warn || function(){}; console.error = console.error || function(){}; console.info = console.info || function(){}; $.snippets = {"frame\/browse\/popup\/item":"\r\n {title}<\/a><\/span><\/td>\r\n {type}<\/span><\/td>\r\n {date}<\/span><\/td>\r\n<\/tr>","frame\/popups\/search\/item":"\r\n {title}<\/a><\/span><\/td>\r\n {type}<\/span><\/td>\r\n<\/tr>","frame\/popups\/collection\/item":"
  • \r\n
    \r\n <\/a>\r\n <\/a>\r\n <\/div>\r\n
    <\/div>\r\n <\/a>\r\n
    \"\"<\/a><\/div>\r\n {title}<\/strong>\r\n
    \r\n

    ...<\/p>\r\n <\/div>\r\n<\/li>"}; $.snippet = function(template, data) { var i; var value; for (i in data) { value = data[i]; if (!value) value = ''; template = template.split('{' + i + '}').join(value); } return template; } $.widget('ui.collection', { _create: function() { this.data = $.cookie('collection'); if (typeof this.data == 'string') this.data = JSON.parse(this.data); this.disabled = (parseInt($('body').attr('rel').length, 10) == 0); this.update(); }, update: function() { var html = ''; var count = 0; var value; for (var url in this.data) { value = this.data[url]; html += $.snippet($.snippets['frame/popups/collection/item'], { title: value.title, url: url, image: value.image }); count++; } this.element.find('.results ul:first').html(html); this.element.find('.results ul:first').sortable('destroy').sortable({ handle: '.button1, .button2', stop: $.delegate(this.order, this) }); this.element.find('.results ul:first > li .remove').bind('click', this, function(event) { event.data.remove($(this).closest('li').attr('rel')); }); this.element.find('.status span').html(count); $('#header .links .collect').toggleClass('disabled', (this.saved() || this.disabled)); $('#header .links .download').toggleClass('disabled', (!this.data || JSON.stringify(this.data).length == 2)); }, order: function() { var data = {}; var urls = []; var url; this.element.find('.results ul:first > li').each(function() { urls.push($(this).find('.image a').attr('href')); }); for (var i = 0; i < urls.length; i++) { url = urls[i]; data[url] = this.data[url]; } this.data = data; this.save(); }, remove: function(url) { delete this.data[url]; this.save(); this.update(); }, save: function() { $.cookie('collection', JSON.stringify(this.data), { domain: 'mcaslan.co.uk', path: '/' }); }, add: function() { if (!this.data) this.data = {}; var url = String(document.location); this.data[url] = { title: String(document.title), url: url.slice(String('http://www.mcaslan.co.uk/').length), image: $('body').attr('rel') }; this.save(); this.update(); }, saved: function() { if (!this.data) return false; return (this.data[String(document.location)] != null); } }); $.widget('ui.search', { _create: function() { this.preloader = this.element.find('.preloader'); this.filter = { type: this.element.find('.filter input[name=type\[\]]'), office: this.element.find('.filter input[name=office\[\]]'), location: this.element.find('.filter input[name=location\[\]]'), date: this.element.find('.filter input[name=date\[\]]'), order: this.element.find('.filter input[name=order]') }; for (var code in this.filter) { if (code == 'order') { this.filter[code].bind('change', $.delegate(this.update, this)); } else { this.filter[code].attr('checked', true).trigger('update').not(':first').bind('change', $.delegate(this.update, this)); this.filter[code].eq(0).bind('change', $.delegate(this.filterAll, this, code)); } } }, filterAll: function(code, event) { var $input = $(event.target); var checked = $input.is(':checked'); this.filter[code].not(':first').attr('checked', checked).trigger('update'); this.update(); }, init: function() { this.form = this.element.find('form'); this.form.validate('destroy').validate({ submit: $.delegate(this.submit, this) }); }, submit: function(valid) { if (!valid) return; this.preloader.show(); $.ajax({ type: 'POST', url: 'http://www.mcaslan.co.uk/popups/search', data: this.form.serialize(), dataType: 'json', success: $.delegate(this.submitComplete, this) }); }, submitComplete: function(data) { this.preloader.hide(); if (!data || isNaN(data.length)) return; this.data = data; this.update(); }, update: function() { if (!this.data) return; var value; var html = ''; var filter = {}; var valid = false; var data = []; var order; for (var code in this.filter) { filter[code] = []; this.filter[code].not(':first').filter(':checked').each(function() { filter[code].push($(this).val()); }); } for (var i = 0; i < this.data.length; i++) { value = this.data[i]; if (value) { valid = true; for (var code in filter) { if (value.filter[code]) { if ($.inArray(value.filter[code], filter[code]) == -1) valid = false; } } if (valid) { data.push(value); } } } switch (this.filter.order.filter(':checked').val()) { case 'type': order = function(a, b) { a = a.filter.type; b = b.filter.type; if (a < b) return -1; if (a > b) return 1; return 0; } break; case 'date': order = function(a, b) { a = new Date().setTime(parseInt(a.date, 10) * 1000); b = new Date().setTime(parseInt(b.date, 10) * 1000); return a - b; } break; default: order = function(a, b) { a = a.title.toLowerCase(); b = b.title.toLowerCase(); if (a < b) return -1; if (a > b) return 1; return 0; } } data.sort(order); for (var i = 0; i < data.length; i++) { value = data[i]; html += $.snippet($.snippets['frame/popups/search/item'], { 'class': (i % 2 == 0 ? " class=\"odd\"" : ""), title: value.title, type: value.filter.type, url: value.url, date: value.date_formatted }); } this.element.find('.results').toggleClass('hidden', (html.length == 0)); this.element.find('.results table').html(html).find('tr').click(function(event) { event.preventDefault(); document.location = $(this).find('a').attr('href'); }); } }); $.widget('ui.browse', { _create: function() { this.button = this.element.find('.expand:first'); this.button.click($.delegate(this.toggle, this, true)); this.popup = this.element.find('.popup:first'); this.visible = false; this.animate = (!$.browser.msie || $.browser.version > 7); this.popup.find('.close').unbind().click($.delegate(this.toggle, this, null)); this.popup.find('.overlay').click($.delegate(this.toggle, this, false)); this.checkboxes = this.popup.find('.filter input[type=checkbox]'); this.checkboxes.not(':first').attr('checked', false).trigger('change').bind('change', $.delegate(this.update, this)); this.checkboxes.eq(0).bind('change', $.delegate(this.filterAll, this)).attr('checked', false).trigger('update'); this.popup.show(); this.height = { popup: this.popup.height(), button: this.button.outerHeight() }; this.popup.hide(); this.popup.css('overflow', 'hidden').css('height', 0); }, load: function() { $.ajax({ type: 'POST', url: 'http://www.mcaslan.co.uk/browse', dataType: 'json', success: $.delegate(this.loadComplete, this) }); }, loadComplete: function(data) { this.options.data = data; this.element.find('.preloader').hide(); this.update(); }, filterAll: function(event) { var checked = $(event.target).is(':checked'); this.checkboxes.not(':first').attr('checked', checked).trigger('update'); this.update(); }, toggle: function(visible) { var height; var speed = 1000; if (visible == null) visible = !this.visible; if (visible == this.visible) return; this.visible = visible; height = (this.visible ? this.height.popup : this.height.button); this.popup.find('.overlay').toggleClass('hidden', !this.visible); this.popup.stop(true).animate({ height: height }, (this.animate ? speed : 0)); this.popup.find('.close').html((this.visible ? 'close' : 'browse all site')).toggleClass('expanded', !this.visible); if (!this.animate && !this.visible) this.popup.css('height', 0); if (!this.options.data) { this.load(); return; } }, resize: function() { var visible = this.popup.is(':visible'); if (!visible) return; this.popup.css('height', ''); this.height.popup = this.popup.height(); //this.element.css('height', this.height.popup); }, update: function() { if (!this.options.data) { this.element.find('.preloader').show(); this.resize(); return; } var results = []; var data = this.options.data; var items; var item var types = []; var date; var html = ''; var i = 0; this.checkboxes.not(':first').filter(':checked').each(function() { types.push($(this).val()); }); for (var type in data) { if ($.inArray(type, types) > -1) { items = data[type]; for (var j = 0; j < items.length; j++) { item = items[j]; if (parseInt(item.date, 10) > 0) { date = new Date(); date.setTime(parseInt(item.date, 10) * 1000); } else { date = null; } html += $.snippet($.snippets['frame/browse/popup/item'], { 'class': (i % 2 == 0 ? " class=\"odd\"" : ""), title: item.title, type: type, url: item.url, date: item.date_formatted, icon: (item.table == 'downloads' ? 'article' : '') }); i++; } } } this.popup.find('.results').toggleClass('hidden', (html.length == 0)); this.popup.find('.results table tbody').html(html).find('tr').click(function(event) { event.preventDefault(); document.location = $(this).find('a').attr('href'); }); if (!this.firstRun && html.length > 0) { this.firstRun = true; this.element.find('.results table').tablesorter({ textExtraction: function(node) { var value = node.childNodes[0].innerHTML; var check = $(node).find('span').attr('rel'); if (check) return check; return value; } }).bind('sortEnd', function() { $(this).find('tr').removeClass('odd').filter(':even').addClass('odd'); }); } if (html.length > 0) this.popup.find('.results table').trigger('update'); this.resize(); } }); $.widget('ui.validate', { _create: function() { var $fields = this.fields(); this.form = this.element.filter('form'); if (this.form.length > 0) { this.form.unbind('submit').submit($.delegate(this.submitCallback, this)); } else { this.element.find('button[type=submit]').unbind().click($.delegate(this.submitCallback, this)); } this.update(); for (var $i = 0; $i < $fields.length; $i++) { $fields.eq($i).trigger('blur'); } }, submitCallback: function(event) { if ($(event.target).filter('form').length == 0) event.preventDefault(); return this.validate(); }, update: function() { var $fields = this.fields(); var $field; for (var $i = 0; $i < $fields.length; $i++) { $field = $fields.eq($i); $field.data('validator', this); if ($field.data('type') == null) { $field.data('type', $field.attr('type')); $field.unbind(); $field.focus($.delegate(this.focus, this)); $field.blur($.delegate(this.blur, this)); } } }, focus: function(event) { var $field = $(event.target); if ($field.val() == $field.attr('title')) { $field.val(''); this.clone($field, true); } }, blur: function(event) { var $field = $(event.target); if ($field.val().length == 0) { $field.val($field.attr('title')); this.clone($field, false); } }, fields: function() { return this.element.find('input, textarea, select').filter(':visible'); }, clone: function($field, password) { var type = $field.data('type'); var attributes = ['id', 'class', 'style', 'type', 'title', 'name', 'value']; var attribute; var html; var $clone; if ($field.attr('type') == (password ? 'password' : 'text')) return; if (type == 'password') { html = " 0); break; default: valid = (value.length >= 2); } $field.toggleClass('error', !valid); errors[$field.attr('name')] = !valid; values[$field.attr('name')] = value; if (!valid) result = false; } } } if (this.options.submit != null) { this.options.submit.apply(this.element[0], [result, errors, values]); return false; } if (result) this.cleanup(); return result; }, cleanup: function() { var $fields = this.fields(); var $field; for (var i = 0; i < $fields.length; i++) { $field = $fields.eq(i); if ($field.val() == $field.attr('title')) $field.val(''); } }, submit: function() { this.cleanup(); this.element[0].submit(); }, serialize: function(object) { var $fields = this.element.find('input, textarea, select'); var $field; var data = {}; var value; var name; var parts; for (var i = 0; i < $fields.length; i++) { $field = $fields.eq(i); name = $field.attr('name'); value = $field.val(); parts = name.split(']').join('').split('['); if (object && parts.length > 1) { if (!data[parts[0]]) data[parts[0]] = {}; data[parts[0]][parts[1]] = value; } else { data[name] = value; } } if (object) return data; return $.param(data); }, clear: function() { this.fields().val(''); } }); $().ready(function() { $('input[type=checkbox], input[type=radio]').each(function() { var $original = $(this); var $checkbox; var $label = $original.next(); var checked = $original.is(':checked'); var html = "

    "; var update = function() { $(this).next().toggleClass('active', $(this).is(':checked')); }; var toggle = function() { var $input = $(this).prev(); var checked = !$input.is(':checked'); $(this).toggleClass('active', checked); $(this).prev().attr('checked', checked).trigger('change'); if ($input.attr('type') == 'radio') $(this).closest('form').find('input[name=' + $input.attr('name') + '][type=radio]').trigger('update'); }; $original.bind('change update', update); $original.after(html); $checkbox = $original.next(); $checkbox.unbind().bind('click', toggle); $checkbox.toggleClass('active', checked); if (String($label[0].nodeName).toLowerCase() == 'label') $label.css('cursor', 'pointer').unbind().click(function() { $(this).prev().trigger('click'); }); $original.hide(); }); $.tablesorter.defaults.textExtraction = 'complex'; $('.articles .promo .header, .articles .promo .icon').click(function() { $(this).closest('.promo').toggleClass('expanded').find('.content').slideToggle(); }); $('.list table, #downloads table').tablesorter({ textExtraction: function(node) { var value = node.childNodes[0].innerHTML; var check = $(node).find('*:first').attr('rel'); if (check) return check; return value; } }).bind('sortEnd', function() { $(this).find('tr').removeClass('odd').filter(':even').addClass('odd'); }); $('#content .gallery').gallery({ transition: ($('#content .gallery .pagination a').length > 0 ? 'slide' : null), change: function() { $('#content .gallery .status').hide(); }, show: function(index) { var $title = this.container.find('*[title]'); var $tooltip = $('#content .gallery .status'); var show = ($title.length > 0 && this.type == 'image'); $tooltip.find('strong').html((show ? $title.attr('title') : '')); if (!show) $tooltip.hide(); } }); $('#content .gallery').hover( function() { if ($(this).find('.status strong').html().length > 0) $(this).find('.status').show(); }, function() { $(this).find('.status').hide(); } ); $('#content .article .expand').click(function() { var expand = (!$(this).hasClass('expanded')); $(this).toggleClass('expanded', expand); $(this).html('Read ' + (expand ? 'less' : 'more') + ' >'); $(this).closest('.article').find('.additional').slideToggle(); }); $('#navigation ul.magazine > li:first > a').click(function() { if ($('#magazine').length == 0 && $('#magazine-article').length == 0) { document.location = $(this).attr('rel'); $(this).unbind(); } }); $('#navigation ul.magazine > li > a').click(function() { $(this).toggleClass('active'); $(this).closest('li').find('.content:first').slideToggle(); }); if ($('#magazine-article').length > 0) { $('#navigation ul.magazine > li:first > a').addClass('active'); $('#navigation ul.magazine > li:first .content:first').show(); } $('#popups .close').click(function() { $('#popups > *').hide(); $('#popups .overlay').show(); $('#popups').hide(); }); $('#header .collect').click(function() { if ($(this).hasClass('disabled')) return; $('#popups .collection').collection('add'); $('#popups .collected').show(); $('#popups').show(); }); $('#header .links .subscribe').click(function() { $('#popups .subscribe').show(); $('#popups').show(); }); $('#popups .collection .help a').click(function() { $('#popups > *').hide(); $('#popups .download .form').show(); $('#popups .download .confirmation').hide(); $('#popups .download, #popups .overlay').show(); $('#popups .download form').validate({ submit: function(valid) { if (!valid) return; /* $('#popups > *').hide(); $('#popups .overlay').show(); $('#popups').hide(); */ $('#popups .download .form').hide(); $('#popups .download .confirmation').show(); $(this).validate('cleanup'); this.submit(); } }); }); $('#header .links .download').click(function() { if ($(this).hasClass('disabled')) return; $('#popups .collection').show(); $('#popups').show(); }); $('#header .links .share').click(function() { $('#popups .share').show(); $('#popups').show(); }); $('#header .links .search').click(function() { var $parent; $('#popups').show(); $parent = $('#popups .search'); $parent.show(); $parent.search('init'); }); $('a.print').click(function() { window.print(); }); if ($.browser.msie && $.browser.version < 7) { $('.wysiwyg').each(function() { var $items; $items = $(this).find('> *'); $items.filter(':first').addClass('first'); $items.filter(':last').addClass('last'); }); $('#content .articles a').hover( function() { $(this).addClass('hover'); }, function() { $(this).removeClass('hover'); } ); } if ($.browser.msie && $.browser.version <= 7) { $('#content .articles a img').click(function() { document.location = $(this).closest('a').attr('href'); }); } $('#header .browse').browse(); $('#popups .search').search(); $('#popups .collection').collection(); $('#content .articles a').mouseover(function() { $(this).find('img').attr('style', 'font-size: 100%;'); }); });