File: preview.js

package info (click to toggle)
tdiary 5.0.11-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 2,852 kB
  • sloc: ruby: 22,925; xml: 325; makefile: 16; sh: 10
file content (69 lines) | stat: -rw-r--r-- 1,995 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
 * preview.js: view preview automatically
 *
 * Copyright (c) MATSUOKA Kohei <http://www.machu.jp/>
 * Distributed under the GPL2 or any later version.
 */
$(function() {

var previewButton = $('input[name*="preview"]');
var intervalRate = 1;

$tDiary.plugin.preview.reload = function() {
  previewButton.prop("disabled", true);
  $.post(
    'update.rb',
    $('form.update').serialize() + "&appendpreview=1",
    function(data) {
      var previewContent = $(data).find('div.autopagerize_page_element');
      if (previewContent.length != 0) {
        $('div.autopagerize_page_element').replaceWith(previewContent);
        intervalRate = 1;
      } else {
        intervalRate *= 2;
        console.info('[preview.js] update failed, the next update will be after '
          + $tDiary.plugin.preview.interval * intervalRate + 'sec.');
      }
      $('div.day')
        .css('flex', "1 1 " + $tDiary.plugin.preview.minWidth / 2 + "px");
    },
    'html'
  )
  .fail(function() {
    intervalRate *= 2;
    console.info('[preview.js] update failed, the next update will be after '
      + $tDiary.plugin.preview.interval * intervalRate + 'sec.');
  })
  .always(function() {
    previewButton.prop("disabled", false);
    setTimeout($tDiary.plugin.preview.reload,
      $tDiary.plugin.preview.interval * 1000 * intervalRate);
  });
}

if ($('div.autopagerize_page_element').length == 0) {
  $('div.update').before(
    '<div class="day autopagerize_page_element">'
  );
}

$('<div class="preview-container"></div>')
  .css('display', 'flex')
  .css('flex-flow', 'row-reverse wrap')
  .insertAfter('h1')
  .append($('div.day'));
$('div.day')
  .css('flex', "1 1 " + $tDiary.plugin.preview.minWidth / 2 + "px");
$("div.whole-content").css('max-width', 'none');

// プレビューボタンを押した時もajaxで更新するよう設定
previewButton.click(
  function(event) {
    event.preventDefault();
    $tDiary.plugin.preview.reload();
  }
);

$tDiary.plugin.preview.reload();

});