// Generated by CoffeeScript 1.4.0 (function() { var Lazy, Placeholder, PopUp, Search, Tooltip, _this = this; $.extend($.fn, { backboneLink: function(options) { var attr, model, save; if (options == null) { options = {}; } model = options.model, attr = options.attr, save = options.save; if (save == null) { save = true; } return $(this).each(function() { var check; check = $(this).find('[data-backbone-link-attr]'); return (check.length ? check : $(this)).each(function() { var $t, checkbox; $t = $(this); $t.backboneUnlink(); $t.data({ backboneLinkModel: model }); checkbox = $t.is(':checkbox'); $t.data({ backboneLinkInputChange: function() { var attributes, newVal, oldVal; oldVal = model.get(attr); newVal = checkbox ? $t.prop('checked') : $t.val() || null; if (newVal !== oldVal) { (attributes = {})[attr] = newVal; return model[save ? 'save' : 'set'](attributes, { wait: true, attr: attr }); } } }); $t.data({ backboneLinkModelChange: function() { var newVal, oldVal, valOrText; valOrText = $t.is(':input') ? 'val' : 'text'; oldVal = checkbox ? $t.prop('checked') : $t[valOrText](); newVal = model.get(attr); newVal = newVal === null ? '' : newVal; if (newVal !== oldVal) { if (checkbox) { return $t.prop({ checked: !!newVal }); } else { return $t[valOrText](newVal); } } } }); if ($t.is(':input')) { $t.on('change', $t.data().backboneLinkInputChange); } model.on("change:" + attr, $t.data().backboneLinkModelChange); return $t.data().backboneLinkModelChange(); }); }); }, backboneUnlink: function() { return $(this).each(function() { var $t, model; $t = $(this); model = $t.data().backboneLinkModel; if (model) { $t.off('change', $t.data().backboneLinkInputChange); return model.off(null, $t.data().backboneLinkModelChange); } }); } }); $.Cookie = function(name, val, options) { var cookie, cookies, encodeName, encodeVal, n, params, rawCookies, v, _i, _len, _ref; if (options == null) { options = {}; } if (typeof name === 'object') { for (n in name) { v = name[n]; $.Cookie(n, v, val); } return $.Cookie(); } else if (typeof name === 'string' && val !== void 0) { if (val === null) { options.expires = -1; } val || (val = ''); params = []; if (options.expires) { params.push("; Expires=" + (options.expires.toGMTString != null ? options.expires.toGMTString() : new Date(+(new Date) + options.expires).toGMTString())); } if (options.path) { params.push("; Path=" + options.path); } if (options.domain) { params.push("; Domain=" + options.domain); } if (options.httpOnly) { params.push('; HttpOnly'); } if (options.secure) { params.push('; Secure'); } encodeName = encodeURIComponent(name); encodeVal = encodeURIComponent(val); document.cookie = "" + encodeName + "=" + encodeVal + (params.join('')); return $.Cookie(); } else { cookies = {}; if (document.cookie) { rawCookies = decodeURIComponent(document.cookie).split(/\s*;\s*/); for (_i = 0, _len = rawCookies.length; _i < _len; _i++) { cookie = rawCookies[_i]; _ref = /^([^=]*)\s*=\s*(.*)$/.exec(cookie), n = _ref[1], v = _ref[2]; if (typeof name === 'string' && name === n) { return v; } else if (!name) { cookies[n] = v; } } } if (!name) { return cookies; } else { return null; } } }; $.Konami = function(callback, options) { var checkEvents, dX, dY, keyDownEvent, keysPressed, startX, startY, tap, touchEndEvent, touchEvents, touchMoveEvent, touchStartEvent; if (options == null) { options = {}; } options = _.extend({ onlyOnce: false, code: '38,38,40,40,37,39,37,39,66,65,13', touchCode: 'up,up,down,down,left,right,left,right,tap,tap,tap' }, options); keysPressed = []; touchEvents = []; tap = false; startX = startY = dX = dY = 0; keyDownEvent = function(e) { keysPressed.push(e.keyCode); if (_.endsWith(keysPressed + '', options.code)) { if (options.onlyOnce) { $(document).off('keydown', keyDownEvent); } keysPressed = []; e.preventDefault(); return callback(); } }; touchStartEvent = function(e) { var touch, tracking; e = e.originalEvent; if (e.touches.length === 1) { touch = e.touches[0]; startX = touch.screenX, startY = touch.screenY; return tap = tracking = true; } }; touchMoveEvent = function(e) { var downUp, rightLeft, touch, val; e = e.originalEvent; if (e.touches.length === 1 && tap) { touch = e.touches[0]; dX = touch.screenX - startX; dY = touch.screenY - startY; rightLeft = dX > 0 ? 'right' : 'left'; downUp = dY > 0 ? 'down' : 'up'; val = Math.abs(dX) > Math.abs(dY) ? rightLeft : downUp; touchEvents.push(val); tap = false; return checkEvents(e); } }; touchEndEvent = function(e) { e = e.originalEvent; if (e.touches.length === 0 && tap) { touchEvents.push('tap'); return checkEvents(e); } }; checkEvents = function(e) { if (_.endsWith(touchEvents + '', options.touchCode)) { if (options.onlyOnce) { $(document).off('touchmove', touchMoveEvent); $(document).off('touchend', touchEndEvent); } touchEvents = []; e.preventDefault(); return callback(); } }; $(document).on('keydown', keyDownEvent); $(document).on('touchstart', touchStartEvent); $(document).on('touchmove', touchMoveEvent); return $(document).on('touchend', touchEndEvent); }; Lazy = { $els: $(), init: _.once(function() { return $(window).on('scroll resize', function() { return Lazy.check(Lazy.$els); }); }), check: function($imgs) { $imgs.each(function() { var $t; $t = $(this); return _.defer(function() { var fold, showLine, visible; visible = _.reduce($t.parents().toArray(), function(memo, parent) { return memo && $(parent).css('display') !== 'none' && $(parent).css('visibility') !== 'hidden'; }, true); fold = $(window).scrollTop() + $(window).outerHeight(); showLine = $t.offset().top - $t.data().lazyTolerance; if (visible && fold >= showLine) { $t.attr('src', $t.data().lazySrc); return Lazy.$els = Lazy.$els.not($t); } }); }); return $imgs; } }; $.fn.lazy = function(src, options) { var $t, tolerance; if (options == null) { options = {}; } tolerance = options.tolerance; if (tolerance == null) { tolerance = 100; } $t = $(this); Lazy.init(); Lazy.$els = Lazy.$els.add($t.data({ lazySrc: src, lazyTolerance: tolerance })); return Lazy.check($t); }; Placeholder = { init: _.once(function() { var val; val = $.fn.val; return $.fn.val = function(str) { var $t, data; $t = $(this); data = $t.data() || {}; if (str === void 0) { if (data.placeholderIsEmpty) { return ''; } else { return val.call($t); } } else { if ((data.placeholderIsEmpty != null) && !$t.is(':focus')) { if (str === '' || str === null) { $t.data({ placeholderIsEmpty: true }); val.call($t, data.placeholderText); if (data.placeholderIsPassword) { $t[0].type = 'text'; } } else { val.call($t, str); if (data.placeholderIsPassword) { $t[0].type = 'password'; } $t.data({ placeholderIsEmpty: false }); } } else { val.call($t, str); } return $t; } }; }), listeners: { focus: function() { var $t; $t = $(this); return _.defer(function() { if ($t.data().placeholderIsPassword) { $t[0].type = 'password'; } if ($t.data().placeholderIsEmpty) { $t.val(''); } return $t.data({ placeholderIsEmpty: false }); }); }, blur: function() { var $t; $t = $(this); return _.defer(function() { if (!$t.val()) { return $t.val(''); } }); } } }; $.fn.placeholder = function(text, options) { var password; if (options == null) { options = {}; } password = options.password; Placeholder.init(); return $(this).each(function() { var $t; if (($t = $(this)).data().placeholderIsEmpty == null) { if (password) { $t[0].type = 'password'; } $t.data({ placeholderText: text, placeholderIsEmpty: false, placeholderIsPassword: password }); if (!$t.val() || $t.val() === text) { $t.val(''); } return $t.attr({ placeholder: text, title: text }).on(Placeholder.listeners); } }); }; PopUp = { bind: function() { $('body').append(PopUp.$container = $('
').attr({ id: 'js-pop-up-container' }).css({ display: 'none', position: 'fixed', zIndex: 999999, left: 0, top: 0, width: '100%', height: '100%', opacity: 0, overflow: 'auto' }).append($('
').attr({ id: 'js-pop-up-table' }).css({ display: 'table', width: '100%', height: '100%' }).append($('
').attr({ id: 'js-pop-up-table-cell' }).css({ display: 'table-cell', textAlign: 'center', verticalAlign: 'middle' }).append(PopUp.$div = $('
').attr({ id: 'js-pop-up' }).css({ display: 'inline-block', position: 'relative' }))))); $.PopUp.hide(); PopUp.$container.on('click', function() { return PopUp.$div.find('.js-pop-up-outside').click(); }); PopUp.$div.on('click', function(e) { return e.stopPropagation(); }).on('click', '.js-pop-up-hide', function() { return $.PopUp.hide(); }); return $(document).keydown(function(e) { if (PopUp.$container.css('display') === 'block' && !$('body :focus').length) { switch (e.keyCode) { case 13: PopUp.$div.find('.js-pop-up-enter').click(); break; case 27: PopUp.$div.find('.js-pop-up-esc').click(); break; default: return true; } return false; } }); } }; PopUp.init = _.once(PopUp.bind); $.PopUp = { duration: 0, fadeDuration: 250, show: function(el, options) { var $body; if (options == null) { options = {}; } PopUp.init(); options = _.extend({ duration: $.PopUp.duration, callback: null, fadeDuration: $.PopUp.fadeDuration }, options); $body = $('body'); if (PopUp.$container.css('display') !== 'block') { PopUp.bodyStyle = $body.attr('style'); } if ($('body').hasScrollbar()) { $body.css({ marginRight: $.scrollbarSize() }); } $body.css({ overflow: 'hidden' }).find(':focus').blur(); PopUp.fadeDuration = options.fadeDuration; PopUp.$div.empty(); if (typeof el === 'string') { PopUp.$div.html(el); } else { PopUp.$div.append(el); } if (PopUp.$container.css('display') === 'block') { $($.PopUp).triggerHandler('hide'); } $($.PopUp).triggerHandler('show'); PopUp.$container.stop().css({ display: 'block' }).animate({ opacity: 1 }, options.fadeDuration); clearTimeout(PopUp.timeout); if (options.duration) { return PopUp.timeout = _.delay(function() { $.PopUp.hide(); return typeof options.callback === "function" ? options.callback() : void 0; }, options.duration); } }, hide: function(fadeDuration) { if (fadeDuration == null) { fadeDuration = PopUp.fadeDuration; } if (!PopUp.$container) { return; } return PopUp.$container.stop().animate({ opacity: 0 }, fadeDuration, function() { $($.PopUp).triggerHandler('hide'); PopUp.$container.css({ display: 'none' }); if (PopUp.bodyStyle) { $('body').attr({ style: PopUp.bodyStyle }); } else { $('body').removeAttr('style'); } return PopUp.bodyStyle = null; }); } }; $.fn.scrollTo = function(val, options) { if (val == null) { val = 0; } if (options == null) { options = {}; } if (val instanceof $) { val = val.offset().top; } return $(this).animate({ scrollTop: val }, options); }; $.scrollTo = function() { var $el; $el = $($.browser.webkit ? document.body : document.documentElement); return $el.scrollTo.apply($el, arguments); }; $.scrollbarSize = function(dimension) { var $in, $out, d1, d2; if (dimension == null) { dimension = 'width'; } $out = $('
').appendTo('body').css({ position: 'fixed', overflow: 'hidden', left: -50, top: -50, width: 50, height: 50 }); $in = $out.find('> div').css({ height: '100%' }); d1 = $in[dimension](); $out.css({ overflow: 'scroll' }); d2 = $in[dimension](); $out.remove(); return d1 - d2; }; $.fn.hasScrollbar = function() { var $t, d1, d2, style; $t = $(this); style = $t.attr('style'); d1 = $t.width(); d2 = $t.css({ overflow: 'hidden' }).width(); if (style != null) { $t.attr({ style: style }); } else { $t.removeAttr('style'); } return d1 !== d2; }; Search = { clean: function(str) { return str.replace(/\s+/g, ' ').replace(/^\s*|\s*$/g, ''); }, query: function($searches, urlN) { if (urlN == null) { urlN = 1; } return $searches.each(function() { var $q, $results, $search, anotherSearch, callback, o, q, t, _base, _ref; o = Search; $search = $(this); $results = $search.data().search$Results; $q = $search.data().search$Q; callback = $search.data().searchCallback; q = o.clean($q.val()); t = new Date().getTime(); $results.css({ display: 'block' }); anotherSearch = $search.data("searchUrl" + (urlN + 1)) != null; if (!(q || $search.data().searchEmpty)) { $results.css({ display: 'none' }).empty(); $search.removeClass('loading'); } else if (q !== $search.data().searchLastQ || urlN > 1) { $search.addClass('loading'); callback($search, null, urlN); clearTimeout($search.data().searchTimeout); if (typeof (_base = $search.data().searchAjax).abort === "function") { _base.abort(); } if ($search.data().searchCache[("" + urlN + "-") + q] != null) { if (!anotherSearch) { $search.removeClass('loading'); } callback($search, $search.data().searchCache[("" + urlN + "-") + q], urlN); if (anotherSearch) { o.query($search, urlN + 1); } } else { $search.data({ searchTimeout: _.delay(function() { var check, handleData; handleData = function(data) { $search.data().searchCache[("" + urlN + "-") + q] = data; if (check === $search.data().searchId && (o.clean($q.val()) || $search.data().empty)) { if (!anotherSearch) { $search.removeClass('loading'); } callback($search, data, urlN); } if (anotherSearch) { return o.query($search, urlN + 1); } }; check = $search.data({ searchId: $search.data().searchId + 1 }).data().searchId; if ($search.data().searchJs) { return handleData($search.data().searchJs(q)); } else if ($search.data().searchUrl != null) { return $search.data({ searchAjax: $.getJSON($search.data("searchUrl" + (urlN === 1 ? '' : urlN)), { q: q }, handleData) }); } }, (_ref = $search.data().searchDelay) != null ? _ref : 0) }); } } return $search.data({ searchLastQ: q }); }); }, select: function($searches, dir) { return $searches.each(function() { var $current, $new, $results, $search, $selected, o, rHeight, rScrollTop, sHeight, sTop; o = Search; $search = $(this); $results = $search.data().search$Results; $current = $results.find('.selected'); if (($new = $current[dir]()).length) { $current.removeClass('selected'); ($selected = $new).addClass('selected'); } else { $selected = $current; } rHeight = $results.height(); rScrollTop = $results.scrollTop(); sTop = $selected.position().top; sHeight = $selected.height(); return $results.scrollTop(sTop + rScrollTop - (rHeight - sHeight) / 2); }); } }; $.extend($.fn, { search: function($q, $results, options) { if (options == null) { options = {}; } return $(this).each(function() { var $search, key, o, val; $search = $(this); if (!$search.data().searchCache) { o = Search; $search.data({ searchCache: [], searchId: 0, searchAjax: {}, searchLastQ: null, searchHoldHover: false, search$Q: $q, search$Results: $results }); for (key in options) { val = options[key]; $search.data("search" + (key.replace(/(\w)/, function(s) { return s.toUpperCase(); })), val); } if ($q.is(':focus')) { o.query($search); } $search.hover(function() { return $search.data({ searchHover: true }); }, function() { $search.data({ searchHover: false }); if (!($q.is(':focus') || $search.data().searchHoldHover)) { return $results.css({ display: 'none' }); } }).mouseover(function() { return $search.data({ searchHoldHover: false }); }); $q.blur(function() { return _.defer(function() { if (!$search.data().searchHover) { return $results.css({ display: 'none' }); } }); }).focus(function() { return $search.data({ searchHoldHover: false }); }).keydown(function(e) { switch (e.keyCode) { case 13: $search.find('.selected').click(); break; case 38: o.select($search, 'prev'); break; case 40: o.select($search, 'next'); break; case 27: if ($q.val() === '') { $q.blur(); _.defer(function() { return o.query($search); }); } else { _.defer(function() { $q.val(''); return o.query($search); }); } break; default: _.defer(function() { if ($q.is(':focus')) { return o.query($search); } }); return true; } return false; }).on('focus keyup change', function() { return o.query($search); }); return $results.on('mouseenter click', '.result', function(e) { var $t; $t = $(this); $results.find('.result.selected').removeClass('selected'); $t.addClass('selected'); if (e.type === 'click') { if ($t.hasClass('submit')) { $t.parents('form').submit(); } if ($t.hasClass('hide')) { $q.blur(); return $results.css({ display: 'none' }); } } }); } }); } }); Tooltip = { mouse: { x: 0, y: 0 }, init: _.once(function() { return $('body').mousemove(function(e) { return Tooltip.mouse = { x: e.pageX, y: e.pageY }; }); }), listeners: { mousemove: function() { var $t; if (($t = $(this)).data('tooltip$Div')) { return $t.data().tooltip$Div.css(Tooltip.position($t).home); } }, mouseenter: function() { var $t; Tooltip.show($t = $(this)); return $t.data({ tooltipHover: true }); }, mouseleave: function() { var $t; ($t = $(this)).data({ tooltipHover: false }); return Tooltip.hide($t); }, focus: function() { return Tooltip.show($(this)); }, blur: function() { return Tooltip.hide($(this)); } }, add: function($els, options) { var _ref, _ref1, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7; if (options == null) { options = {}; } $els.data({ tooltipHtml: (_ref = options.html) != null ? _ref : '', tooltipPosition: (_ref1 = options.position) != null ? _ref1 : 'top', tooltipOffset: (_ref2 = options.offset) != null ? _ref2 : 0, tooltipDuration: (_ref3 = options.duration) != null ? _ref3 : 0, tooltipNoHover: (_ref4 = options.noHover) != null ? _ref4 : false, tooltipNoFocus: (_ref5 = options.noFocus) != null ? _ref5 : false, tooltipMouse: (_ref6 = options.mouse) != null ? _ref6 : false, tooltipHoverable: (_ref7 = options.hoverable) != null ? _ref7 : false }); if (options.mouse) { $els.on('mousemove', Tooltip.listeners.mousemove); } if (!options.noHover) { $els.on('mouseenter', Tooltip.listeners.mouseenter); $els.on('mouseleave', Tooltip.listeners.mouseleave); } if (!options.noFocus) { $els.on('focus', Tooltip.listeners.focus); $els.on('blur', Tooltip.listeners.blur); } return $els; }, divFor: function($t) { var $div, position; if (!$t.data('tooltip$Div')) { if ($t.parent().css('position') === 'static') { $t.parent().css({ position: 'relative' }); } if ($t.data().tooltipMouse) { $t.data({ tooltipHoverable: false }); } $t.data(_.extend({ tooltipPosition: 'top', tooltipOffset: 0, tooltipDuration: 0 }, $t.data())); $div = $('
').addClass("tooltip " + ($t.data().tooltipPosition)).css({ display: 'none', position: 'absolute', zIndex: 999999 }).append($('
').html($t.data().tooltipHtml).css({ position: 'relative' })); $t.data({ tooltip$Div: $div }).parent().append($div); position = Tooltip.position($t); $div.css(position.home).find('> div').css(_.extend({ opacity: 0 }, position.away)); if ($t.data().tooltipHoverable) { $div.hover(function() { Tooltip.show($t); return $t.data({ tooltipHoverableHover: true }); }, function() { $t.data({ tooltipHoverableHover: false }); return Tooltip.hide($t); }); } else { $div.css({ pointerEvents: 'none', '-webkit-user-select': 'none', '-moz-user-select': 'none', userSelect: 'none' }); } } return $t.data('tooltip$Div'); }, show: function($t) { var $div, position; $div = Tooltip.divFor($t); if (!((!$t.data().tooltipNoHover && $t.data().tooltipHover) || (!$t.data().tooltipNoFocus && $t.is(':input:focus')) || $t.data().tooltipHoverableHover)) { position = Tooltip.position($t); return $div.appendTo($t.parent()).css(_.extend({ display: 'block' }, position.home)).find('> div').stop().animate({ opacity: 1, top: 0, left: 0 }, $t.data().tooltipDuration); } }, hide: function($t) { var $div, position; if ($div = $t.data('tooltip$Div')) { if (!((!$t.data().tooltipNoHover && $t.data().tooltipHover) || (!$t.data().tooltipNoFocus && $t.is(':input:focus')) || $t.data().tooltipHoverableHover)) { position = Tooltip.position($t); return $div.css(position.home).find('> div').stop().animate(_.extend({ opacity: 0 }, position.away), { duration: $t.data().tooltipDuration, complete: function() { $t.data({ tooltip$Div: null }); return $(this).parent().remove(); } }); } } }, position: function($t) { var $div, $parent, away, divHeight, divWidth, home, offset, parentScrollLeft, parentScrollTop, tHeight, tLeft, tPosition, tTop, tWidth; $div = $t.data('tooltip$Div'); $parent = $t.parent(); offset = $t.data().tooltipOffset; divWidth = $div.outerWidth(); divHeight = $div.outerHeight(); parentScrollLeft = $parent.scrollLeft(); parentScrollTop = $parent.scrollTop(); if ($t.data().tooltipMouse) { tLeft = Tooltip.mouse.x - $t.parent().offset().left + parentScrollLeft; tTop = Tooltip.mouse.y - $t.parent().offset().top + parentScrollTop; tWidth = tHeight = 0; } else { tPosition = $t.position(); tLeft = tPosition.left + parentScrollLeft + parseInt($t.css('marginLeft')); tTop = tPosition.top + parentScrollTop + parseInt($t.css('marginTop')); tWidth = $t.outerWidth(); tHeight = $t.outerHeight(); } home = { left: tLeft, top: tTop }; away = {}; switch ($t.data().tooltipPosition) { case 'top': home.left += (tWidth - divWidth) / 2; home.top -= divHeight; away.top = -offset; break; case 'right': home.left += tWidth; home.top += (tHeight - divHeight) / 2; away.left = offset; break; case 'bottom': home.left += (tWidth - divWidth) / 2; home.top += tHeight; away.top = offset; break; case 'left': home.left -= divWidth; home.top += (tHeight - divHeight) / 2; away.left = -offset; } return { home: home, away: away }; } }; $.extend($.fn, { tooltip: function(options) { Tooltip.init(); return Tooltip.add($(this), options); }, correctTooltip: function() { return $(this).each(function() { var $div, $t; $t = $(this); $div = $t.data('tooltip$Div'); if ($div) { if ($t.css('display') === 'none') { return $t.mouseleave().blur(); } else { $div.find('> div').html($t.data().tooltipHtml); return $div.css(Tooltip.position($t).home); } } }); }, resetTooltip: function() { return $(this).each(function() { var _ref; return (_ref = $(this).data().tooltip$Div) != null ? _ref.remove() : void 0; }); } }); }).call(this);