console.log("Loading gui_div.js\n");
var initialised_iframe = "false";
/*
$("#iframe").ready(function(){
console.log("iframe is ready ...");
var iframe = document.getElementById('iframe');
var iframe_document = iframe.document;
if(iframe.contentDocument)
{
iframe_document = iframe.contentDocument; // For NS6
console.log("Chose content document");
}
else if(iframe.contentWindow)
{
iframe_document = iframe.contentWindow.document; // For IE5.5 and IE6
console.log("Chose content window");
}
console.log(iframe_document.documentElement.innerHTML); //document.documentElement.outerHTML
$(iframe_document.documentElement.innerHTML).find('a').each(function() {
console.log("data "+$(this).data('href'));
console.log("getAttribute "+$(this).getAttribute('href'));
console.log("attr "+$(this).attr('href'));
console.log("this.href "+this.href);
var original = this.href; //$(this).attr('href');
// check if greenstone link ie. starts with format
//var original = $(this).data('href');
var modified = original.toString().concat("&excerptid=gs_content");
console.log(modified);
this.href = modified;
//$(this).attr('href',modified);
//$(this).data('href', modified);
//console.log($(this).attr('href'));
console.log("data "+$(this).data('href'));
console.log("getAttribute "+$(this).getAttribute('href'));
console.log("attr "+$(this).attr('href'));
console.log("this.href "+this.href);
console.log("**********");
});
}); */
/*
function loadXMLDoc()
{
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
console.log("state changed to " + xmlhttp.readyState);
console.log("status is " + xmlhttp.status);
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
console.log("get code");
console.log(xmlhttp.responseText);
document.getElementById("gs_content").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","http://localhost:8080/greenstone3/format?a=b&rt=s&s=ClassifierBrowse&c=simpleht&cl=CL1&excerptid=gs_content",true);
//xmlhttp.open("GET","http://www.cs.waikato.ac.nz",true);
//xmlhttp.open("GET","http://wand.net.nz/~sjb48/index.html",true);
xmlhttp.send();
}
*/
$(document).ready(function(){
console.log("Document ready function\n");
var CURRENT_SELECT_VALUE = "";
var iframe = document.getElementById('iframe');
var iframe_document = iframe.document;
if(iframe.contentDocument)
{
iframe_document = iframe.contentDocument; // For NS6
console.log("Chose content document");
}
else if(iframe.contentWindow)
{
iframe_document = iframe.contentWindow.document; // For IE5.5 and IE6
console.log("Chose content window");
}
// Edit the hrefs in preview_html - search for
var start_index = 0;
var end_index = 0;
while(start_index != -1)
{
start_index = preview_html.indexOf("href=\"format", start_index);
console.log("start index = " + start_index);
if(start_index != -1)
{
end_index = preview_html.indexOf("\">", start_index);
console.log("end_index = " + end_index);
a = preview_html.substring(0,end_index);
b = preview_html.substring(end_index);
preview_html = a.concat("&excerptid=gs_content", b);
console.log(preview_html);
start_index = end_index + "&excerptid=gs_content\">".length;
}
}
// Put the content in the iframe
if(initialised_iframe == "false")
{
console.log("Initialised iframe with preview html");
console.log(preview_html);
iframe_document.open();
iframe_document.writeln(preview_html); //.concat("&excerptid=gs_content"));
iframe_document.close();
initialised_iframe = "true";
}
/*
$(iframe_document.documentElement.innerHTML).find('a').each(function() {
console.log("data "+$(this).data('href'));
console.log("getAttribute "+this.getAttribute('href'));
console.log("attr "+$(this).attr('href'));
console.log("this.href "+this.href);
var original = this.href; //$(this).attr('href');
// check if greenstone link ie. starts with format
//var original = $(this).data('href');
var modified = original.toString().concat("&excerptid=gs_content");
console.log("* *");
console.log(modified);
console.log("* *");
//this.href = modified;
//$(this).attr('href',modified);
//$(this).data('href', modified);
$(this).attr({ 'href': modified });
//console.log($(this).attr('href'));
console.log("data "+$(this).data('href'));
console.log("getAttribute "+this.getAttribute('href'));
console.log("attr "+$(this).attr('href'));
console.log("this.href "+this.href);
console.log("***********************");
});
*/
/******************************************/
/* DRAGGABLES */
/******************************************/
$(".draggable_gsf_template").draggable({
cursor: 'crosshair',
connectToSortable: '#formatStatement',
helper: 'clone',
revert: 'invalid'
});
$(".draggable_table").draggable({
cursor: 'crosshair',
connectToSortable: '.gsf_template',
helper: 'clone',
revert: 'invalid'
});
$(".draggable_tr").draggable({
cursor: 'crosshair',
connectToSortable: '.gsf_table',
helper: 'clone',
revert: 'invalid'
})
$(".draggable_td").draggable({
cursor: 'crosshair',
//connectToSortable: '.td',
helper: 'clone',
revert: 'invalid'
})
$(".draggable_gsf_text").draggable({
cursor: 'crosshair',
connectToSortable: '.td-div, .gsf_when, .gsf_otherwise, .gsf_link, .gsf_choose_metadata, .gsf_default',
helper: 'clone',
revert: 'invalid'
});
$(".draggable_gsf_choose_metadata").draggable({
cursor: 'crosshair',
connectToSortable: '.td-div, .gsf_link, .gsf_when, .gsf_otherwise',
helper: 'clone',
revert: 'invalid'
});
//$(".element_type_gsf_metadata").draggable({
$(".draggable_gsf_metadata").draggable({
cursor: 'crosshair',
connectToSortable: '.gsf_choose_metadata, .gsf_when, .gsf_otherwise, .gsf_link, .td-div',
helper: 'clone',
revert: 'invalid'
});
$(".draggable_gsf_link").draggable({
cursor: 'crosshair',
connectToSortable: '.td-div, .gsf_when, .gsf_otherwise, .gsf_link',
helper: 'clone',
revert: 'invalid'
});
// switch, when, otherwise, icon
$(".draggable_gsf_switch").draggable({
cursor: 'crosshair',
connectToSortable: '.td-div, .gsf_link',
helper: 'clone',
revert: 'invalid'
});
$(".draggable_gsf_when").draggable({
cursor: 'crosshair',
connectToSortable: '.gsf_switch',
helper: 'clone',
revert: 'invalid'
});
$(".draggable_gsf_otherwise").draggable({
cursor: 'crosshair',
connectToSortable: '.gsf_switch',
helper: 'clone',
revert: 'invalid'
});
$(".draggable_gsf_icon").draggable({
cursor: 'crosshair',
connectToSortable: '.td-div, .gsf_link, .gsf_choose, .gsf_when, .gsf_otherwise',
helper: 'clone',
revert: 'invalid'
});
/******************************************/
/* SORTABLES */
/******************************************/
bind_td_sortable();
bind_all_sortables();
$('#formatStatement').sortable({
cursor: 'pointer',
tolerance: 'pointer',
items: '.gsf_template',
placeholder:'placeholder',
//'nested':'div'
stop: function(event, ui) {
if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('css_gsf_template')) { replace_with(ui.item,gsf_template_element); }
}
});
$('div.gsf_template').children(".block,.table").slideUp(300);
});
/*******************************************************************************/
function bind_all_sortables()
{
console.log('function bind_all_sortables()');
bind_template_sortable();
//bind_table_sortable();
//bind_tr_sortable();
//bind_td_sortable();
bind_choose_metadata_sortable();
bind_link_sortable();
bind_switch_sortable();
bind_when_sortable();
bind_otherwise_sortable();
bind_tables();
bind_block_mouseover();
bind_minmax_remove();
}
function bind_tables()
{
console.log('function bind_tables()');
//$('.tr').resize_tables($(this)); //equalHeights();
$('td').click(function () {
console.log('td click *');
return false;
});
$(".td-div").resizable({
alsoResize: 'parent',
//containment: 'parent',
handles: 'w,e',
stop: function(event, ui) {
console.log('Resize table on stop');
resize_tables($(this));
//$(this).parent().parent().equalHeights();
}, });
//$(".droppable").sortable({
// 'cursor':'pointer',
// 'tolerance': 'pointer',
// 'items':'.column, .td-div',
// 'placeholder':'placeholder'
//});
$(".droppable").droppable({
accept: '.element_type_td',
tolerance: 'pointer',
activate: function(event, ui) { $(this).addClass("droppable_hl");}, // console.log("droppable activated")},
deactivate: function(event, ui) { $(this).removeClass("droppable_hl"); }, // console.log("droppable deactivated")},
drop: function(event, ui) {
//if ($(this).hasClass("ui-draggable"))
//if (ui.helper.hasClass("ui-draggable"))
//{
var neverempty = document.createElement("div");
neverempty.setAttribute("class","neverempty block");
neverempty.setAttribute("style","height:50px");
neverempty.setAttribute("style","display:block");
var text = document.createTextNode('NEVER EMPTY');
neverempty.appendChild(text);
var td = document.createElement("td");
var div = document.createElement("div"); // class=\"td block\" title=\"td-div\"");
div.setAttribute("title","td-div");
div.setAttribute("class","td-div block");
div.setAttribute("style","margin-left:0px");
div.setAttribute("width","25px");
td.appendChild(div);
div.appendChild(neverempty);
var sep = document.createElement("td");
sep.setAttribute("class","droppable");
sep.setAttribute("width","10px");
$(this).after(sep);
$(this).after(td);
bind_tables();
resize_tables($(this));
bind_td_sortable();
bind_block_mouseover();
//bind_all_sortables();
//}
//else
//{
// console.log("Attempting to add");
//$(this).appendTo(ui.draggable[0]);
// $(this).prepend(ui.draggable[0]);
//$(ui.draggable[0]).appendTo($(this));
//}
}
});
}
function replace_with(item, me)
{
// Search me for select
if(me.search("select") != -1)
{
// If select exists, then find CURRENT_SELECT_VALUE
var index = me.search(CURRENT_SELECT_VALUE);
if(index == -1)
console.log("Did not find " + CURRENT_SELECT_VALUE);
else
console.log("Found " + CURRENT_SELECT_VALUE + " at index " + index);
index = index + CURRENT_SELECT_VALUE.length + 1;
console.log("Attempt inserting select at new index "+index);
a = me.substring(0,index);
b = me.substring(index);
me = a.concat("selected",b);
}
//console.log('function replace_with(item, me)');
item.replaceWith(me); //'
XXXXXXXXXXXXXXXXXXXXXXXX |