home *** CD-ROM | disk | FTP | other *** search
/ Chip 2011 November / CHIP_2011_11.iso / Programy / Narzedzia / Calibre / calibre-0.8.18.msi / file_294 < prev    next >
Text File  |  2011-09-01  |  11KB  |  324 lines

  1.  
  2. // Cookies {{{
  3. /**
  4.  * Create a cookie with the given name and value and other optional parameters.
  5.  *
  6.  * @example $.cookie('the_cookie', 'the_value');
  7.  * @desc Set the value of a cookie.
  8.  * @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
  9.  * @desc Create a cookie with all available options.
  10.  * @example $.cookie('the_cookie', 'the_value');
  11.  * @desc Create a session cookie.
  12.  * @example $.cookie('the_cookie', null);
  13.  * @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain
  14.  *       used when the cookie was set.
  15.  *
  16.  * @param String name The name of the cookie.
  17.  * @param String value The value of the cookie.
  18.  * @param Object options An object literal containing key/value pairs to provide optional cookie attributes.
  19.  * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.
  20.  *                             If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
  21.  *                             If set to null or omitted, the cookie will be a session cookie and will not be retained
  22.  *                             when the the browser exits.
  23.  * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).
  24.  * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).
  25.  * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will
  26.  *                        require a secure protocol (like HTTPS).
  27.  * @type undefined
  28.  *
  29.  * @name $.cookie
  30.  * @cat Plugins/Cookie
  31.  * @author Klaus Hartl/klaus.hartl@stilbuero.de
  32.  */
  33.  
  34. function cookie(name, value, options) {
  35.     if (typeof value != 'undefined') { // name and value given, set cookie
  36.         options = options || {};
  37.         if (value === null) {
  38.             value = '';
  39.             options.expires = -1;
  40.         }
  41.         var expires = '';
  42.         if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
  43.             var date;
  44.             if (typeof options.expires == 'number') {
  45.                 date = new Date();
  46.                 date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
  47.             } else {
  48.                 date = options.expires;
  49.             }
  50.             expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
  51.         }
  52.         // CAUTION: Needed to parenthesize options.path and options.domain
  53.         // in the following expressions, otherwise they evaluate to undefined
  54.         // in the packed version for some reason...
  55.         var path = options.path ? '; path=' + (options.path) : '';
  56.         var domain = options.domain ? '; domain=' + (options.domain) : '';
  57.         var secure = options.secure ? '; secure' : '';
  58.         document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
  59.     } else { // only name given, get cookie
  60.         var cookieValue = null;
  61.         if (document.cookie && document.cookie != '') {
  62.             var cookies = document.cookie.split(';');
  63.             for (var i = 0; i < cookies.length; i++) {
  64.                 var cookie = jQuery.trim(cookies[i]);
  65.                 // Does this cookie string begin with the name we want?
  66.                 if (cookie.substring(0, name.length + 1) == (name + '=')) {
  67.                     cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
  68.                     break;
  69.                 }
  70.             }
  71.         }
  72.         return cookieValue;
  73.     }
  74. };
  75.  
  76. // }}}
  77.  
  78. // Sort {{{
  79.  
  80. function init_sort_combobox() {
  81.     $("#sort_combobox").multiselect({
  82.        multiple: false,
  83.        header: sort_select_label,
  84.        noneSelectedText: sort_select_label,
  85.        selectedList: 1,
  86.        click: function(event, ui){
  87.             $(this).multiselect("close");
  88.             cookie(sort_cookie_name, ui.value);
  89.             window.location.reload();
  90.        }
  91.     });
  92. }
  93.  
  94. // }}}
  95.  
  96. function init() {
  97.     $("#container").corner("30px");
  98.     $("#header").corner("30px");
  99.     $("#calibre-home-link").click(function() { window.location = "http://calibre-ebook.com"; });
  100.  
  101.     init_sort_combobox();
  102.  
  103.     $("#search_box input:submit").button();
  104. }
  105.  
  106. // Top-level feed {{{
  107.  
  108. function toplevel_layout() {
  109.     var last = $(".toplevel li").last();
  110.     var title = $('.toplevel h3').first();
  111.     if (title && title.position()) {
  112.         var bottom = last.position().top + last.height() - title.position().top;
  113.         $("#main").height(Math.max(200, bottom+75));
  114.     }
  115. }
  116.  
  117. function toplevel() {
  118.     $(".sort_select").hide();
  119.  
  120.     $(".toplevel li").click(function() {
  121.         var href = $(this).children("a").attr('href');
  122.         window.location = href;
  123.     });
  124.  
  125.     toplevel_layout();
  126.     $(window).resize(toplevel_layout);
  127.  
  128. }
  129. // }}}
  130.  
  131. function render_error(msg) {
  132.     var st = "";
  133.     try {
  134.         var st = printStackTrace();
  135.         st = st.join('\n\n');
  136.     } catch(e) {
  137.     }
  138.     return '<div class="ui-widget"><div class="ui-state-error ui-corner-all" style="padding: 0pt 0.7em"><p><span class="ui-icon ui-icon-alert" style="float: left; margin-right: 0.3em"> </span><strong>Error: </strong>'+msg+"<pre>"+st+"</pre></p></div></div>"
  139. }
  140.  
  141. // Category feed {{{
  142.  
  143. function category_clicked() {
  144.    var href = $(this).find("a").attr('href');
  145.    window.location = href;
  146. }
  147.  
  148. function category() {
  149.     $(".category .category-item").click(category_clicked);
  150.  
  151.     $(".category a.navlink").button();
  152.     
  153.     $("#groups").accordion({
  154.         collapsible: true,
  155.         active: false,
  156.         autoHeight: false,
  157.         clearStyle: true,
  158.         header: "h3",
  159.  
  160.         change: function(event, ui) {
  161.             if (ui.newContent) {
  162.                 var href = ui.newContent.prev().children("a.load_href").attr('href');
  163.                 ui.newContent.children(".loading").show();
  164.                 if (href) {
  165.                     $.ajax({
  166.                         url:href,
  167.                         cache: false,
  168.                         data:{'sort':cookie(sort_cookie_name)},
  169.                         success: function(data) {
  170.                             this.children(".loaded").html(data);
  171.                             this.children(".loaded").show();
  172.                             this.children(".loading").hide();
  173.                             this.find('.category-item').click(category_clicked);
  174.                         },
  175.                         context: ui.newContent,
  176.                         dataType: "json",
  177.                         timeout: 600000, //milliseconds (10 minutes)
  178.                         error: function(xhr, stat, err) {
  179.                             this.children(".loaded").html(render_error(stat));
  180.                             this.children(".loaded").show();
  181.                             this.children(".loading").hide();
  182.                         }
  183.                     });
  184.                 }
  185.             }
  186.         }
  187.     });
  188. }
  189. // }}}
  190.  
  191. // Booklist {{{
  192.  
  193. function first_page() {
  194.     load_page($("#booklist #page0"));
  195. }
  196.  
  197. function last_page() {
  198.     load_page($("#booklist .page").last());
  199. }
  200.  
  201. function next_page() {
  202.     var elem = $("#booklist .page:visible").next('.page');
  203.     if (elem.length > 0) load_page(elem);
  204.     else first_page();
  205. }
  206.  
  207. function previous_page() {
  208.     var elem = $("#booklist .page:visible").prev('.page');
  209.     if (elem.length > 0) load_page(elem);
  210.     else last_page();
  211. }
  212.  
  213. function gp_internal(id) {
  214.     var gp = $('#goto_page_dialog');
  215.     gp.dialog('close');
  216.     var elem = $("#booklist #" + id);
  217.     load_page(elem);
  218. }
  219.  
  220. function goto_page() {
  221.     var gp = $('#goto_page_dialog');
  222.     var pl = $('#booklist > #pagelist');
  223.     gp.html(pl.html());
  224.     gp.dialog('option', 'title', pl.attr('title'));
  225.     gp.dialog('option', 'height', $(window).height() - 100);
  226.     gp.dialog('open');
  227.  
  228. }
  229.  
  230. function load_page(elem) {
  231.     if (elem.is(":visible")) return;
  232.     var ld = elem.find('.load_data');
  233.     var ids = ld.attr('title');
  234.     var href = ld.find(".url").attr('title');
  235.     elem.children(".loaded").hide();
  236.  
  237.     $.ajax({
  238.         url: href,
  239.         context: elem,
  240.         dataType: "json",
  241.         cache : false,
  242.         type: 'POST',
  243.         timeout: 600000, //milliseconds (10 minutes)
  244.         data: {'ids': ids},
  245.         error: function(xhr, stat, err) {
  246.             this.children(".loaded").html(render_error(stat));
  247.             this.children(".loaded").show();
  248.             this.children(".loading").hide();
  249.         },
  250.         success: function(data) {
  251.             this.children(".loaded").html(data);
  252.             this.find(".left a.read").button();
  253.             this.children(".loading").hide();
  254.             this.parent().find('.navmiddle .start').html(this.find('.load_data .start').attr('title'));
  255.             this.parent().find('.navmiddle .end').html(this.find('.load_data .end').attr('title'));
  256.             this.children(".loaded").fadeIn(1000);
  257.         }
  258.     });
  259.     $("#booklist .page:visible").hide();
  260.     elem.children(".loaded").hide();
  261.     elem.children(".loading").show();
  262.     elem.show();
  263. }
  264.  
  265. function hidesort() {$("#content > .sort_select").hide();}
  266.  
  267. function booklist(hide_sort) {
  268.     if (hide_sort) hidesort();
  269.     var test = $("#booklist #page0").html();
  270.     if (!test) {
  271.         $("#booklist").html(render_error("No books found"));
  272.         return;
  273.     }
  274.     $("#book_details_dialog").dialog({
  275.         autoOpen: false,
  276.         modal: true,
  277.         show: 'slide'
  278.     });
  279.     $("#goto_page_dialog").dialog({
  280.         autoOpen: false,
  281.         modal: true,
  282.         show: 'slide'
  283.     });
  284.  
  285.     first_page(); 
  286. }
  287.  
  288. function show_details(a_dom) {
  289.     var book = $(a_dom).closest('div.summary');
  290.     var bd = $('#book_details_dialog');
  291.     bd.html('<span class="loading"><img src="'+url_prefix+'/static/loading.gif" alt="Loading" />Loading, please wait…</span>');
  292.     bd.dialog('option', 'width', $(window).width() - 100);
  293.     bd.dialog('option', 'height', $(window).height() - 100);
  294.     bd.dialog('option', 'title', book.find('.title').text());
  295.  
  296.     $.ajax({
  297.         url: book.find('.details-href').attr('title'),
  298.         context: bd,
  299.         cache: false,
  300.         dataType: "json",
  301.         timeout: 600000, //milliseconds (10 minutes)
  302.         error: function(xhr, stat, err) {
  303.             this.html(render_error(stat));
  304.         },
  305.         success: function(data) {
  306.             this.html(data);
  307.         }
  308.     });
  309.  
  310.     bd.dialog('open');
  311. }
  312.  
  313. // }}}
  314.  
  315. function book() {
  316.     hidesort();
  317.     $('.details .left img').load(function() {
  318.         var img = $('.details .left img');
  319.         var height = $('#main').height();
  320.         height = Math.max(height, img.height() + 100);
  321.         $('#main').height(height);
  322.     });
  323. }
  324.