Browse Source

Remove BrowserInterface.

Herbert Vojčík 9 years ago
parent
commit
a8ec4e72a7
4 changed files with 24 additions and 344 deletions
  1. 0 187
      src/Platform-Browser.js
  2. 0 53
      src/Platform-Browser.st
  3. 18 81
      src/Platform-Services.js
  4. 6 23
      src/Platform-Services.st

+ 0 - 187
src/Platform-Browser.js

@@ -4,193 +4,6 @@ $core.addPackage('Platform-Browser');
 $core.packages["Platform-Browser"].innerEval = function (expr) { return eval(expr); };
 $core.packages["Platform-Browser"].transport = {"type":"amd","amdNamespace":"amber_core"};
 
-$core.addClass('BrowserInterface', $globals.Object, [], 'Platform-Browser');
-//>>excludeStart("ide", pragmas.excludeIdeData);
-$globals.BrowserInterface.comment="I am platform interface class that tries to use window and jQuery; that is, one for browser environment.\x0a\x0a## API\x0a\x0a    self isAvailable. \x22true if window and jQuery exist\x22.\x0a\x0a    self alert: 'Hey, there is a problem'.\x0a    self confirm: 'Affirmative?'.\x0a    self prompt: 'Your name:'.\x0a\x0a    self ajax: #{\x0a        'url' -> '/patch.js'. 'type' -> 'GET'. dataType->'script'\x0a    }.";
-//>>excludeEnd("ide");
-$core.addMethod(
-$core.method({
-selector: "ajax:",
-protocol: 'actions',
-fn: function (anObject){
-var self=this;
-function $JQuery(){return $globals.JQuery||(typeof JQuery=="undefined"?nil:JQuery)}
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-return $core.withContext(function($ctx1) {
-//>>excludeEnd("ctx");
-var $1,$receiver;
-self._deprecatedAPI_("Use newXhr or dedicated library.");
-if(($receiver = $JQuery()) == null || $receiver.isNil){
-$1=self._error_("JQuery wrapper not loaded, cannot do AJAX.");
-} else {
-$1=$recv($recv($JQuery())._current())._ajax_(anObject);
-};
-return $1;
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx1) {$ctx1.fill(self,"ajax:",{anObject:anObject},$globals.BrowserInterface)});
-//>>excludeEnd("ctx");
-},
-//>>excludeStart("ide", pragmas.excludeIdeData);
-args: ["anObject"],
-source: "ajax: anObject\x0a\x09self deprecatedAPI: 'Use newXhr or dedicated library.'.\x0a\x09^ JQuery\x0a\x09\x09ifNil: [ self error: 'JQuery wrapper not loaded, cannot do AJAX.' ]\x0a\x09\x09ifNotNil: [ JQuery current ajax: anObject ]",
-referencedClasses: ["JQuery"],
-//>>excludeEnd("ide");
-messageSends: ["deprecatedAPI:", "ifNil:ifNotNil:", "error:", "ajax:", "current"]
-}),
-$globals.BrowserInterface);
-
-$core.addMethod(
-$core.method({
-selector: "alert:",
-protocol: 'actions',
-fn: function (aString){
-var self=this;
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-return $core.withContext(function($ctx1) {
-//>>excludeEnd("ctx");
-var $1;
-$1=$recv(window)._alert_(aString);
-return $1;
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx1) {$ctx1.fill(self,"alert:",{aString:aString},$globals.BrowserInterface)});
-//>>excludeEnd("ctx");
-},
-//>>excludeStart("ide", pragmas.excludeIdeData);
-args: ["aString"],
-source: "alert: aString\x0a\x09^ window alert: aString",
-referencedClasses: [],
-//>>excludeEnd("ide");
-messageSends: ["alert:"]
-}),
-$globals.BrowserInterface);
-
-$core.addMethod(
-$core.method({
-selector: "confirm:",
-protocol: 'actions',
-fn: function (aString){
-var self=this;
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-return $core.withContext(function($ctx1) {
-//>>excludeEnd("ctx");
-var $1;
-$1=$recv(window)._confirm_(aString);
-return $1;
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx1) {$ctx1.fill(self,"confirm:",{aString:aString},$globals.BrowserInterface)});
-//>>excludeEnd("ctx");
-},
-//>>excludeStart("ide", pragmas.excludeIdeData);
-args: ["aString"],
-source: "confirm: aString\x0a\x09^ window confirm: aString",
-referencedClasses: [],
-//>>excludeEnd("ide");
-messageSends: ["confirm:"]
-}),
-$globals.BrowserInterface);
-
-$core.addMethod(
-$core.method({
-selector: "isAvailable",
-protocol: 'testing',
-fn: function (){
-var self=this;
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-return $core.withContext(function($ctx1) {
-//>>excludeEnd("ctx");
-return typeof window !== "undefined" && typeof jQuery !== "undefined";
-return self;
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx1) {$ctx1.fill(self,"isAvailable",{},$globals.BrowserInterface)});
-//>>excludeEnd("ctx");
-},
-//>>excludeStart("ide", pragmas.excludeIdeData);
-args: [],
-source: "isAvailable\x0a<return typeof window !== \x22undefined\x22 && typeof jQuery !== \x22undefined\x22>",
-referencedClasses: [],
-//>>excludeEnd("ide");
-messageSends: []
-}),
-$globals.BrowserInterface);
-
-$core.addMethod(
-$core.method({
-selector: "newXhr",
-protocol: 'actions',
-fn: function (){
-var self=this;
-function $XMLHttpRequest(){return $globals.XMLHttpRequest||(typeof XMLHttpRequest=="undefined"?nil:XMLHttpRequest)}
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-return $core.withContext(function($ctx1) {
-//>>excludeEnd("ctx");
-var $1;
-$1=$recv($XMLHttpRequest())._new();
-return $1;
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx1) {$ctx1.fill(self,"newXhr",{},$globals.BrowserInterface)});
-//>>excludeEnd("ctx");
-},
-//>>excludeStart("ide", pragmas.excludeIdeData);
-args: [],
-source: "newXhr\x0a\x09^ XMLHttpRequest new",
-referencedClasses: ["XMLHttpRequest"],
-//>>excludeEnd("ide");
-messageSends: ["new"]
-}),
-$globals.BrowserInterface);
-
-$core.addMethod(
-$core.method({
-selector: "prompt:",
-protocol: 'actions',
-fn: function (aString){
-var self=this;
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-return $core.withContext(function($ctx1) {
-//>>excludeEnd("ctx");
-var $1;
-$1=$recv(window)._prompt_(aString);
-return $1;
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx1) {$ctx1.fill(self,"prompt:",{aString:aString},$globals.BrowserInterface)});
-//>>excludeEnd("ctx");
-},
-//>>excludeStart("ide", pragmas.excludeIdeData);
-args: ["aString"],
-source: "prompt: aString\x0a\x09^ window prompt: aString",
-referencedClasses: [],
-//>>excludeEnd("ide");
-messageSends: ["prompt:"]
-}),
-$globals.BrowserInterface);
-
-$core.addMethod(
-$core.method({
-selector: "prompt:default:",
-protocol: 'actions',
-fn: function (aString,defaultString){
-var self=this;
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-return $core.withContext(function($ctx1) {
-//>>excludeEnd("ctx");
-var $1;
-$1=$recv(window)._prompt_default_(aString,defaultString);
-return $1;
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx1) {$ctx1.fill(self,"prompt:default:",{aString:aString,defaultString:defaultString},$globals.BrowserInterface)});
-//>>excludeEnd("ctx");
-},
-//>>excludeStart("ide", pragmas.excludeIdeData);
-args: ["aString", "defaultString"],
-source: "prompt: aString default: defaultString\x0a\x09^ window prompt: aString default: defaultString",
-referencedClasses: [],
-//>>excludeEnd("ide");
-messageSends: ["prompt:default:"]
-}),
-$globals.BrowserInterface);
-
-
-
 $core.addClass('BrowserTerminal', $globals.Object, [], 'Platform-Browser');
 //>>excludeStart("ide", pragmas.excludeIdeData);
 $globals.BrowserTerminal.comment="I am `Terminal` service implementation for browser.";

