選挙に行って問題だと感じたこと
- 選挙に行った
- 投票所に行くまでに入場券を落とした
- 投票所で気づいた
- 再発行してもらった
- 身分確認がなかった
成りすまし対策みたいなのはしないでよいのか、と思ったという話。
JavaScriptで戻るボタンを使えるようにするjQueryプラグイン
(function (jQuery){ jQuery.history = this; this.init = function(){ this.loc; if(jQuery.browser.msie){ this.iframe = $('<iframe>').hide(); $("body").append(this.iframe); var iframe = this.iframe.get(0).contentWindow.document; iframe.open(); iframe.close(); this.loc = iframe.location; } else { this.loc = location; } this.checkinterval = 100; this.histories = []; this.def = Number(this.loc.hash ? this.loc.hash.replace('#', '') : 0); this.current = def; this.mvflag = false; this.dontcheck = false; setInterval((function(self){ return function(){ self.check(); } })(this), this.checkinterval); }; this.push = function(callback){ if(this.mvflag){ this.mvflag = false; return; } if( !this.histories[this.def] ) this.histories[this.def] = callback; else{ this.dontcheck = true; if(jQuery.browser.msie){ var iframe = this.iframe.get(0).contentDocument || this.iframe.get(0).contentWindow.document; iframe.open(); iframe.close(); } this.histories[++this.current] = callback; this.loc.hash = '#' + this.current; this.dontcheck = false; } }; this.check = function(){ if( this.dontcheck ) return; var number = Number(this.loc.hash.replace('#', '')); if( number != this.current ){ // $.jGrowl((number > this.current ? 'forward' : 'back') + '... '+ this.current+ '->'+ number); this.current = number; if(this.histories[number]){ this.mvflag = true; (this.histories[number])(); } } }; return jQuery; })(jQuery);
使用法はまたこんど書く。
首が痛い
正面のディスプレイにputty+emacs, 右側に置いたディスプレイにブラウザでいろいろやってるんですが、JavaScriptをやるときは必然的にブラウザのほうを向いている時間が長くなって右ばっかり向いてるせいで首を痛めました。
ある要素が画面内に収まるようにスクロールするjQueryプラグイン
(function(){ jQuery.fn.isinwindow = function(){ var top = $(window).scrollTop(); var bottom = $(window).height() + $(window).scrollTop(); var left = $(window).scrollLeft(); var right = $(window).width() + $(window).scrollLeft(); return this.offset().top >= top && this.offset().top + this.height() <= bottom && this.offset().left >= left && this.offset().left + this.width() <= right; }; jQuery.fn.inwindow = function(){ var top = $(window).scrollTop(); var bottom = $(window).height() + $(window).scrollTop(); var left = $(window).scrollLeft(); var right = $(window).width() + $(window).scrollLeft(); if(!(this.offset().top >= top)){ $(window).scrollTop(this.offset().top); } if(!(this.offset().top + this.height() <= bottom)){ $(window).scrollTop( $(window).scrollTop() + this.offset().top + this.height() - bottom ); } if(!(this.offset().left >= left)){ $(window).scrollLeft(this.offset().left); } if(!(this.offset().left + this.width() <= right)){ $(window).scrollLeft( $(window).scrollLeft() + this.offset().left + this.width() - right ); } return this; }; })(jQuery);
$('#hoge').isinwindow(); // hogeが画面内(見える位置)にあればtrue, なければfalseを返します $('#hoge').inwindow(); // hogeがスクロールしないと見えない位置にある場合、見えるようにスクロールします