00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 if (typeof window["CPPlatformEnableHTMLDragAndDrop"] === "undefined")
00024 CPPlatformEnableHTMLDragAndDrop = NO;
00025
00026 CPPlatformDidClearBodyElementNotification = @"CPPlatformDidClearBodyElementNotification";
00027 CPPlatformWillClearBodyElementNotification = @"CPPlatformWillClearBodyElementNotification";
00028
00029 var screenNeedsInitialization = NO,
00030 mainBodyElement = nil,
00031 elementRemovalTest = new RegExp("\\bcpdontremove\\b", "g");
00032
00033 @implementation CPPlatform : CPBasePlatform
00034 {
00035 }
00036
00037 + (void)initialize
00038 {
00039 if (self !== [CPPlatform class])
00040 return;
00041
00042 screenNeedsInitialization = [CPPlatform isBrowser];
00043
00044
00045 if (document.documentElement)
00046 document.documentElement.style.overflow = "hidden";
00047 }
00048
00049 + (BOOL)isBrowser
00050 {
00051 return typeof window.cpIsDesktop === "undefined";
00052 }
00053
00054 + (BOOL)supportsDragAndDrop
00055 {
00056 return CPFeatureIsCompatible(CPHTMLDragAndDropFeature) && (CPPlatformEnableHTMLDragAndDrop || ![self isBrowser]);
00057 }
00058
00059 + (BOOL)supportsNativeMainMenu
00060 {
00061 return (typeof window["cpSetMainMenu"] === "function");
00062 }
00063
00064 + (void)terminateApplication
00065 {
00066 if (typeof window["cpTerminate"] === "function")
00067 window.cpTerminate();
00068 }
00069
00070 + (void)activateIgnoringOtherApps:(BOOL)shouldIgnoreOtherApps
00071 {
00072 if (typeof window["cpActivateIgnoringOtherApps"] === "function")
00073 window.cpActivateIgnoringOtherApps(!!shouldIgnoreOtherApps);
00074 }
00075
00076 + (void)deactivate
00077 {
00078 if (typeof window["cpDeactivate"] === "function")
00079 window.cpDeactivate();
00080 }
00081
00082 + (void)hideOtherApplications:(id)aSender
00083 {
00084 if (typeof window["cpHideOtherApplications"] === "function")
00085 window.cpHideOtherApplications();
00086 }
00087
00088 + (void)hide:(id)aSender
00089 {
00090 if (typeof window["cpHide"] === "function")
00091 window.cpHide();
00092 }
00093
00094 + (DOMElement)mainBodyElement
00095 {
00096 if (!mainBodyElement)
00097 mainBodyElement = document.getElementById("cappuccino-body") || document.body;
00098
00099 return mainBodyElement;
00100 }
00101
00102 + (void)initializeScreenIfNecessary
00103 {
00104 if (!screenNeedsInitialization)
00105 return;
00106
00107 screenNeedsInitialization = NO;
00108
00109 [[CPNotificationCenter defaultCenter]
00110 postNotificationName:CPPlatformWillClearBodyElementNotification
00111 object:self];
00112
00113 var bodyElement = [self mainBodyElement];
00114
00115
00116 var children = bodyElement.childNodes,
00117 length = children.length;
00118
00119 while (length--)
00120 {
00121 var element = children[length];
00122 if (!element.className || element.className.match(elementRemovalTest) === null)
00123 bodyElement.removeChild(element);
00124 }
00125
00126 bodyElement.style.overflow = "hidden";
00127
00128 [[CPNotificationCenter defaultCenter]
00129 postNotificationName:CPPlatformDidClearBodyElementNotification
00130 object:self];
00131 }
00132
00133 @end