+ 0 - 53
src/Platform-Browser.st

@@ -1,57 +1,4 @@
 Smalltalk createPackage: 'Platform-Browser'!
-Object subclass: #BrowserInterface
-	instanceVariableNames: ''
-	package: 'Platform-Browser'!
-!BrowserInterface commentStamp!
-I am platform interface class that tries to use window and jQuery; that is, one for browser environment.
-
-## API
-
-    self isAvailable. "true if window and jQuery exist".
-
-    self alert: 'Hey, there is a problem'.
-    self confirm: 'Affirmative?'.
-    self prompt: 'Your name:'.
-
-    self ajax: #{
-        'url' -> '/patch.js'. 'type' -> 'GET'. dataType->'script'
-    }.!
-
-!BrowserInterface methodsFor: 'actions'!
-
-ajax: anObject
-	self deprecatedAPI: 'Use newXhr or dedicated library.'.
-	^ JQuery
-		ifNil: [ self error: 'JQuery wrapper not loaded, cannot do AJAX.' ]
-		ifNotNil: [ JQuery current ajax: anObject ]
-!
-
-alert: aString
-	^ window alert: aString
-!
-
-confirm: aString
-	^ window confirm: aString
-!
-
-newXhr
-	^ XMLHttpRequest new
-!
-
-prompt: aString
-	^ window prompt: aString
-!
-
-prompt: aString default: defaultString
-	^ window prompt: aString default: defaultString
-! !
-
-!BrowserInterface methodsFor: 'testing'!
-
-isAvailable
-<return typeof window !!== "undefined" && typeof jQuery !!== "undefined">
-! !
-
 Object subclass: #BrowserTerminal
 	instanceVariableNames: ''
 	package: 'Platform-Browser'!

