PDA

View Full Version : 0.82 Ext.setup() should check for meta tags before it adds them.



watrboy00
9 Jun 2010, 6:04 PM
I've made comments in red where needed...


Ext.setup = function(config) {
if (Ext.isObject(config)) {
var appendString ='',
viewport = Ext.get(document.createElement('meta')),
app = Ext.get(document.createElement('meta')),
statusBar = Ext.get(document.createElement('meta')),
startupScreen = Ext.get(document.createElement('link')),
appIcon = Ext.get(document.createElement('link'));

//does user-scalable=no, user-scalable=0 translate different on different platforms?
viewport.set({
name: 'viewport',
content: 'width=device-width, user-scalable=no, initial-scale=1.0; maximum-scale=1.0; user-scalable=0;'
});

if (config.fullscreen !== false) {
app.set({
name: 'apple-mobile-web-app-capable',
content: 'yes'
});

if (Ext.isString(config.statusBarStyle)) {
statusBar.set({
name: 'apple-mobile-web-app-status-bar-style',
content: config.statusBarStyle
})
}
}

if (Ext.isString(config.tabletStartupScreen) && Ext.platform.isTablet) {
startupScreen.set({
rel: 'apple-touch-startup-image',
href: config.tabletStartupScreen
});
} else if (Ext.isString(config.phoneStartupScreen) && Ext.platform.isPhone) {
startupScreen.set({
rel: 'apple-touch-startup-image',
href: config.phoneStartupScreen
});
}

if (config.icon) {
config.phoneIcon = config.tabletIcon = config.icon;
}

var precomposed = (config.glossOnIcon == false) ? '-precomposed' : '';
if (Ext.isString(config.tabletIcon) && Ext.platform.isTablet) {
appIcon.set({
rel: 'apple-touch-icon' + precomposed,
href: config.tabletIcon
});
} else if (Ext.isString(config.phoneIcon) && Ext.platform.isPhone) {
appIcon.set({
rel: 'apple-touch-icon' + precomposed,
href: config.phoneIcon
});
}

if (Ext.isArray(config.preloadImages)) {
for (var i = config.preloadImages.length - 1; i >= 0; i--) {
(new Image()).src = config.preloadImages[i];
};
}

//I have an app that is already built that I am layering Touch on top of. Because of this I already have the meta viewport tag setup. With this block it duplicates the tag. Same *could* be said about the others.
var attachTags = function(){
var head = Ext.get(document.getElementsByTagName('head')[0]);
head.appendChild(viewport);
if (app.getAttribute('name')) head.appendChild(app);
if (statusBar.getAttribute('name')) head.appendChild(statusBar);

if (appIcon.getAttribute('href')) head.appendChild(appIcon);
if (startupScreen.getAttribute('href')) head.appendChild(startupScreen);
};

if (Ext.platform.isAndroidOS) {
attachTags();
}
else {
Ext.onReady(attachTags);
}

if (Ext.isFunction(config.onReady)) {
Ext.onReady(config.onReady, config.scope || window);
}
}
};

TommyMaintz
9 Jun 2010, 6:41 PM
Good idea. Will look into doing this.

TommyMaintz
9 Jun 2010, 6:45 PM
For now I have added an addMetaTags configuration option to setup. It defaults to true. Somehow looping over all meta tags and check for attributes felt a bit dirty.

watrboy00
9 Jun 2010, 11:49 PM
I like. Def better than individual checks.

Tommy, any idea about the user-scalable = 0|no? Is it a requirement to have both? Like does 0 only work on iPhone|iPad and no works on Android or something like that?

TommyMaintz
10 Jun 2010, 9:52 AM
No, that was a bug. Also the mixing of semicolons and commas was wrong. This is al
Fixed in the next release.

watrboy00
10 Jun 2010, 1:51 PM
I believe they are suppose to be commas correct? and which one is correct the 0 or the no?

TommyMaintz
10 Jun 2010, 2:37 PM
I think "no" is the correct one, and commas.