Skip to content

Commit

Permalink
new javascript files... about to doc them again
Browse files Browse the repository at this point in the history
all the docs are redone and build / doc is ready with the rakefile

Trying to align JS with HTML5 Spec

Added New JS
  • Loading branch information
dave johnson authored and sintaxi committed Feb 27, 2009
1 parent 6c1e194 commit 765481a
Show file tree
Hide file tree
Showing 147 changed files with 16,983 additions and 272 deletions.
109 changes: 70 additions & 39 deletions Rakefile
@@ -1,50 +1,81 @@
require 'rubygems'
require "hpricot"
LIBPATH = File.expand_path(File.dirname(__FILE__)) + File::SEPARATOR

#
# builds and tests
#
desc 'writes lib/phonegap.js and lib/phonegap-min.js and runs docs'
task :default do
build
doc
end

PHONEGAP_WEB_PATH = "iphone/www"
task :doc do
doc
end

namespace :iphone do
task :default => [:import] do
def doc
puts 'writing the full interface source for documentation into tmp/phonegap.js'
final = "#{ LIBPATH }tmp#{ File::SEPARATOR }phonegap.js"
js = ""
interfaces_to_build.each do |lib|
js << import("#{ LIBPATH }javascripts#{ File::SEPARATOR }#{ lib }.js")
end
FileUtils.mkdir_p "#{ LIBPATH }tmp"
open(final,'w'){|f| f.puts( js )}
sh "java -jar util#{ File::SEPARATOR }jsdoc-toolkit#{ File::SEPARATOR }jsrun.jar util#{ File::SEPARATOR }jsdoc-toolkit#{ File::SEPARATOR }app#{ File::SEPARATOR }run.js -a -t=util#{ File::SEPARATOR }jsdoc-toolkit#{ File::SEPARATOR }templates#{ File::SEPARATOR }jsdoc tmp#{ File::SEPARATOR }phonegap.js"
end

desc 'reverts file back to original form'
task :revert do
back = open("#{PHONEGAP_WEB_PATH}/index.back.html").read
File.open("#{PHONEGAP_WEB_PATH}/index.html", "w") {|f| f.puts back}
def build
puts 'writing the full JS file to lib/phonegap.js'
final = "#{ LIBPATH }lib#{ File::SEPARATOR }phonegap.js"
js = ""
platforms_to_build.each do |platform|
interfaces_to_build.each do |interface|
begin
js << import("#{ LIBPATH }javascripts#{ File::SEPARATOR }#{ platform }#{ File::SEPARATOR }#{ interface }.js")
rescue
end
end
end

desc 'backups index.html file'
task :backup do
puts "creating backup file (if needed)"
index = open("#{PHONEGAP_WEB_PATH}/index.html").read
File.open("#{PHONEGAP_WEB_PATH}/index.back.html", "w") {|f| f.write index} unless index.include?("RAKED::")
interfaces_to_build.each do |interface|
js << import("#{ LIBPATH }javascripts#{ File::SEPARATOR }#{ interface }.js")
end

desc 'puts external javascript and css content into index page'
task :import => :backup do
#open backup file
doc = Hpricot(open("#{PHONEGAP_WEB_PATH}/index.back.html"))
FileUtils.mkdir_p "#{ LIBPATH }lib"
open(final,'w'){|f| f.puts( js )}

#find and import stylesheets
(doc/"head/link[@rel='stylesheet']").remove.each do |elem|
path = file elem.attributes['href']
puts " importing stylesheet: #{path}"
css_content = open("#{PHONEGAP_WEB_PATH}/#{path}").read
elem.after("<style type=\"text/css\" media=\"screen\">\n/*RAKED::css file::#{path} */\n" + css_content + "\n</style>\n")
end

#find and import javascripts
doc.search("head/script").remove.each do |elem|
path = file elem.attributes['src']
puts " importing javascript: #{path}"
js_content = open("#{PHONEGAP_WEB_PATH}/#{path}").read
elem.after( "<script type=\"text/javascript\" charset=\"utf-8\">\n//RAKED::javascript file::#{path}\n" + js_content + "\n</script>\n\n")
end

#write and save as index.html
open("#{PHONEGAP_WEB_PATH}/index.html", "w") { |f| f.write doc}
end
min
end

# the sub libraries used by xui
def interfaces_to_build
%w(acceleration accelerometer camera contact file geolocation map notification orientation position sms telephony)
end

# the sub libraries used by xui
def platforms_to_build
%w(android blackberry iphone)
end

# helper for build_sub_libaries
def import(lib)
s = ""
r = ""
open(lib) { |f| s << "\n#{f.read}\n\n" }
s.each_line {|l| r << " #{l}"}
r
end

# creates lib/xui-min.js (tho not obfuscates)
def min
puts 'minifying js'
min_file = "#{ LIBPATH }lib#{ File::SEPARATOR }phonegap-min.js"
doc_file = "#{ LIBPATH }lib#{ File::SEPARATOR }phonegap.js"
sh "java -jar #{LIBPATH}#{ File::SEPARATOR }util#{ File::SEPARATOR }yuicompressor-2.4.2.jar --charset UTF-8 -o #{min_file} #{doc_file}"
end

