1
0
Преглед на файлове

helios: prevent parent window scrolling when using the arrow keys in Helios

Nicolas Petton преди 11 години
родител
ревизия
85abef3102
променени са 3 файла, в които са добавени 65 реда и са изтрити 4 реда
  1. 23 1
      js/Helios-Core.deploy.js
  2. 29 2
      js/Helios-Core.js
  3. 13 1
      st/Helios-Core.st

+ 23 - 1
js/Helios-Core.deploy.js

@@ -2922,6 +2922,27 @@ smalltalk.HLManager);
 
 
 smalltalk.HLManager.klass.iVarNames = ['current'];
+smalltalk.addMethod(
+smalltalk.method({
+selector: "clearKeydownEvent",
+fn: function (){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
+var $1;
+_st(_st(window)._jQuery_("body"))._keydown_((function(e){
+return smalltalk.withContext(function($ctx2) {
+$1=_st(_st(_st(e)._keyCode()).__gt_eq((37)))._and_((function(){
+return smalltalk.withContext(function($ctx3) {
+return _st(_st(e)._keyCode()).__lt_eq((40));
+}, function($ctx3) {$ctx3.fillBlock({},$ctx2)})}));
+if(smalltalk.assert($1)){
+return false;
+};
+}, function($ctx2) {$ctx2.fillBlock({e:e},$ctx1)})}));
+return self}, function($ctx1) {$ctx1.fill(self,"clearKeydownEvent",{},smalltalk.HLManager.klass)})},
+messageSends: ["keydown:", "ifTrue:", "and:", "<=", "keyCode", ">=", "jQuery:"]}),
+smalltalk.HLManager.klass);
+
 smalltalk.addMethod(
 smalltalk.method({
 selector: "current",
@@ -2948,8 +2969,9 @@ fn: function (){
 var self=this;
 return smalltalk.withContext(function($ctx1) { 
 _st(_st(self)._current())._appendToJQuery_(_st("body")._asJQuery());
+_st(self)._clearKeydownEvent();
 return self}, function($ctx1) {$ctx1.fill(self,"initialize",{},smalltalk.HLManager.klass)})},
-messageSends: ["appendToJQuery:", "asJQuery", "current"]}),
+messageSends: ["appendToJQuery:", "asJQuery", "current", "clearKeydownEvent"]}),
 smalltalk.HLManager.klass);
 
 smalltalk.addMethod(

+ 29 - 2
js/Helios-Core.js

@@ -3803,6 +3803,32 @@ smalltalk.HLManager);
 
 
 smalltalk.HLManager.klass.iVarNames = ['current'];
+smalltalk.addMethod(
+smalltalk.method({
+selector: "clearKeydownEvent",
+category: 'private',
+fn: function (){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
+var $1;
+_st(_st(window)._jQuery_("body"))._keydown_((function(e){
+return smalltalk.withContext(function($ctx2) {
+$1=_st(_st(_st(e)._keyCode()).__gt_eq((37)))._and_((function(){
+return smalltalk.withContext(function($ctx3) {
+return _st(_st(e)._keyCode()).__lt_eq((40));
+}, function($ctx3) {$ctx3.fillBlock({},$ctx2)})}));
+if(smalltalk.assert($1)){
+return false;
+};
+}, function($ctx2) {$ctx2.fillBlock({e:e},$ctx1)})}));
+return self}, function($ctx1) {$ctx1.fill(self,"clearKeydownEvent",{},smalltalk.HLManager.klass)})},
+args: [],
+source: "clearKeydownEvent\x0a\x09\x22Prevent default keydown event with arrow key from scrolling the parent page\x0a\x09when helios is run inside a frame.\x22\x0a\x09\x0a\x09(window jQuery: 'body') keydown: [ :e | \x0a\x09\x09(e keyCode >= 37 and: [ e keyCode <= 40 ])\x0a\x09\x09\x09ifTrue: [ false ] ]",
+messageSends: ["keydown:", "ifTrue:", "and:", "<=", "keyCode", ">=", "jQuery:"],
+referencedClasses: []
+}),
+smalltalk.HLManager.klass);
+
 smalltalk.addMethod(
 smalltalk.method({
 selector: "current",
@@ -3835,10 +3861,11 @@ fn: function (){
 var self=this;
 return smalltalk.withContext(function($ctx1) { 
 _st(_st(self)._current())._appendToJQuery_(_st("body")._asJQuery());
+_st(self)._clearKeydownEvent();
 return self}, function($ctx1) {$ctx1.fill(self,"initialize",{},smalltalk.HLManager.klass)})},
 args: [],
-source: "initialize\x0a\x09self current appendToJQuery: 'body' asJQuery",
-messageSends: ["appendToJQuery:", "asJQuery", "current"],
+source: "initialize\x0a\x09self current appendToJQuery: 'body' asJQuery.\x0a\x09self clearKeydownEvent",
+messageSends: ["appendToJQuery:", "asJQuery", "current", "clearKeydownEvent"],
 referencedClasses: []
 }),
 smalltalk.HLManager.klass);

+ 13 - 1
st/Helios-Core.st

@@ -1350,7 +1350,8 @@ current
 !HLManager class methodsFor: 'initialization'!
 
 initialize
-	self current appendToJQuery: 'body' asJQuery
+	self current appendToJQuery: 'body' asJQuery.
+	self clearKeydownEvent
 ! !
 
 !HLManager class methodsFor: 'instance creation'!
@@ -1361,6 +1362,17 @@ new
 	self shouldNotImplement
 ! !
 
+!HLManager class methodsFor: 'private'!
+
+clearKeydownEvent
+	"Prevent default keydown event with arrow key from scrolling the parent page
+	when helios is run inside a frame."
+	
+	(window jQuery: 'body') keydown: [ :e | 
+		(e keyCode >= 37 and: [ e keyCode <= 40 ])
+			ifTrue: [ false ] ]
+! !
+
 HLWidget subclass: #HLModalWidget
 	instanceVariableNames: ''
 	package: 'Helios-Core'!