1 /* Part of Objavi2, which turns html manuals into books. This file
2 * provides javascript to help people select the book and options they
5 * Copyright (C) 2009 Douglas Bagnall
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 function toggle_advanced(){
23 var adv = $(".advanced");
24 if (adv.filter(".gone").length){
25 $("#toggle-advanced").text('Hide advanced options');
26 adv.removeClass("gone");
29 $("#toggle-advanced").text('Show advanced options');
36 function css_mode_switch(){
37 var v = $("#css-control").val();
40 $('.css-' + s).removeClass("hidden-css");
41 $('.css-' + s + ' input').removeAttr('disabled');
42 $('.css-' + s + ' textarea').removeAttr('disabled');
45 $('.css-' + s + ' input').attr('disabled', 'disabled');
46 $('.css-' + s + ' textarea').attr('disabled', 'disabled');
47 $('.css-' + s).addClass("hidden-css");
55 var not_v = (v == 'url') ? 'custom' : 'url';
61 function mode_switch(){
62 /*For openoffice mode, hide the irrelevant inputs */
63 var mode = $("#mode").val();
64 if (mode == 'openoffice'){
65 $('.advanced').not($('.openoffice')).addClass('hidden-mode');
68 $('div.advanced').removeClass('hidden-mode');
72 function load_booklist(){
73 var server = $("#server").val();
76 w.attr('disabled', 'disabled');
77 w.load("?server=" + server + "&book=" + book + "&mode=booklist",
78 undefined, function(){w.removeAttr('disabled');}
83 var server = $("#server").val();
84 var textarea = $('#css');
86 //Try to get CSS to suit current mode
87 $.get("?server=" + server + "&mode=css&pdftype=" + $("#mode").val(),
88 undefined, function(data){textarea.val(data);}
93 function toggle_custom_size(){
94 var v = $("#booksize").val();
96 $('.booksize').removeClass("hidden");
99 $('.booksize').addClass("hidden");
104 $(".advanced").addClass("gone");
106 if ($("#toggle-advanced").length == 0){
107 $("#license_div").after('<button id="toggle-advanced">Show advanced options</button>');
108 $("#toggle-advanced").click(toggle_advanced);
111 $("#booksize").change(toggle_custom_size);
112 toggle_custom_size();
114 $("#server").change(load_booklist);
116 if ($("#css-control").length == 0){
117 $(".css-url").before('<div id="css-control_div" class="advanced form-item openoffice">' +
118 '<div class="input_title">CSS mode</div>' +
119 '<div><select id="css-control">' +
120 '<option value="default" selected="selected">Server default</option>' +
121 '<option value="url">URL</option>' +
122 '<option value="custom">Custom</option>' +
123 '</select></div></div>'
124 ).attr("name", 'css');
125 $('#css_div .input_title').after('<a href="#" onclick="load_css(); return false;">' +
126 'Load default CSS for this server and mode ' +
127 '(lose changes)</a>');
130 $("#mode").change(mode_switch);
131 $("#css-control").change(css_mode_switch);
133 //load the booklist for the selected server