+ 18 - 81
src/Platform-Services.js

@@ -1518,16 +1518,16 @@ selector: "ajax:",
 protocol: 'actions',
 fn: function (anObject){
 var self=this;
+function $JQuery(){return $globals.JQuery||(typeof JQuery=="undefined"?nil:JQuery)}
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx1) {
 //>>excludeEnd("ctx");
-var $2,$1,$receiver;
+var $1,$receiver;
 self._deprecatedAPI_("Use newXhr or dedicated library.");
-$2=self["@worker"];
-if(($receiver = $2) == null || $receiver.isNil){
-$1=self._error_("ajax: not available");
+if(($receiver = $JQuery()) == null || $receiver.isNil){
+$1=self._error_("JQuery wrapper not loaded, cannot do AJAX.");
 } else {
-$1=$recv(self["@worker"])._ajax_(anObject);
+$1=$recv($recv($JQuery())._current())._ajax_(anObject);
 };
 return $1;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
@@ -1536,10 +1536,10 @@ return $1;
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: ["anObject"],
-source: "ajax: anObject\x0a\x09self deprecatedAPI: 'Use newXhr or dedicated library.'.\x0a\x09^ worker\x0a\x09\x09ifNotNil: [ worker ajax: anObject ]\x0a\x09\x09ifNil: [ self error: 'ajax: not available' ]",
-referencedClasses: [],
+source: "ajax: anObject\x0a\x09self deprecatedAPI: 'Use newXhr or dedicated library.'.\x0a\x09^ JQuery\x0a\x09\x09ifNotNil: [ JQuery current ajax: anObject ]\x0a\x09\x09ifNil: [ self error: 'JQuery wrapper not loaded, cannot do AJAX.' ]",
+referencedClasses: ["JQuery"],
 //>>excludeEnd("ide");
-messageSends: ["deprecatedAPI:", "ifNotNil:ifNil:", "ajax:", "error:"]
+messageSends: ["deprecatedAPI:", "ifNotNil:ifNil:", "ajax:", "current", "error:"]
 }),
 $globals.PlatformInterface.klass);
 
@@ -1653,78 +1653,34 @@ messageSends: []
 }),
 $globals.PlatformInterface.klass);
 
