ディスプレイをたてにしてみた

1680x1050のディスプレイを縦向きにして、1050x1680にしてみました。
コードを書く分には100行近くがばっと表示できて非常によい感じです。
横幅1680を分割せずに使うと、だいたいは右側のスペースが余ってもったいない感じになるんですが、横幅1050だとちょうどぎりぎりいっぱいという感じ。

ただ、コードを書く以外では不便そうな感じです。 いまどき横幅1050ではなかなか辛いというか……。
アームを買ってきて、必要なときだけぐりっと90度回転できるようにするのがベストなのかなあと考えてます。

現状は、壁にただ立てかけてる状態です。 なんかの表紙にビタンッと行きそうで怖い。

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がスクロールしないと見えない位置にある場合、見えるようにスクロールします