// Generated by CoffeeScript 1.10.0 (function() { var CloudKeys; CloudKeys = (function() { function CloudKeys() { this.entities = []; this.version = ""; this.password = ''; $('#pw').focus().keyup((function(_this) { return function(evt) { var that = this; if (evt.keyCode === 13) { _this.password = $(that).val(); $('#loader').removeClass('hide'); _this.fetchData(); $('#newEntityLink').click(function() { return _this.showForm(); }); $('#passwordRequest').addClass('hide'); $('#search').keyup(function() { var that = this; _this.limitItems(_this.getItems($(that).val())); }); $('#search').focus(); return $(window).keyup(function(evt) { if (evt.altKey === true && evt.keyCode === 66) { if (typeof window.copyToClipboard === "function") { copyToClipboard($('#items li.active .username').val()); } else { $('#items li.active .username').focus().select(); } } if (evt.altKey === true && evt.keyCode === 79) { if (typeof window.copyToClipboard === "function") { copyToClipboard($('#items li.active .password').data('toggle')); } else { $('#items li.active .passwordtoggle em').click(); $('#items li.active .password').focus().select(); } } if (evt.altKey === true && evt.keyCode === 80) { if (typeof window.copyToClipboard === "function") { copyToClipboard($('#items li.active .password').data('toggle')); } else { $('#items li.active .password').focus().select(); } } if (evt.altKey === true && evt.keyCode === 85) { if (typeof window.copyToClipboard === "function") { return copyToClipboard($('#items li.active .url').val()); } else { return $('#items li.active .url').focus().select(); } } }); } }; })(this)); } CloudKeys.prototype["import"] = function(xml) { var e, entity, entry, group, j, l, len, len1, parsedXML, ref, ref1, tag; parsedXML = $.parseXML(xml); ref = $(parsedXML).find('group'); for (j = 0, len = ref.length; j < len; j++) { group = ref[j]; tag = $(group).find('>title').text(); ref1 = $(group).find('entry'); for (l = 0, len1 = ref1.length; l < len1; l++) { entry = ref1[l]; e = $(entry); entity = {}; entity['title'] = e.find('title').text(); entity['username'] = e.find('username').text(); entity['password'] = e.find('password').text(); entity['url'] = e.find('url').text(); entity['comment'] = e.find('comment').text(); entity['tags'] = tag; this.entities.push(entity); } } return this.updateData((function(_this) { return function() { $('#import').val(''); return $('#importLink').click(); }; })(this)); }; CloudKeys.prototype.updateData = function(callback) { var encrypted, hash; encrypted = this.encrypt(JSON.stringify(this.entities)); hash = CryptoJS.SHA1(encrypted).toString(); return $.post('ajax', { 'version': this.version, 'checksum': hash, 'data': encrypted }, (function(_this) { return function(result) { if (result.error === true) { return alert("An error occured, please reload and try it again"); } else { if (typeof callback !== "undefined") { callback(); } return _this.updateInformation(result); } }; })(this), "json"); }; CloudKeys.prototype.fetchData = function() { return $.get('ajax', (function(_this) { return function(data) { return _this.updateInformation(data); }; })(this), "json"); }; CloudKeys.prototype.updateInformation = function(data) { var e, error; this.version = data.version; if (data.data === "") { this.entities = []; } else { try { this.entities = $.parseJSON(this.decrypt(data.data)); } catch (error) { e = error; window.location.reload(); } } this.entities.sort(this.sortItems); this.showItems(this.getItems('')); return this.limitItems(this.getItems($('#search').val())); }; CloudKeys.prototype.encrypt = function(value) { return CryptoJS.AES.encrypt(value, this.password).toString(); }; CloudKeys.prototype.decrypt = function(value) { return CryptoJS.AES.decrypt(value, this.password).toString(CryptoJS.enc.Utf8); }; CloudKeys.prototype.getClipboardCode = function(value) { var cb; cb = $('
'); cb.click(function(e) { var elem; elem = $("").css({ 'position': 'absolute', 'left': '-9999px', 'readonly': 'readonly', 'top': (window.pageYOffset || document.documentElement.scrollTop) + 'px' }); $("body").append(elem); elem.focus(); elem.select(); document.execCommand('copy'); elem.remove(); }); return cb; }; CloudKeys.prototype.limitItems = function(items) { var current; $('#resultdescription span').text(items.length); current = 0; $('#items>li').each((function(_this) { return function(k, v) { var item; item = $(v); item.removeClass('odd'); if ($.inArray(item.data('num'), items) === -1) { item.addClass('hide'); } else { if (item.hasClass('hide')) { item.removeClass('hide'); } if (current % 2 === 0) { item.addClass('odd'); } current = current + 1; } }; })(this)); }; CloudKeys.prototype.showItems = function(items) { var additionalClass, c, char, counter, field, i, item, itemContainer, j, len, lines_match, password, ref, ul; $('#items li').remove(); itemContainer = $('#items'); $('#resultdescription span').text(items.length); for (i = j = 0, len = items.length; j < len; i = ++j) { item = items[i]; additionalClass = ""; if (i % 2 === 0) { additionalClass = "odd"; } item = this.entities[item]; c = $("