# opens up the specs
def spec
puts 'running automated test suite'
#sh "open -a WebKit file://#{ LIBPATH }/spec/index.html"
#sh "open -a '/Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone Simulator.app' file://#{ LIBPATH }/spec/index.html"
end
4 changes: 2 additions & 2 deletions iphone/Classes/Contacts.m
Expand Up @@ -30,7 +30,7 @@ - (NSMutableString *)getContacts {
allPeople = (NSArray *)ABAddressBookCopyArrayOfAllPeople(self.addressBook);
CFIndex nPeople = ABAddressBookGetPersonCount(self.addressBook);

[update appendString:@"gap_contacts = ["];
[update appendString:@"var Contacts = function() { return ["];

for (int i=0;i < numberOfPeople;i++) {
ABRecordRef ref = CFArrayGetValueAtIndex(allPeople,i);
Expand All @@ -53,7 +53,7 @@ - (NSMutableString *)getContacts {
}
}

[update appendString:@"];"];
[update appendString:@"]; };"];
}
return update;
}
Expand Down
22 changes: 12 additions & 10 deletions iphone/Classes/Device.m
Expand Up @@ -24,16 +24,18 @@ - (NSString *)init{
jsCallBack = nil;
myCurrentDevice = [UIDevice currentDevice];

return jsCallBack = [[NSString alloc] initWithFormat:@"\
__gap = true; \
__gap_version='0.2'; \
__gap_device_model='%s'; \
__gap_device_version='%s';\
__gap_device_uniqueid='%s';",
[[myCurrentDevice model] UTF8String],
[[myCurrentDevice systemVersion] UTF8String],
[[myCurrentDevice uniqueIdentifier] UTF8String]
];
// return jsCallBack = [[NSString alloc] initWithFormat:@"\
// __gap = true; \
// __gap_version='0.2'; \
// __gap_device_model='%s'; \
// __gap_device_version='%s';\
// __gap_device_uniqueid='%s';",
// [[myCurrentDevice model] UTF8String],
// [[myCurrentDevice systemVersion] UTF8String],
// [[myCurrentDevice uniqueIdentifier] UTF8String]
// ];

return [[NSString alloc] initWithFormat:@"Device={};Device.platform = '%s';",[[myCurrentDevice model] UTF8String]];
}

- (void)dealloc {
Expand Down
37 changes: 29 additions & 8 deletions iphone/Classes/GlassAppDelegate.m
Expand Up @@ -23,7 +23,11 @@ void alert(NSString *message) {

- (void)applicationDidFinishLaunching:(UIApplication *)application {

/*
* Fire up the GPS Service right away as it takes a moment for data to come back.
*/
[[Location sharedInstance].locationManager startUpdatingLocation];


webView.delegate = self;

Expand All @@ -33,7 +37,6 @@ - (void)applicationDidFinishLaunching:(UIApplication *)application {
imagePickerController.delegate = self;
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePickerController.view.hidden = YES;
//[window addSubview:imagePickerController.view];

[[UIAccelerometer sharedAccelerometer] setUpdateInterval:1.0/40.0];
[[UIAccelerometer sharedAccelerometer] setDelegate:self];
Expand Down Expand Up @@ -85,6 +88,9 @@ - (void)applicationDidFinishLaunching:(UIApplication *)application {
imageView = [[UIImageView alloc] initWithImage:tempImage];
[window addSubview:imageView];

/*
* This is the Battery View bar at the top
*/
activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
[window addSubview:activityView];
[activityView startAnimating];
Expand All @@ -94,15 +100,26 @@ - (void)applicationDidFinishLaunching:(UIApplication *)application {


/*
* When web application loads pass it device information
*
* When web application loads Add stuff to the DOM (HTML 5)
*/
- (void)webViewDidStartLoad:(UIWebView *)theWebView {
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;

Device * device = [[Device alloc] init];
[theWebView stringByEvaluatingJavaScriptFromString:[device getDeviceInfo]];
[device release];
/*
* This is the Device.plaftorm information
*/
[theWebView stringByEvaluatingJavaScriptFromString:[[Device alloc] init]];

/*
* We want to Add Contact to the DOM on init.
*/
NSString * jsCallBack = nil;
Contacts *contacts = [[Contacts alloc] init];
jsCallBack = [contacts getContacts];
NSLog(@"%@",jsCallBack);
[webView stringByEvaluatingJavaScriptFromString:jsCallBack];

[contacts release];

}

- (void)webViewDidFinishLoad:(UIWebView *)theWebView {
Expand Down Expand Up @@ -235,11 +252,15 @@ - (BOOL)webView:(UIWebView *)theWebView shouldStartLoadWithRequest:(NSURLRequest


- (void) accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration {
NSString * jsCallBack = [NSString stringWithFormat:@"gotAcceleration('%f','%f','%f');", acceleration.x, acceleration.y, acceleration.z];
NSString * jsCallBack = nil;

jsCallBack = [[NSString alloc] initWithFormat:@"navigator.accelerometer._getCurrentAcceleration(%f,%f,%f);", acceleration.x, acceleration.y, acceleration.z];
NSLog(jsCallBack);
[webView stringByEvaluatingJavaScriptFromString:jsCallBack];
}



- (void)imagePickerController:(UIImagePickerController *)thePicker didFinishPickingImage:(UIImage *)theImage editingInfo:(NSDictionary *)editingInfo
{

Expand Down

0 comments on commit 765481a

Please sign in to comment.