I developed a GWT aplication which was initially meant only for Desktop PC browser. Now I decided to make it available also to smartphones and tablets. I created a different .css for each user-agent. Now my question is, how can I decide which of these files to load basing on the type of user-agent? Is this strategy a good one, or there is a better practice?
To swap implementation according to the user-agent, you can use deferred binding, which is a built-in GWT feature.
In you module.gwt.xml type something like:
<module>
...
<inherits name='com.google.gwt.sample.mobilewebapp.FormFactor'/>
...
<!-- Use ClientFactoryImpl by default -->
<replace-with class="com.google.gwt.sample.mobilewebapp.client.ClientFactoryImpl">
<when-type-is class="com.google.gwt.sample.mobilewebapp.client.ClientFactory"/>
</replace-with>
<!-- Use ClientFactoryImplMobile for mobile form factor. -->
<replace-with class="com.google.gwt.sample.mobilewebapp.client.ClientFactoryImplMobile">
<when-type-is class="com.google.gwt.sample.mobilewebapp.client.ClientFactory"/>
<when-property-is name="formfactor" value="mobile"/>
</replace-with>
<!-- Use ClientFactoryImplTablet for tablet form factor. -->
<replace-with class="com.google.gwt.sample.mobilewebapp.client.ClientFactoryImplTablet">
<when-type-is class="com.google.gwt.sample.mobilewebapp.client.ClientFactory"/>
<when-property-is name="formfactor" value="tablet"/>
</replace-with>
</module>
Then just call GWT.create(ClientFactory.class) to get the proper implementation at runtime. For CSS, use a subclass of CSSResource or ClientBundle. Source is here.
I am using mgwt for creating mobile gwt apps.
There is a themeing based on user agent: https://code.google.com/p/mgwt/source/browse/src/main/java/com/googlecode/mgwt/ui/client/theme/MGWTThemeBaseThemeStandardImpl.java
In your Bundle you can seperate different css. If you don't use CssResources you may just use the StyleInjector
Related
We're using the WordPress REST API to power a static site. The site is "headless" in the sense that we don't use a WordPress theme; we rely on the content being exposed via the REST API.
Some of the default Gutenberg blocks - the Buttons block for instance - have styles with hashed class names associated with them that don't seem to be exposed in the API. This would be kind of ok if the class names were predictable but, since they aren't, we have no way of providing the styles on our end.
If we do render the blocks in a theme, the styles are rendered in the footer
Here's an example of the style block for the default Buttons block looks like in a WordPress theme
The Rest API endpoint exposes the markup in content.rendered (including the classnames) but no styles
Is this expected behavior for using Gutenberg and the WordPress REST API? If so, is the correct solution to expose the styles via a custom field (for lack of a better term) on the API?
The unique id (hash) in the classnames are randomly generated each time the blocks are parsed, even when directly calling the REST API. Unfortunately, the inline style attributes like .alignleft are absent from the content markup in the REST API. Being a REST API, it makes sense that style specific information isn't included; this keeps data and presentation of the data separate. It also prevents bloating the API by including style-specific information that would be rarely used outside of WordPress theme.
In your scenario, if you wish to style the resulting HTML content without worrying about the unique id, I'd suggest using css partial selectors, eg:
div[class*="wp-container-"] .wp-block-button{
...
}
Alternatively, as you mentioned, its possbile to extend the REST API to include the styles. While I haven't built a working example of this for styles, when blocks where introduced I ended up extended the REST API to include extra meta data. I'd suggest looking at render_block_data to handle adding in the styles into the content.
Eg. For the buttons block, the serialized content stored in the database as:
<!-- wp:buttons {"layout":{"type":"flex","justifyContent":"center"}} -->
<div class="wp-block-buttons"><!-- wp:button -->
<div class="wp-block-button"><a class="wp-block-button__link">Hello</a></div>
<!-- /wp:button --></div>
<!-- /wp:buttons -->
By using parse_blocks() you can obtain all the block properties into an array and get style information that way. I think this approach is do-able if you just add the generated classnames and not the inline styles. I am keen to know if you find a better way...
I need a solution that meets following requirements:
use a diazo theme based on unstyled(!), Theme base (i.e. "Plone Default") with the URL diazotheme.domain.com
use "Sunburst Theme" (or any other Plone Theme) with the URL "sunburst.domain.com"
It seems that diazo not only uses the Base Theme for the diazo theme but also for the "Unthemed host names". Setting the Base Theme in diazo's "##theming-controlpanel" actually changes the Default skin of the Site.
I've posted a solution using diazo in combination with editskinswitcher: https://stackoverflow.com/a/23130398/1659599. I'd like to know whether this is possible without using editskinswitcher.
Take a look at the collective.behavior.localdiazo package.
You can see it in action in http://www.cfa.org.br/rba site, which has a different theme from http://www.cfa.org.br/ main site.
RBA is an instance of Microsite, a Dexterity-based content type defined in sc.microsite.
you'll definitely need a mechanism to activate different skins for the different parts of you site. editskinswitcher is one choice here.
you could also code your own traverser that applies the correct browserlayer and patches the portal_skins tool.
another approach is to allow skin selection in portal_skins and set the skin via a request variable.
the concept is outlined here: https://dev.plone.org/ticket/10311
Do you need to switch plone skin? Or would it be enough to change the diazo theme, using the same (more or less neutral) plone skin?
I use this approach to switch diazo rule set and index.html depending on the path. The two diazo themes uses different resources: images, styles, js, etc., and are very different.
My rules.xml - shortened:
<?xml version="1.0" encoding="UTF-8"?>
<rules
xmlns="http://namespaces.plone.org/diazo"
xmlns:css="http://namespaces.plone.org/diazo/css"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xi="http://www.w3.org/2001/XInclude">
<!-- The theme for my "app" -->
<rules if-path="/app_path /site/app_path">
<theme href="index_app.html"/>
<!-- rules for the specific path -->
</rules>
<!-- The default theme, used for standard Plone web pages -->
<theme href="index.html" css:if-content="#visual-portal-wrapper" />
<!-- Rules applying to a standard Plone web page -->
<rules css:if-content="#visual-portal-wrapper">
<!-- rules for the rest of the site -->
</rules>
</rules>
The same should be doable for domains using p.a.theming theme parameters: https://pypi.python.org/pypi/plone.app.theming#theme-parameters
and using "Conditions based on arbitrary parameters" from http://docs.diazo.org/en/latest/advanced.html
(replace the if-path with if="$host = 'domain'")
UNTESTED! :)
I have a requirement where I can add both flash and embed HTML5 app on page. But HTML5 app is not supported on many browsers. What I want to do is to check at runtime if the HTML5 app is not working fine, then show Flash File. But I don't know how can I check at run time whether my app is displaying anything or not. I have embedded the HTML5 code through following code in user-control:
<embed src='<fully qualified html5 app link>' height="<height>" width="<width>" />
The process of checking for supported functionality at runtime is often referred as "feature detection". Modernizr is one popular JavaScript library that provides such "feature detects": http://modernizr.com/
For example, let's start with the HTML you suggested, and add an id attribute for convenience:
<embed id="fancy" height="<height>" width="<width>" />
If you wanted to use HTML5 Canvas, for example, but had to fall back to a Flash alternative in non-Canvas browsers, you could do something like this (in JavaScript, with Modernizr):
if (Modernizr.canvas) {
// TODO: do whatever it is you want to do with Canvas
} else {
// hook up your embed to the fallback Flash component
document.getElementById('fancy').src = 'url/for/flash/component.swf';
}
HTML5 covers loads of functionality. The precise "detect" required will vary based on your requirements, but Modernizr makes most of this quite simple.
on Plone, tiles are nothing but Zope browser views; we were wondering if it is possible to declare/use different templates for a tile on an simple way.
according to plone.tiles documentation you can override a template for a different context.
<plone:tile
name="sample.persistenttile"
template="override.pt"
permission="zope.Public"
for="*"
layer=".interfaces.IMyLayer"
/>
should we need to implement a way to mark the tiles with some interface for this? is there a different/easier solution?
My page is showing regular component presentations very well.
I have a flash/video file in my local machine and i want to upload this file on my page.
How can I achieve this?
I have this code snippet for rendering components on my page:
<!-- TemplateBeginRepeat name="Components" -->
<!-- TemplateBeginIf cond="ComponentTemplate == 'HomePageCT'" -->
##RenderComponentPresentation()##
<!-- TemplateEndIf -->
<!-- TemplateEndRepeat -->
Please provide all details related to flash files and video files.
Placing a Flash file on a page follows exactly the same process as placing any image in the output of your templates. The steps are outlined below:
Create a Multimedia Schema which allows the Flash multimedia type (e.g. Flash Video Schema)
Upload your Flash file using your new Schema
Create a Component Template to render the HTML you want to use to display the Flash file, and actually publish the binary itself. (e.g. Display Flash CT)
Create a page template (you seem to have done this part) which renders the Page, and renders the Components on the page using ##RenderComponentPresentation()##
Create a Page, and place your Flash file on it using the Display Flash CT
Publish the Page
Without details of the output you want to produce, it is hard to provide the sample Dreamweaver Template Building Block code for the DisplayFlash CT, but it might look something like this:
<embed src="##Component.Id##" allowFullScreen="true" width="540"
height="438" bgcolor="#000000" type="application/x-shockwave-flash"
pluginspage="http://www.macromedia.com/go/getflashplayer">
</embed>
Make sure you use the Default Finish Actions TBB after this in your Component Template so that the src link is processed and the binary is published.
There is nothing special about Flash files with Tridion. They can be treated just like any other Multimedia Component. You can upload them into the CME (or by using Webdav) and thus you will have a Multimedia Component. Make sure of course, that you Multimedia Schema allows the Flash (and extension) as Multimedia Type.
Regarding how you put the Flash file on the Page - again just like a normal Multimedia Component. In your CT you have to generate the output that will make use of your Flash file URL somewhere. You will have to publish your Flash MMC in order to get its URL. You can use Engine.AddBinary or RenderedItem.AddBinary methods for that, or use the Publish Binaries in Package Default TBB, if your MMC is in the package. Then you can simply refer to your Flash URL as package item. Have a look at this URLs for some inspiration: http://yatb.mitza.net/2012/03/publishing-images-as-variants.html (your case doesn't have to be that complex) and http://yatb.mitza.net/2012/04/referencing-image-variants-from.html.
There are several approaches to rendering Multimedia with a Tridion-managed page.
Multimedia components can be:
Part of a component presentation, added to a page with a template selected
As a linked-to multimedia component within a "container" component, which is added to a page
In a rich text format (RTF) area within another component
You could also just publish binaries with dynamic component templates and handle the markup and links outside of Tridion. Get creative with the above basic scenarios depending on the markup and/or metadata you need.
Chris addresses #1 and Mihai explains schema setup and .AddBinary. The second option would be similar, except you'd have to get the referenced ID rather than the component on the page. The third option requires you to parse multimedia within RTF which depends on your templating language and multimedia type.
I've seen XSLT (<xsl:template match="">), grep, and various .replace options to parse specific markup such as Flash videos.