Browse Source

Amending "no jQuery needed" optimism.

Herbert Vojčík 9 years ago
parent
commit
1555ba92f0
3 changed files with 13 additions and 16 deletions
  1. 2 1
      CHANGELOG
  2. 8 13
      src/Platform-Browser.js
  3. 3 2
      src/Platform-Browser.st

+ 2 - 1
CHANGELOG

@@ -4,7 +4,8 @@
 Highlights:
 
 * Extraction of `Web` and `Wrappers-JQuery` to own repos.
-* Amber core itself with no production dependencies.
+* Amber core itself formally with no production dependencies, but
+ `PlatformInterface >> ajax:` still needs jQuery wrapper loaded to work.
 
 Commits: https://github.com/amber-smalltalk/amber/compare/0.14.13...0.14.14
 

+ 8 - 13
src/Platform-Browser.js

@@ -1,16 +1,7 @@
-define("amber_core/Platform-Browser", ["amber/boot"
-//>>excludeStart("imports", pragmas.excludeImports);
-, "amber-contrib-jquery/Wrappers-JQuery"
-//>>excludeEnd("imports");
-, "amber_core/Kernel-Objects"], function($boot
-//>>excludeStart("imports", pragmas.excludeImports);
-
-//>>excludeEnd("imports");
-){
+define("amber_core/Platform-Browser", ["amber/boot", "amber_core/Kernel-Objects"], function($boot){
 var $core=$boot.api,nil=$boot.nil,$recv=$boot.asReceiver,$globals=$boot.globals;
 $core.addPackage('Platform-Browser');
 $core.packages["Platform-Browser"].innerEval = function (expr) { return eval(expr); };
-$core.packages["Platform-Browser"].imports = ["amber-contrib-jquery/Wrappers-JQuery"];
 $core.packages["Platform-Browser"].transport = {"type":"amd","amdNamespace":"amber_core"};
 
 $core.addClass('BrowserInterface', $globals.Object, [], 'Platform-Browser');
@@ -27,8 +18,12 @@ function $JQuery(){return $globals.JQuery||(typeof JQuery=="undefined"?nil:JQuer
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx1) {
 //>>excludeEnd("ctx");
-var $1;
+var $1,$receiver;
+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)});
@@ -36,10 +31,10 @@ return $1;
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: ["anObject"],
-source: "ajax: anObject\x0a\x09^ JQuery current ajax: anObject",
+source: "ajax: anObject\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: ["ajax:", "current"]
+messageSends: ["ifNil:ifNotNil:", "error:", "ajax:", "current"]
 }),
 $globals.BrowserInterface);
 

+ 3 - 2
src/Platform-Browser.st

@@ -1,5 +1,4 @@
 Smalltalk createPackage: 'Platform-Browser'!
-(Smalltalk packageAt: 'Platform-Browser') imports: {'amber-contrib-jquery/Wrappers-JQuery'}!
 Object subclass: #BrowserInterface
 	instanceVariableNames: ''
 	package: 'Platform-Browser'!
@@ -21,7 +20,9 @@ I am platform interface class that tries to use window and jQuery; that is, one
 !BrowserInterface methodsFor: 'actions'!
 
 ajax: anObject
-	^ JQuery current ajax: anObject
+	^ JQuery
+		ifNil: [ self error: 'JQuery wrapper not loaded, cannot do AJAX.' ]
+		ifNotNil: [ JQuery current ajax: anObject ]
 !
 
 alert: aString