-$core.addMethod(
-$core.method({
-selector: "initialize",
-protocol: 'initialization',
-fn: function (){
-var self=this;
-var candidate;
-function $BrowserInterface(){return $globals.BrowserInterface||(typeof BrowserInterface=="undefined"?nil:BrowserInterface)}
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-return $core.withContext(function($ctx1) {
-//>>excludeEnd("ctx");
-var $1,$receiver;
-(
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-$ctx1.supercall = true, 
-//>>excludeEnd("ctx");
-$globals.PlatformInterface.klass.superclass.fn.prototype._initialize.apply($recv(self), []));
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-$ctx1.supercall = false;
-//>>excludeEnd("ctx");;
-if(($receiver = $BrowserInterface()) == null || $receiver.isNil){
-$BrowserInterface();
-} else {
-candidate=$recv($BrowserInterface())._new();
-candidate;
-$1=$recv(candidate)._isAvailable();
-if($core.assert($1)){
-self._setWorker_(candidate);
-return self;
-};
-};
-return self;
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx1) {$ctx1.fill(self,"initialize",{candidate:candidate},$globals.PlatformInterface.klass)});
-//>>excludeEnd("ctx");
-},
-//>>excludeStart("ide", pragmas.excludeIdeData);
-args: [],
-source: "initialize\x0a\x09| candidate |\x0a\x09\x0a\x09super initialize.\x0a\x09\x0a\x09BrowserInterface ifNotNil: [\x0a\x09\x09candidate := BrowserInterface new.\x0a\x09\x09candidate isAvailable ifTrue: [ self setWorker: candidate. ^ self ]\x0a\x09]",
-referencedClasses: ["BrowserInterface"],
-//>>excludeEnd("ide");
-messageSends: ["initialize", "ifNotNil:", "new", "ifTrue:", "isAvailable", "setWorker:"]
-}),
-$globals.PlatformInterface.klass);
-
 $core.addMethod(
 $core.method({
 selector: "newXhr",
 protocol: 'actions',
 fn: function (){
 var self=this;
+function $XMLHttpRequest(){return $globals.XMLHttpRequest||(typeof XMLHttpRequest=="undefined"?nil:XMLHttpRequest)}
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx1) {
 //>>excludeEnd("ctx");
-var $2,$1,$receiver;
-$2=self["@worker"];
-if(($receiver = $2) == null || $receiver.isNil){
-$1=self._error_("newXhr: not available");
+var $1,$receiver;
+if(($receiver = $XMLHttpRequest()) == null || $receiver.isNil){
+self._error_("XMLHttpRequest not available.");
 } else {
-$1=$recv(self["@worker"])._newXhr();
-};
+$1=$recv($XMLHttpRequest())._new();
 return $1;
+};
+return self;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 }, function($ctx1) {$ctx1.fill(self,"newXhr",{},$globals.PlatformInterface.klass)});
 //>>excludeEnd("ctx");
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: [],
-source: "newXhr\x0a\x09^ worker\x0a\x09\x09ifNotNil: [ worker newXhr ]\x0a\x09\x09ifNil: [ self error: 'newXhr: not available' ]",
-referencedClasses: [],
+source: "newXhr\x0a\x09XMLHttpRequest\x0a\x09\x09ifNotNil: [ ^ XMLHttpRequest new ]\x0a\x09\x09ifNil: [ self error: 'XMLHttpRequest not available.' ]",
+referencedClasses: ["XMLHttpRequest"],
 //>>excludeEnd("ide");
-messageSends: ["ifNotNil:ifNil:", "newXhr", "error:"]
+messageSends: ["ifNotNil:ifNil:", "new", "error:"]
 }),
 $globals.PlatformInterface.klass);
 
@@ -1782,25 +1738,6 @@ messageSends: ["deprecatedAPI:", "prompt:default:"]
 }),
 $globals.PlatformInterface.klass);
 
-$core.addMethod(
-$core.method({
-selector: "setWorker:",
-protocol: 'accessing',
-fn: function (anObject){
-var self=this;
-self["@worker"]=anObject;
-return self;
-
-},
-//>>excludeStart("ide", pragmas.excludeIdeData);
-args: ["anObject"],
-source: "setWorker: anObject\x0a\x09worker := anObject",
-referencedClasses: [],
-//>>excludeEnd("ide");
-messageSends: []
-}),
-$globals.PlatformInterface.klass);
-
 
 $core.addClass('Service', $globals.Object, [], 'Platform-Services');
 //>>excludeStart("ide", pragmas.excludeIdeData);

+ 6 - 23
src/Platform-Services.st

@@ -365,19 +365,15 @@ PlatformInterface class instanceVariableNames: 'worker'!
 
 globals
 	<return (new Function('return this'))();>
-!
-
-setWorker: anObject
-	worker := anObject
 ! !
 
 !PlatformInterface class methodsFor: 'actions'!
 
 ajax: anObject
 	self deprecatedAPI: 'Use newXhr or dedicated library.'.
-	^ worker
-		ifNotNil: [ worker ajax: anObject ]
-		ifNil: [ self error: 'ajax: not available' ]
+	^ JQuery
+		ifNotNil: [ JQuery current ajax: anObject ]
+		ifNil: [ self error: 'JQuery wrapper not loaded, cannot do AJAX.' ]
 !
 
 alert: aString
@@ -398,9 +394,9 @@ existsGlobal: aString
 !
 
 newXhr
-	^ worker
-		ifNotNil: [ worker newXhr ]
-		ifNil: [ self error: 'newXhr: not available' ]
+	XMLHttpRequest
+		ifNotNil: [ ^ XMLHttpRequest new ]
+		ifNil: [ self error: 'XMLHttpRequest not available.' ]
 !
 
 prompt: aString
@@ -413,19 +409,6 @@ prompt: aString default: defaultString
 	^ Terminal prompt: aString default: defaultString
 ! !
 
-!PlatformInterface class methodsFor: 'initialization'!
-
-initialize
-	| candidate |
-	
-	super initialize.
-	
-	BrowserInterface ifNotNil: [
-		candidate := BrowserInterface new.
-		candidate isAvailable ifTrue: [ self setWorker: candidate. ^ self ]
-	]
-! !
-
 Object subclass: #Service
 	instanceVariableNames: ''
 	package: 'Platform-Services'!