// 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 = $('