Created
June 25, 2014 13:37
-
-
Save radek-baczynski/c99bf65dd2cda99e839b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var SecretItem = function ($el) { | |
| this.$el = $el; | |
| this.$text = $('.secret-text', $el); | |
| this.$save = $('button.edit-item', $el); | |
| var master = this; | |
| if (this.$el.hasClass('secret-init')) { | |
| this.$text.focus(); | |
| } | |
| this.save = function () { | |
| console.log(this.$el.data()); | |
| return $.ajax({ | |
| url: this.$el.data('save-url'), | |
| data: { | |
| form: { | |
| text: this.$text.text(), | |
| _token: this.$el.data('csrf-token') | |
| } | |
| }, | |
| dataType: 'json', | |
| type: 'post' | |
| }); | |
| } | |
| this.bindEvents = function () { | |
| this.$text.keydown(function (e) { | |
| var self = $(this); | |
| if (self.text() == self.data('default')) { | |
| self.text(''); | |
| } | |
| else if (self.text().length > 0) { | |
| master.$save.removeClass('hide '); | |
| } | |
| else if (self.text().length == 0) { | |
| master.$save.addClass('hide'); | |
| } | |
| // trap the return key being pressed | |
| if (e.keyCode === 13) { | |
| return false; | |
| } | |
| }); | |
| this.$save.click(function (e) { | |
| e.preventDefault(); | |
| master.save().done(function (rsp) { | |
| if (rsp.post_url) { | |
| window.location = rsp.post_url; | |
| } | |
| }).fail(function () { | |
| alert('Wystąpił jakiś błąd, spróbuj odświeżyć stronę i dodać sekret jeszcze raz'); | |
| }); | |
| }); | |
| } | |
| this.bindEvents(); | |
| }; | |
| CommentBar = function ($el) { | |
| this.$el = $el; | |
| this.$form = $('.comment-form', this.$el); | |
| var master = this; | |
| this.bindEvents = function () { | |
| this.$form.on('click', ':text', function () { | |
| if (!master.$el.hasClass('big')) { | |
| master.$el.animate({ | |
| height: '+=50px' | |
| }, 500, function () { | |
| master.$el.addClass('big'); | |
| }); | |
| } | |
| }); | |
| this.$form.ajaxForm({ | |
| }); | |
| }; | |
| this.bindEvents(); | |
| } | |
| $(document).ready(function () { | |
| if ($el = $('.comment-navbar', 'body')) { | |
| bar = new CommentBar($el); | |
| } | |
| $('[data-toggle="tooltip"]').tooltip(); | |
| $('.secret-item').each(function () { | |
| item = new SecretItem($(this)); | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment