/// class PD.Web.KeystrokeScope

PD.Web.KeystrokeScope = Class.extend({

    _PD: null,

    init: function (options) {
        this._PD = options.application;
        $(window).on("keydown", $.proxy(this._window_onKeyDown, this));
        $(document).on("focus", ".-pd-scope-capture", $.proxy(this._document_onFocus, this));
        $(document).ready($.proxy(this._document_onReady, this));



    },

    _window_onKeyDown: function (e) {

        var scope = this._PD.scope();

        if (e.keyCode === 13 && scope) {

            if ($(e.target).hasClass("-pd-capture-keystroke")) {
                e.stopPropagation();
                return;
            }

            alert(scope.outerHTML);

        }

    },

    _document_onFocus: function (e) {
        e.stopPropagation();
        if (e.currentTarget) {
            this._PD.scope(e.currentTarget || $("BODY")[0]);
        }
    },

    _document_onReady: function (e) {
        this._PD.scope($("BODY")[0]);
    }

});