<commit_before>define([
	"dojo/_base/kernel",
	"dojo/_base/declare",
	"dojo/_base/array",
	"dojo/_base/connect",
	"dojo/_base/lang",
	"dojo/_base/html",
	"dojo/_base/event",
	"dojo/query",
	"dojo/string",
	"dojo/keys",
	"dojo/text!../templates/Pagination.html",
	"./Dialog",
	"./_StoreLayer",
	"../_Plugin",
	"../../EnhancedGrid",
	"dijit/form/Button",
	"dijit/form/NumberTextBox",
	"dijit/focus",
	"dijit/_Widget",
	"dijit/_TemplatedMixin",
	"dijit/_WidgetsInTemplateMixin",
	"dojox/html/metrics",
	"dojo/i18n!../nls/Pagination"
], function(kernel, declare, array, connect, lang, html, event, query,
	string, keys, template, Dialog, layers, _Plugin, EnhancedGrid,
	Button, NumberTextBox, dijitFocus, _Widget, _TemplatedMixin, _WidgetsInTemplateMixin, metrics, nls){
		
var _GotoPagePane = declare("dojox.grid.enhanced.plugins.pagination._GotoPagePane", [_Widget, _TemplatedMixin, _WidgetsInTemplateMixin], {
	templateString: "<div>" + 
						"<div class='dojoxGridDialogMargin' dojoAttachPoint='_mainMsgNode'></div>" +
						"<div class='dojoxGridDialogMargin'>" +
							"<input dojoType='dijit.form.NumberTextBox' style='width: 50px;' dojoAttachPoint='_pageInputBox' dojoAttachEvent='onKeyUp: _onKey'></input>" +
							"<label dojoAttachPoint='_pageLabelNode'></label>" +
						"</div>" +
						"<div class='dojoxGridDialogButton'>" +
							"<button dojoType='dijit.form.Button' dojoAttachPoint='_confirmBtn' dojoAttachEvent='onClick: _onConfirm'></button>" +
							"<button dojoType='dijit.form.Button' dojoAttachPoint='_cancelBtn' dojoAttachEvent='onClick: _onCancel'></button>" +
						"</div>" +
					"</div>",
	widgetsInTemplate: true,
	dlg: null,
	postMixInProperties: function(){
		this.plugin = this.dlg.plugin;
	},
	postCreate: function(){
		this.inherited(arguments);
		this._mainMsgNode.innerHTML = this.plugin._nls[12];
		this._confirmBtn.set("label", this.plugin._nls[14]);
		this._confirmBtn.set("disabled", true);
		this._cancelBtn.set("label", this.plugin._nls[15]);
	},
	_onConfirm: function(evt){
		if(this._pageInputBox.isValid() && this._pageInputBox.getDisplayedValue() !== ""){
			this.plugin.currentPage(this._pageInputBox.parse(this._pageInputBox.getDisplayedValue()));
			this.dlg._gotoPageDialog.hide();
			this._pageInputBox.reset();
		}
		stopEvent(evt);
	},
	_onCancel: function(evt){
		this._pageInputBox.reset();
		this.dlg._gotoPageDialog.hide();
		stopEvent(evt);
	},
	_onKey: function(evt){
		this._confirmBtn.set("disabled", !this._pageInputBox.isValid() || this._pageInputBox.getDisplayedValue() == "");
		if(!evt.altKey && !evt.metaKey && evt.keyCode === keys.ENTER){
			this._onConfirm(evt);
		}
	}
});

var _GotoPageDialog = declare("dojox.grid.enhanced.plugins.pagination._GotoPageDialog", null, {
	pageCount: 0,
	dlgPane: null,
	constructor: function(plugin){
		this.plugin = plugin;
		this.dlgPane = new _GotoPagePane({"dlg": this});
		this.dlgPane.startup();
		this._gotoPageDialog = new Dialog({
			"refNode": plugin.grid.domNode,
			"title": this.plugin._nls[11],
			"content": this.dlgPane
		});
		this._gotoPageDialog.startup();
	},
	_updatePageCount: function(){
		this.pageCount = this.plugin.getTotalPageNum();
		this.dlgPane._pageInputBox.constraints = {fractional:false, min:1, max:this.pageCount};
		this.dlgPane._pageLabelNode.innerHTML = string.substitute(this.plugin._nls[13], [this.pageCount]);
	},
	showDialog: function(){
		this._updatePageCount();
		this._gotoPageDialog.show();
	},
	destroy: function(){
		this._gotoPageDialog.destroy();
	}
});

var _ForcedPageStoreLayer = declare("dojox.grid.enhanced.plugins._ForcedPageStoreLayer", layers._StoreLayer, {
	tags: ["presentation"],
	constructor: function(plugin){
		this._plugin = plugin;
	},
	_fetch: function(request){
		var _this = this,
			plugin = _this._plugin,
			grid = plugin.grid,
			scope = request.scope || kernel.global,
			onBegin = request.onBegin;
		request.start = (plugin._currentPage - 1) * plugin._currentPageSize + request.start;
		_this.startIdx = request.start;
		_this.endIdx = request.start + plugin._currentPageSize - 1;
		var p = plugin._paginator;
		if(!plugin._showAll){
			plugin._showAll = !p.sizeSwitch && !p.pageStepper && !p.gotoButton;
		}
		if(onBegin && plugin._showAll){
			request.onBegin = function(size, req){
				plugin._maxSize = plugin._currentPageSize = size;
				_this.startIdx = 0;
				_this.endIdx = size - 1;
				plugin._paginator._update();
				req.onBegin = onBegin;
				req.onBegin.call(scope, size, req);
			};
		}else if(onBegin){
			request.onBegin = function(size, req){
				req.start = 0;
				req.count = plugin._currentPageSize;
				plugin._maxSize = size;
				_this.endIdx = _this.endIdx >= size ? (size - 1) : _this.endIdx;
				if(_this.startIdx > size && size !== 0){
					grid._pending_requests[req.start] = false;
					plugin.firstPage();
				}
				plugin._paginator._update();
				req.onBegin = onBegin;
				req.onBegin.call(scope, Math.min(plugin._currentPageSize, (size - _this.startIdx)), req);
			};
		}
		return lang.hitch(this._store, this._originFetch)(request);
	}
});

var stopEvent = function(evt){
	try{
		event.stop(evt);
	}catch(e){}
};

var _Focus = declare("dojox.grid.enhanced.plugins.pagination._Focus", null, {
	_focusedNode: null,
	_isFocused: false,
	constructor: function(paginator){
		this._pager = paginator;
		var focusMgr =  paginator.plugin.grid.focus;
		paginator.plugin.connect(paginator, 'onSwitchPageSize', lang.hitch(this, '_onActive'));
		paginator.plugin.connect(paginator, 'onPageStep', lang.hitch(this, '_onActive'));
		paginator.plugin.connect(paginator, 'onShowGotoPageDialog', lang.hitch(this, '_onActive'));
		paginator.plugin.connect(paginator, '_update', lang.hitch(this, '_moveFocus'));
	},
	_onFocus: function(evt, step){
		var node, nodes;
		if(!this._isFocused){
			node = this._focusedNode || query('[tabindex]', this._pager.domNode)[0];
		}else if(step && this._focusedNode){
			var dir = step > 0 ? -1 : 1,
				tabindex = parseInt(this._focusedNode.getAttribute('tabindex'), 10) + dir;
			while(tabindex >= -3 && tabindex < 0){
				node = query('[tabindex=' + tabindex + ']', this._pager.domNode)[0];
				if(node){
					break;<commit_msg>Fixes #15276 !strict, a sane check before stopEvent()<commit_after>define([
	"dojo/_base/kernel",
	"dojo/_base/declare",
	"dojo/_base/array",
	"dojo/_base/connect",
	"dojo/_base/lang",
	"dojo/_base/html",
	"dojo/_base/event",
	"dojo/query",
	"dojo/string",
	"dojo/keys",
	"dojo/text!../templates/Pagination.html",
	"./Dialog",
	"./_StoreLayer",
	"../_Plugin",
	"../../EnhancedGrid",
	"dijit/form/Button",
	"dijit/form/NumberTextBox",
	"dijit/focus",
	"dijit/_Widget",
	"dijit/_TemplatedMixin",
	"dijit/_WidgetsInTemplateMixin",
	"dojox/html/metrics",
	"dojo/i18n!../nls/Pagination"
], function(kernel, declare, array, connect, lang, html, event, query,
	string, keys, template, Dialog, layers, _Plugin, EnhancedGrid,
	Button, NumberTextBox, dijitFocus, _Widget, _TemplatedMixin, _WidgetsInTemplateMixin, metrics, nls){
		
var _GotoPagePane = declare("dojox.grid.enhanced.plugins.pagination._GotoPagePane", [_Widget, _TemplatedMixin, _WidgetsInTemplateMixin], {
	templateString: "<div>" + 
						"<div class='dojoxGridDialogMargin' dojoAttachPoint='_mainMsgNode'></div>" +
						"<div class='dojoxGridDialogMargin'>" +
							"<input dojoType='dijit.form.NumberTextBox' style='width: 50px;' dojoAttachPoint='_pageInputBox' dojoAttachEvent='onKeyUp: _onKey'></input>" +
							"<label dojoAttachPoint='_pageLabelNode'></label>" +
						"</div>" +
						"<div class='dojoxGridDialogButton'>" +
							"<button dojoType='dijit.form.Button' dojoAttachPoint='_confirmBtn' dojoAttachEvent='onClick: _onConfirm'></button>" +
							"<button dojoType='dijit.form.Button' dojoAttachPoint='_cancelBtn' dojoAttachEvent='onClick: _onCancel'></button>" +
						"</div>" +
					"</div>",
	widgetsInTemplate: true,
	dlg: null,
	postMixInProperties: function(){
		this.plugin = this.dlg.plugin;
	},
	postCreate: function(){
		this.inherited(arguments);
		this._mainMsgNode.innerHTML = this.plugin._nls[12];
		this._confirmBtn.set("label", this.plugin._nls[14]);
		this._confirmBtn.set("disabled", true);
		this._cancelBtn.set("label", this.plugin._nls[15]);
	},
	_onConfirm: function(evt){
		if(this._pageInputBox.isValid() && this._pageInputBox.getDisplayedValue() !== ""){
			this.plugin.currentPage(this._pageInputBox.parse(this._pageInputBox.getDisplayedValue()));
			this.dlg._gotoPageDialog.hide();
			this._pageInputBox.reset();
		}
		stopEvent(evt);
	},
	_onCancel: function(evt){
		this._pageInputBox.reset();
		this.dlg._gotoPageDialog.hide();
		stopEvent(evt);
	},
	_onKey: function(evt){
		this._confirmBtn.set("disabled", !this._pageInputBox.isValid() || this._pageInputBox.getDisplayedValue() == "");
		if(!evt.altKey && !evt.metaKey && evt.keyCode === keys.ENTER){
			this._onConfirm(evt);
		}
	}
});

var _GotoPageDialog = declare("dojox.grid.enhanced.plugins.pagination._GotoPageDialog", null, {
	pageCount: 0,
	dlgPane: null,
	constructor: function(plugin){
		this.plugin = plugin;
		this.dlgPane = new _GotoPagePane({"dlg": this});
		this.dlgPane.startup();
		this._gotoPageDialog = new Dialog({
			"refNode": plugin.grid.domNode,
			"title": this.plugin._nls[11],
			"content": this.dlgPane
		});
		this._gotoPageDialog.startup();
	},
	_updatePageCount: function(){
		this.pageCount = this.plugin.getTotalPageNum();
		this.dlgPane._pageInputBox.constraints = {fractional:false, min:1, max:this.pageCount};
		this.dlgPane._pageLabelNode.innerHTML = string.substitute(this.plugin._nls[13], [this.pageCount]);
	},
	showDialog: function(){
		this._updatePageCount();
		this._gotoPageDialog.show();
	},
	destroy: function(){
		this._gotoPageDialog.destroy();
	}
});

var _ForcedPageStoreLayer = declare("dojox.grid.enhanced.plugins._ForcedPageStoreLayer", layers._StoreLayer, {
	tags: ["presentation"],
	constructor: function(plugin){
		this._plugin = plugin;
	},
	_fetch: function(request){
		var _this = this,
			plugin = _this._plugin,
			grid = plugin.grid,
			scope = request.scope || kernel.global,
			onBegin = request.onBegin;
		request.start = (plugin._currentPage - 1) * plugin._currentPageSize + request.start;
		_this.startIdx = request.start;
		_this.endIdx = request.start + plugin._currentPageSize - 1;
		var p = plugin._paginator;
		if(!plugin._showAll){
			plugin._showAll = !p.sizeSwitch && !p.pageStepper && !p.gotoButton;
		}
		if(onBegin && plugin._showAll){
			request.onBegin = function(size, req){
				plugin._maxSize = plugin._currentPageSize = size;
				_this.startIdx = 0;
				_this.endIdx = size - 1;
				plugin._paginator._update();
				req.onBegin = onBegin;
				req.onBegin.call(scope, size, req);
			};
		}else if(onBegin){
			request.onBegin = function(size, req){
				req.start = 0;
				req.count = plugin._currentPageSize;
				plugin._maxSize = size;
				_this.endIdx = _this.endIdx >= size ? (size - 1) : _this.endIdx;
				if(_this.startIdx > size && size !== 0){
					grid._pending_requests[req.start] = false;
					plugin.firstPage();
				}
				plugin._paginator._update();
				req.onBegin = onBegin;
				req.onBegin.call(scope, Math.min(plugin._currentPageSize, (size - _this.startIdx)), req);
			};
		}
		return lang.hitch(this._store, this._originFetch)(request);
	}
});

var stopEvent = function(evt){
	try{
		if(evt){
			event.stop(evt);
		}
	}catch(e){}
};

var _Focus = declare("dojox.grid.enhanced.plugins.pagination._Focus", null, {
	_focusedNode: null,
	_isFocused: false,
	constructor: function(paginator){
		this._pager = paginator;
		var focusMgr =  paginator.plugin.grid.focus;
		paginator.plugin.connect(paginator, 'onSwitchPageSize', lang.hitch(this, '_onActive'));
		paginator.plugin.connect(paginator, 'onPageStep', lang.hitch(this, '_onActive'));
		paginator.plugin.connect(paginator, 'onShowGotoPageDialog', lang.hitch(this, '_onActive'));
		paginator.plugin.connect(paginator, '_update', lang.hitch(this, '_moveFocus'));
	},
	_onFocus: function(evt, step){
		var node, nodes;
		if(!this._isFocused){
			node = this._focusedNode || query('[tabindex]', this._pager.domNode)[0];
		}else if(step && this._focusedNode){
			var dir = step > 0 ? -1 : 1,
				tabindex = parseInt(this._focusedNode.getAttribute('tabindex'), 10) + dir;
			while(tabindex >= -3 && tabindex < 0){
				node = query('[tabindex=' + tabindex + ']', this._pager.domNode)[0];
				if(node){
					break;
{'fraction_non_alphanumeric': 0.1692493946731235, 'fraction_numerical': 0.005569007263922518, 'mean_word_length': 4.6657521719250115, 'pattern_counts': {'":': 8, '<': 37, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4805182', 'n_tokens_mistral': 4893, 'n_tokens_neox': 4435, 'n_words': 685}