var optSpecs = []; var nashi = {opts: []}, inputMinSize = 300, fullWidthExpansion = false; var shortcutKeys = {}; function extract_num(q) { return parseInt(q.attr('id'), 10); } function parent_post($el) { return $el.closest('article, section'); } function parent_model($el) { var $a = parent_post($el); var op = extract_num($a); if (!op) return null; if ($a.is('section')) return Threads.get(op); var $s = $a.parent('section'); if (!$s.length) { // when we have better hover/inline expansion we will have to // deal with this, probably by setting data-op on the post console.warn($a, "'s parent is not thread?!"); return null; } var num = op; op = extract_num($s); return Threads.lookup(num, op); } (function () { /* OPTIONS LIST */ optSpecs.push(option_inline_expansion); if (window.devicePixelRatio > 1) optSpecs.push(option_high_res); optSpecs.push(option_thumbs); optSpecs.push(option_autocomplete); optSpecs.push(option_backlinks); optSpecs.push(option_reply_at_right); optSpecs.push(option_theme); optSpecs.push(option_last_n); _.defaults(options, { lastn: config.THREAD_LAST_N, inlinefit: 'width', }); options = new Backbone.Model(options); nashi.upload = !!$('').prop('disabled'); if (window.screen && screen.width <= 480) { inputMinSize = 50; fullWidthExpansion = true; } function load_ident() { try { var id = JSON.parse(localStorage.ident); if (id.name) $name.val(id.name); if (id.email) $email.val(id.email); } catch (e) {} } function save_ident() { try { var name = $name.val(), email = $email.val(); if (email == 'misaki') { $email.val(''); $.getScript(mediaURL + 'js/login.js'); email = false; } else if (is_sage(email) && !is_noko(email)) email = false; var id = {}; if (name || email) { if (name) id.name = name; if (email) id.email = email; localStorage.setItem('ident', JSON.stringify(id)); } else localStorage.removeItem('ident'); } catch (e) {} } options.on('change', function () { try { localStorage.options = JSON.stringify(options); } catch (e) {} }); /* LAST N CONFIG */ function option_last_n(n) { if (!reasonable_last_n(n)) return; $.cookie('lastn', n); // should really load/hide posts as appropriate } option_last_n.id = 'lastn'; option_last_n.label = '[Last #]'; option_last_n.type = 'positive'; oneeSama.lastN = options.get('lastn'); options.on('change:lastn', function (model, lastN) { oneeSama.lastN = lastN; }); /* THEMES */ var themes = [ 'moe', 'gar', 'mawaru', 'moon', 'ashita', 'console', 'tea', 'higan', ]; function option_theme(theme) { if (theme) { var css = theme + '.css?v=' + themeVersion; $('#theme').attr('href', mediaURL + 'css/' + css); } } option_theme.id = 'board.$BOARD.theme'; option_theme.label = 'Theme'; option_theme.type = themes; /* THUMBNAIL OPTIONS */ var revealSetup = false; function option_thumbs(type) { $.cookie('thumb', type); // really ought to apply the style immediately // need pinky/mid distinction in the model to do properly oneeSama.thumbStyle = type; var hide = type == 'hide'; if (hide) $('img').hide(); else $('img').show(); if (hide && !revealSetup) $DOC.on('click', 'article', reveal_thumbnail); else if (!hide && revealSetup) $DOC.off('click', 'article', reveal_thumbnail); revealSetup = hide; } option_thumbs.id = 'board.$BOARD.thumbs'; option_thumbs.label = 'Thumbnails'; option_thumbs.type = thumbStyles; /* Alt-click a post to reveal its thumbnail if hidden */ function reveal_thumbnail(event) { if (!event.altKey) return; var $article = $(event.target); var $img = $article.find('img'); if ($img.length) { with_dom(function () { $img.show(); }); return false; } /* look up the image info and make the thumbnail */ var thread = Threads.get(extract_num($article.closest('section'))); if (!thread) return; var post = thread.get('replies').get(extract_num($article)); if (!post) return; var info = post.get('image'); if (!info) return; with_dom(function () { var img = oneeSama.gazou_img(info, false); var $img = $.parseHTML(flatten(img.html).join('')); $article.find('figcaption').after($img); }); return false; } /* REPLY AT RIGHT */ function option_reply_at_right(r) { if (r) $('