|
| 1 | +var GeekWeek = Class.create({ |
| 2 | + initialize: function() { |
| 3 | + this.domNode = $('iphone_body'); |
| 4 | + this.attachNecessaryEvents(); |
| 5 | + }, |
| 6 | + |
| 7 | + attachNecessaryEvents: function() { |
| 8 | + this.attachNavigationLinks(); |
| 9 | + this.attachTextBoxEvents(); |
| 10 | + this.attachSubmit(); |
| 11 | + }, |
| 12 | + |
| 13 | + attachNavigationLinks: function() { |
| 14 | + this.domNode.select('a.navigation').each(function(link) { |
| 15 | + link.observe('click', this.loadContent.bindAsEventListener(this)); |
| 16 | + }.bind(this)); |
| 17 | + }, |
| 18 | + |
| 19 | + attachSubmit: function() { |
| 20 | + this.domNode.select('a.submit').each(function(link) { |
| 21 | + link.observe('click', this.submitForm.bindAsEventListener(this)); |
| 22 | + }.bind(this)); |
| 23 | + }, |
| 24 | + |
| 25 | + attachTextBoxEvents: function() { |
| 26 | + this.domNode.select('input').each(function(text) { |
| 27 | + text.observe('blur', this.maskTextField.bindAsEventListener(this)); |
| 28 | + text.observe('focus', this.clearTextField.bindAsEventListener(this)); |
| 29 | + text.value = text.value === "" ? text.readAttribute("title") : text.value; |
| 30 | + }.bind(this)); |
| 31 | + }, |
| 32 | + |
| 33 | + loadContent: function(e) { |
| 34 | + var url = e.element().readAttribute("data-url"); |
| 35 | + var request = new Ajax.Request(url, { |
| 36 | + method: 'get', |
| 37 | + onSuccess: function(response) { |
| 38 | + this.domNode.update().update(response.responseText); |
| 39 | + this.attachNecessaryEvents(); |
| 40 | + }.bind(this) |
| 41 | + }); |
| 42 | + }, |
| 43 | + |
| 44 | + clearTextField: function(e) { |
| 45 | + var text = e.element(); |
| 46 | + var maskedText = text.readAttribute("title"); |
| 47 | + text.value = (text.value == maskedText ? "" : text.value); |
| 48 | + }, |
| 49 | + |
| 50 | + maskTextField: function(e) { |
| 51 | + var text = e.element(); |
| 52 | + var maskedText = text.readAttribute("title"); |
| 53 | + text.value = (text.value === "" ? maskedText : text.value); |
| 54 | + }, |
| 55 | + |
| 56 | + submitForm: function(e) { |
| 57 | + var button = e.element(); |
| 58 | + var form = button.up('form'); |
| 59 | + var submitRequest = new Ajax.Request(form.action, { |
| 60 | + parameters: form.serialize(), |
| 61 | + onSuccess: function(response) { |
| 62 | + this.domNode.update().update(response.responseText); |
| 63 | + this.attachNecessaryEvents(); |
| 64 | + }.bind(this) |
| 65 | + }); |
| 66 | + } |
| 67 | + |
| 68 | +}); |
0 commit comments