/*
Copyright 2008 Kevin Morey (email : kevin@kmorey.net)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
var advtag_pluginDir = '/wp-content/plugins/advanced-tagline/';
var advtag_blogHome = '/';
var advtag_ajaxUrl = '/wp-admin/admin-ajax.php';
//var jQuery = jQuery.noConflict();
var STR_REACTIVATE_TAGLINE = "Re-activate Tagline";
var STR_EDIT_TAGLINE = "Edit Tagline";
var STR_REMOVE_TAGLINE = "Remove Tagline";
var ID_ACTIVE = '#active_taglines';
function advtag_saveTagline() {
var index = jQuery('#add_index').val();
var textElem = jQuery('#add_text');
var linkElem = jQuery('#add_link');
var targetElem = jQuery('#add_target');
index = parseInt(index);
jQuery('#add-tagline img.throbber').show();
var div = null;
if (index != -1) {
div = jQuery(ID_ACTIVE).find('tr.tagline').eq(index);
}
jQuery.ajax({
url: advtag_ajaxUrl,
type: 'POST',
dataType: 'json',
data: {
action: 'advtag_save',
index: index,
text: textElem.val(),
link: linkElem.val(),
target: targetElem.val()
},
success: function(data){
console.log(data);
if (index == -1) {
var e = advtag_newTagline(textElem.val(), linkElem.val(), targetElem.val());
}
else {
var e = advtag_buildTagDiv(textElem.val(), linkElem.val(), targetElem.val());
div.replaceWith(e);
advtag_updateButtons();
}
jQuery('#add_index').val(-1);
textElem.val("");
linkElem.val("");
targetElem.val("");
jQuery('div#add-tagline').hide();
advtag_scrollTo(e);
},
complete: function(data) {
jQuery('#add-tagline img').hide();
}
});
}
function advtag_editTag(button)
{
var div = jQuery(button).parent().parent();
var text, link, target;
if (div.find('a').length == 0) {
//text only
text = div.find('p').eq(0).html();
}
else {
var a = div.find('a').eq(0);
text = a.html();
link = a.attr('href');
target = a.attr('target');
}
var index = advtag_getIndex(div);
jQuery('#add_index').val(index);
jQuery('#add_text').val(text);
jQuery('#add_link').val(link);
jQuery('#add_target').val(target);
/* jQuery('#btn-add-tagline').click(); */
jQuery('div#add-tagline').slideDown();
advtag_scrollTo('div#add-tagline');
advtag_switchToEdit();
}
function advtag_scrollTo(e) {
var destination = jQuery(e).offset().top;
jQuery('html,body').animate(
{scrollTop: destination},
400
);
}
function advtag_getIndex(div) {
var index = -1;
jQuery(ID_ACTIVE).find('tr.tagline').each(function(i, val) {
if (jQuery(val).get(0) == div.get(0)) { index = i; return false; }
});
return index;
}
function advtag_switchToEdit() {
jQuery('#TB_ajaxWindowTitle').html('Edit Tagline');
}
function advtag_newTagline(text, link, target) {
var e = advtag_buildTagDiv(text,link,target);
jQuery(ID_ACTIVE).append(e);
advtag_updateButtons();
return e;
}
function advtag_buildTagDiv(text, link, target) {
//TODO: create a class for the tagline elements
var e = jQuery('