// bookmarks setup window.addEvent('domready', function() { var bookmarkForms = $$('form.bookmark'); if(bookmarkForms) { bookmarkForms.each(function(form) { new BookmarkForm(form); }); } }); // links setup window.addEvent('domready', function() { var entries = $$('li[id^=item]'); if(entries) { entries.each(function(entry) { var itemid = entry.getProperty('id').match(/\d+$/); var links = entry.getElements('a[target=_blank]'); if(links) { links.each(function(l) { new LinkTrack(l, { sobi2Id: itemid, requestUri: document.location.href, type: 'feature' }); }); } }); } var banners = $$('a.companybanner'); if(banners) { banners.each(function(banner) { var image = banner.getElement('img'); new LinkTrack(banner, { requestUri: document.location.href, type: 'campaign', imageUri: image.getProperty('src') }); }); } }); var LinkTrack = new Class({ initialize: function(a, options) { this.element = a; this.setOptions(options); this.attachEvents(); this.options.link = this.element.getProperty('href'); }, attachEvents: function() { var that = this; var mouseIsDown = false; this.element.addEvents({ mousedown: function(e) { if(!e) { e = new Event(e); } mouseIsDown = true; return true; }, mouseup: function(e) { mouseIsDown = false; return true; }, click: function(e) { //_ct.trackEvent(that.options); /*var remote = new Ajax(baseUrl + '/index.php?option=com_company&controller=feature&task=click&format=raw', { data: that.options, method: 'post', async: false }).request();*/ return true; } }); } }); LinkTrack.implement(new Options); var BookmarkForm = new Class({ initialize: function(form) { this.element = form; this.timeoutLength = 200; this.timeoutId = 0; this.submitButton = form.getElement('input[type=submit]'); this.note = form.getElement('textarea'); this.label = form.getElement('input.label'); this.star = form.getElement('input.star'); this.published = form.getElement('input.published'); this.submit = form.getElement('input[type=submit]'); this.bookmarkId = form.getElement('input.bookmarkId'); this.attachEvents(); this.initializeFields(); }, initializeFields: function() { if(this.note.value == '') { this.note.value = this.note.getProperty('data-label', 'Note'); } if(this.label.value == '') { this.label.value = this.label.getProperty('data-label', 'Label'); } if(this.submit) { this.submit.setStyle('display', 'none'); } this.length = this.note.value.length + 5; this.fitToContent(); }, attachEvents: function() { var that = this; var timeoutId = 0; this.note.addEvents({ keyup: function(e) { that.fitToContent(); that.onFieldChange(); }, change: this.onFieldChange.bind(this), focus: function() { this.addClass('active'); if(this.value == this.getProperty('data-label')) { this.value = ''; } }, blur: function() { this.removeClass('active'); if(this.value == '') { this.value = this.getProperty('data-label'); } } }); this.label.addEvents({ keyup: this.onFieldChange.bind(this), change: this.onFieldChange.bind(this), focus: function() { this.addClass('active'); if(this.value == this.getProperty('data-label')) { this.value = ''; } }, blur: function() { this.removeClass('active'); if(this.value == '') { this.value = this.getProperty('data-label'); } } }); this.star.addEvents({ click: function(e) { that.published.value = that.published.value == 1 ? 0 : 1; //that.submitForm(); if(that.published.value == 0) { that.deleteBookmark(); } else { that.submitForm(); } } }); this.element.addEvents({ submit: function(e) { if(e) { e = new Event(e); e.stop(); } that.submitForm(); } }); }, onFieldChange: function() { var that = this; if(this.timeoutId) { clearTimeout(this.timeoutId); this.timeoutId = 0; } this.published.value = 1; this.timeoutId = setTimeout(function() { that.submitForm(); }, this.timeoutLength); }, fitToContent: function() { var text = this.note; var length = text.value.length; // recalculate scroll height for shrinking field if(this.length > length) { text.setStyle('height', 20); } var size = text.getSize(); if(size.scrollSize.y > size.size.y || size.scroll.y > 0) { text.setStyle('height', size.scrollSize.y + 'px'); } this.length = length; }, emptyLabel: function(field) { if(field.value == field.getProperty('data-label')) { field.value = ''; } }, fillLabel: function(field) { if(field.value == '' && !field.hasClass('active')) { field.value = field.getProperty('data-label'); } }, deleteBookmark: function() { var that = this; var url = this.element.getProperty('action'); url = url.replace('edit', 'delete'); url += url.match(/\?/) ? '&' : '?'; url += 'format=raw'; var remote = new Ajax(url, { data: { bookmarkId: this.element.getElement('input.bookmarkId').value }, method: 'post', onComplete: function(response) { if(Json.evaluate(response)) { that.note.value = ''; that.label.value = ''; that.fillLabel(that.note); that.fillLabel(that.label); that.star.removeClass('starred'); that.note.addClass('hidden'); that.label.addClass('hidden'); } else { alert('Could not remove bookmark'); } } }).request(); }, submitForm: function() { var url = this.element.getProperty('action'); var that = this; var data = {}; if(url.match(/\?/)) { url += '&'; } else { url += '?'; } url += 'format=raw'; this.emptyLabel(this.note); this.emptyLabel(this.label); var remote = new Ajax(url, { data: this.element, method: 'post', onComplete: function(response) { var data = Json.evaluate(response); that.published.value = data.published; that.bookmarkId.value = data.bookmarkId; if(data.published == 1) { that.star.addClass('starred'); that.note.removeClass('hidden'); that.label.removeClass('hidden'); if(that.note.value == '') { that.note.value = data.note; } if(that.label.value == '') { that.label.value = data.label; } } else { that.star.removeClass('starred'); that.note.addClass('hidden'); that.label.addClass('hidden'); that.note.value = ''; that.label.value = ''; } } }).request(); this.fillLabel(this.note); this.fillLabel(this.label); } });