📄 ssfx.ui.forms.debug.js
字号:
// Script# Framework
// Copyright (c) 2007, Nikhil Kothari. All Rights Reserved.
// http://projects.nikhilk.net
//
Type.createNamespace('ScriptFX.UI');
////////////////////////////////////////////////////////////////////////////////
// ScriptFX.UI.AutoCompleteOptions
ScriptFX.UI.$create_AutoCompleteOptions = function ScriptFX_UI_AutoCompleteOptions(service) {
var $o = { };
Debug.assert(!String.isNullOrEmpty(service), 'service parameter must not be empty.');
$o.service = service;
$o.id = null;
$o.itemCount = 10;
$o.itemLookupDelay = 500;
$o.minimumPrefixLength = 3;
$o.cssClass = 'autoComplete';
$o.itemCSSClass = 'autoCompleteItem';
$o.selectedItemCSSClass = 'autoCompleteSelectedItem';
$o.xOffset = 0;
$o.yOffset = 0;
return $o;
}
////////////////////////////////////////////////////////////////////////////////
// ScriptFX.UI.EnterKeyOptions
ScriptFX.UI.$create_EnterKeyOptions = function ScriptFX_UI_EnterKeyOptions(clickTarget) {
var $o = { };
Debug.assert(clickTarget);
$o.clickTarget = clickTarget;
return $o;
}
////////////////////////////////////////////////////////////////////////////////
// ScriptFX.UI.WatermarkOptions
ScriptFX.UI.$create_WatermarkOptions = function ScriptFX_UI_WatermarkOptions(watermarkText, watermarkCssClass) {
var $o = { };
$o.watermarkText = watermarkText;
$o.watermarkCssClass = watermarkCssClass;
return $o;
}
////////////////////////////////////////////////////////////////////////////////
// ScriptFX.UI.AutoCompleteBehavior
ScriptFX.UI.AutoCompleteBehavior = function ScriptFX_UI_AutoCompleteBehavior(domElement, options) {
ScriptFX.UI.AutoCompleteBehavior.constructBase(this, [ domElement, options.id ]);
this._options$1 = options;
this._selectedItemIndex$1 = -1;
domElement.autocomplete = 'off';
var events = this.get_domEvents();
events.attach('onfocus', Delegate.create(this, this._onTextBoxFocus$1));
events.attach('onblur', Delegate.create(this, this._onTextBoxBlur$1));
events.attach('onkeydown', Delegate.create(this, this._onTextBoxKeyDown$1));
}
ScriptFX.UI.AutoCompleteBehavior.prototype = {
_options$1: null,
_arguments$1: null,
_dropDown$1: null,
_dropDownPopup$1: null,
_dropDownEvents$1: null,
_dropDownVisible$1: false,
_selectedItemIndex$1: 0,
_itemCache$1: null,
_timerID$1: 0,
_currentPrefix$1: null,
_itemRequest$1: null,
get_arguments: function ScriptFX_UI_AutoCompleteBehavior$get_arguments() {
if (!this._arguments$1) {
this._arguments$1 = {};
}
return this._arguments$1;
},
add_itemDisplay: function ScriptFX_UI_AutoCompleteBehavior$add_itemDisplay(value) {
this.get_events().addHandler('itemDisplay', value);
},
remove_itemDisplay: function ScriptFX_UI_AutoCompleteBehavior$remove_itemDisplay(value) {
this.get_events().removeHandler('itemDisplay', value);
},
add_itemSelected: function ScriptFX_UI_AutoCompleteBehavior$add_itemSelected(value) {
this.get_events().addHandler('itemSelected', value);
},
remove_itemSelected: function ScriptFX_UI_AutoCompleteBehavior$remove_itemSelected(value) {
this.get_events().removeHandler('itemSelected', value);
},
add_requestingItems: function ScriptFX_UI_AutoCompleteBehavior$add_requestingItems(value) {
this.get_events().addHandler('requestingItems', value);
},
remove_requestingItems: function ScriptFX_UI_AutoCompleteBehavior$remove_requestingItems(value) {
this.get_events().removeHandler('requestingItems', value);
},
_abortRequest$1: function ScriptFX_UI_AutoCompleteBehavior$_abortRequest$1() {
if (this._itemRequest$1) {
this._itemRequest$1.abort();
this._itemRequest$1 = null;
}
},
clearCache: function ScriptFX_UI_AutoCompleteBehavior$clearCache() {
this._itemCache$1 = null;
},
_createDropDown$1: function ScriptFX_UI_AutoCompleteBehavior$_createDropDown$1() {
Debug.assert(!this._dropDown$1);
this._dropDown$1 = document.createElement('DIV');
if (this._options$1.cssClass) {
this._dropDown$1.className = this._options$1.cssClass;
}
this._dropDown$1.unselectable = 'unselectable';
document.body.appendChild(this._dropDown$1);
this._dropDownEvents$1 = new ScriptFX.UI.DOMEventList(this._dropDown$1);
this._dropDownEvents$1.attach('onmousedown', Delegate.create(this, this._onDropDownMouseDown$1));
this._dropDownEvents$1.attach('onmouseup', Delegate.create(this, this._onDropDownMouseUp$1));
this._dropDownEvents$1.attach('onmouseover', Delegate.create(this, this._onDropDownMouseOver$1));
var options = ScriptFX.UI.$create_PopupOptions(this.get_domElement(), ScriptFX.UI.PopupMode.anchorBottomLeft);
options.xOffset = this._options$1.xOffset;
options.yOffset = -1 + this._options$1.yOffset;
this._dropDownPopup$1 = new ScriptFX.UI.PopupBehavior(this._dropDown$1, options);
},
dispose: function ScriptFX_UI_AutoCompleteBehavior$dispose() {
this._stopTimer$1();
this._abortRequest$1();
if (this._dropDown$1) {
this._dropDownEvents$1.dispose();
this._dropDownEvents$1 = null;
this._dropDownPopup$1.dispose();
this._dropDownPopup$1 = null;
document.body.removeChild(this._dropDown$1);
this._dropDown$1 = null;
this._dropDownVisible$1 = false;
}
ScriptFX.UI.AutoCompleteBehavior.callBase(this, 'dispose');
},
_getDropDownItem$1: function ScriptFX_UI_AutoCompleteBehavior$_getDropDownItem$1(element) {
while ((element) && (element !== this._dropDown$1)) {
if (!isUndefined(element.__item)) {
return element;
}
element = element.parentNode;
}
return null;
},
_hideDropDown$1: function ScriptFX_UI_AutoCompleteBehavior$_hideDropDown$1() {
if (this._dropDownVisible$1) {
this._dropDownVisible$1 = false;
this._dropDownPopup$1.hide();
this._selectedItemIndex$1 = -1;
}
},
_highlightDropDownItem$1: function ScriptFX_UI_AutoCompleteBehavior$_highlightDropDownItem$1(itemElement) {
if (this._options$1.selectedItemCSSClass) {
ScriptFX.UI.Element.addCSSClass(itemElement, this._options$1.selectedItemCSSClass);
}
},
_onDropDownMouseDown$1: function ScriptFX_UI_AutoCompleteBehavior$_onDropDownMouseDown$1() {
var element = this._getDropDownItem$1(window.event.srcElement);
if (element) {
var item = element.__item;
var index = element.__index;
this._updateTextBox$1(item, index);
}
},
_onDropDownMouseUp$1: function ScriptFX_UI_AutoCompleteBehavior$_onDropDownMouseUp$1() {
this.get_domElement().focus();
},
_onDropDownMouseOver$1: function ScriptFX_UI_AutoCompleteBehavior$_onDropDownMouseOver$1() {
var element = this._getDropDownItem$1(window.event.srcElement);
if (this._selectedItemIndex$1 !== -1) {
this._unhighlightItem$1(this._dropDown$1.childNodes[this._selectedItemIndex$1]);
this._selectedItemIndex$1 = -1;
}
if (element) {
var selectedItemIndex = element.__index;
if (!isUndefined(this._selectedItemIndex$1)) {
this._selectedItemIndex$1 = selectedItemIndex;
this._highlightDropDownItem$1(element);
return;
}
}
},
_onRequestComplete$1: function ScriptFX_UI_AutoCompleteBehavior$_onRequestComplete$1(request, context) {
if ((request !== this._itemRequest$1) || (request.get_state() !== ScriptFX.Net.HTTPRequestState.completed) || (request.get_response().get_statusCode() !== ScriptFX.Net.HTTPStatusCode.OK)) {
return;
}
var parameters = context;
var prefixText = parameters['prefix'];
var cacheKey = prefixText;
if (this.get_events().getHandler('requestingItems')) {
delete parameters.prefix;
delete parameters.count;
cacheKey += ScriptFX.JSON.serialize(parameters);
}
var items = request.get_response().getObject();
this._updateDropDown$1(prefixText, items, cacheKey);
},
_onTextBoxBlur$1: function ScriptFX_UI_AutoCompleteBehavior$_onTextBoxBlur$1() {
this._stopTimer$1();
this._abortRequest$1();
this._hideDropDown$1();
},
_onTextBoxFocus$1: function ScriptFX_UI_AutoCompleteBehavior$_onTextBoxFocus$1() {
this._startTimer$1();
},
_onTextBoxKeyDown$1: function ScriptFX_UI_AutoCompleteBehavior$_onTextBoxKeyDown$1() {
this._stopTimer$1();
var e = window.event;
if (this._dropDownVisible$1) {
switch (e.keyCode) {
case ScriptFX.UI.Key.escape:
this._hideDropDown$1();
e.returnValue = false;
break;
case ScriptFX.UI.Key.up:
if (this._selectedItemIndex$1 > 0) {
this._unhighlightItem$1(this._dropDown$1.childNodes[this._selectedItemIndex$1]);
this._selectedItemIndex$1--;
this._highlightDropDownItem$1(this._dropDown$1.childNodes[this._selectedItemIndex$1]);
}
else if (this._selectedItemIndex$1 === -1) {
this._selectedItemIndex$1 = this._dropDown$1.childNodes.length - 1;
this._highlightDropDownItem$1(this._dropDown$1.childNodes[this._selectedItemIndex$1]);
}
e.returnValue = false;
break;
case ScriptFX.UI.Key.down:
if (this._selectedItemIndex$1 < (this._dropDown$1.childNodes.length - 1)) {
if (this._selectedItemIndex$1 === -1) {
this._selectedItemIndex$1 = 0;
}
else {
this._unhighlightItem$1(this._dropDown$1.childNodes[this._selectedItemIndex$1]);
this._selectedItemIndex$1++;
}
this._highlightDropDownItem$1(this._dropDown$1.childNodes[this._selectedItemIndex$1]);
}
e.returnValue = false;
break;
case ScriptFX.UI.Key.enter:
if (this._selectedItemIndex$1 !== -1) {
var item = this._dropDown$1.childNodes[this._selectedItemIndex$1].__item;
var index = this._dropDown$1.childNodes[this._selectedItemIndex$1].__index;
this._updateTextBox$1(item, index);
}
e.returnValue = false;
break;
}
}
if (e.keyCode !== ScriptFX.UI.Key.tab) {
this._startTimer$1();
}
},
_onTimerTick$1: function ScriptFX_UI_AutoCompleteBehavior$_onTimerTick$1() {
this._timerID$1 = 0;
this._abortRequest$1();
var text = (this.get_domElement()).value;
if (text === this._currentPrefix$1) {
return;
}
if (text.trim().length < this._options$1.minimumPrefixLength) {
this._updateDropDown$1(null, null, null);
return;
}
this._currentPrefix$1 = text;
var requestHandler = this.get_events().getHandler('requestingItems');
if (requestHandler) {
var e = new ScriptFX.UI.AutoCompleteRequestEventArgs(text);
requestHandler.invoke(this, e);
var items = e.get__items();
if (items) {
this._updateDropDown$1(text, items, null);
return;
}
}
if (this._itemCache$1) {
var cacheKey = text;
if (this._arguments$1) {
delete this._arguments$1.prefix;
delete this._arguments$1.count;
cacheKey += ScriptFX.JSON.serialize(this._arguments$1);
}
var items = this._itemCache$1[cacheKey];
if (items) {
this._updateDropDown$1(text, items, null);
return;
}
}
var parameters;
if (this._arguments$1) {
parameters = this._arguments$1;
}
else {
parameters = {};
}
parameters['prefix'] = text;
parameters['count'] = this._options$1.itemCount;
this._itemRequest$1 = ScriptFX.Net.HTTPRequest.createRequest(ScriptFX.Net.HTTPRequest.createURI(this._options$1.service, parameters), ScriptFX.Net.HTTPVerb.GET);
this._itemRequest$1.invoke(Delegate.create(this, this._onRequestComplete$1), parameters);
},
_showDropDown$1: function ScriptFX_UI_AutoCompleteBehavior$_showDropDown$1() {
if (!this._dropDownVisible$1) {
this._dropDownVisible$1 = true;
this._dropDown$1.style.width = (this.get_domElement().offsetWidth - 2) + 'px';
this._dropDownPopup$1.show();
}
},
_startTimer$1: function ScriptFX_UI_AutoCompleteBehavior$_startTimer$1() {
if (!this._timerID$1) {
this._timerID$1 = window.setTimeout(Delegate.create(this, this._onTimerTick$1), this._options$1.itemLookupDelay);
}
},
_stopTimer$1: function ScriptFX_UI_AutoCompleteBehavior$_stopTimer$1() {
if (this._timerID$1) {
window.clearTimeout(this._timerID$1);
this._timerID$1 = 0;
}
},
_unhighlightItem$1: function ScriptFX_UI_AutoCompleteBehavior$_unhighlightItem$1(itemElement) {
if (this._options$1.selectedItemCSSClass) {
ScriptFX.UI.Element.removeCSSClass(itemElement, this._options$1.selectedItemCSSClass);
}
},
_updateDropDown$1: function ScriptFX_UI_AutoCompleteBehavior$_updateDropDown$1(prefixText, items, cacheKey) {
var itemCount = 0;
if (items) {
itemCount = items.length;
}
if ((cacheKey) && (itemCount)) {
if (!this._itemCache$1) {
this._itemCache$1 = {};
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -