diff --git a/Yesod/Form.hs b/Yesod/Form.hs index 4d658344..1add7800 100644 --- a/Yesod/Form.hs +++ b/Yesod/Form.hs @@ -398,7 +398,7 @@ jqueryDayFieldProfile = FieldProfile addScriptRemote "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" addScriptRemote "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/jquery-ui.min.js" addStylesheetRemote "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/themes/cupertino/jquery-ui.css" - addHead [$hamlet|%script $$(function(){$$("#$name$").datepicker({dateFormat:'yy-mm-dd'})})|] + addJavaScript [$hamlet|$$(function(){$$("#$name$").datepicker({dateFormat:'yy-mm-dd'})});|] , fpName = Nothing , fpLabel = mempty , fpTooltip = mempty @@ -535,7 +535,7 @@ nicHtmlFieldProfile = FieldProfile |] , fpWidget = \name -> do addScriptRemote "http://js.nicedit.com/nicEdit-latest.js" - addHead [$hamlet|%script bkLib.onDomLoaded(function(){new nicEditor({fullPanel:true}).panelInstance("$name$")})|] + addJavaScript [$hamlet|bkLib.onDomLoaded(function(){new nicEditor({fullPanel:true}).panelInstance("$name$")});|] , fpName = Nothing , fpLabel = mempty , fpTooltip = mempty @@ -787,7 +787,7 @@ jqueryAutocompleteFieldProfile src = FieldProfile addScriptRemote "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" addScriptRemote "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/jquery-ui.min.js" addStylesheetRemote "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/themes/cupertino/jquery-ui.css" - addHead [$hamlet|%script $$(function(){$$("#$name$").autocomplete({source:"@src@",minLength:2})});|] + addJavaScript [$hamlet|$$(function(){$$("#$name$").autocomplete({source:"@src@",minLength:2})});|] , fpName = Nothing , fpLabel = mempty , fpTooltip = mempty diff --git a/Yesod/Widget.hs b/Yesod/Widget.hs index d88de5fd..ea8dfe58 100644 --- a/Yesod/Widget.hs +++ b/Yesod/Widget.hs @@ -60,13 +60,13 @@ newtype Script url = Script { unScript :: Location url } newtype Stylesheet url = Stylesheet { unStylesheet :: Location url } deriving (Show, Eq) newtype Title = Title { unTitle :: Html () } -newtype Style url = Style (Hamlet url) +newtype Style url = Style (Maybe (Hamlet url)) deriving Monoid newtype Head url = Head (Hamlet url) deriving Monoid newtype Body url = Body (Hamlet url) deriving Monoid -newtype JavaScript url = JavaScript (Hamlet url) +newtype JavaScript url = JavaScript (Maybe (Hamlet url)) deriving Monoid newtype GWidget sub master a = GWidget ( @@ -103,7 +103,7 @@ newIdent = GWidget $ lift $ lift $ lift $ lift $ lift $ lift $ lift $ do return $ "w" ++ show i' addStyle :: Hamlet (Route master) -> GWidget sub master () -addStyle = GWidget . lift . lift . lift . lift . tell . Style +addStyle = GWidget . lift . lift . lift . lift . tell . Style . Just addStylesheet :: Route master -> GWidget sub master () addStylesheet = GWidget . lift . lift . lift . tell . toUnique . Stylesheet . Local @@ -120,7 +120,8 @@ addScriptRemote = GWidget . lift . lift . tell . toUnique . Script . Remote addJavaScript :: Hamlet (Route master) -> GWidget sub master () -addJavaScript = GWidget . lift . lift . lift . lift . lift. tell . JavaScript +addJavaScript = GWidget . lift . lift . lift . lift . lift. tell + . JavaScript . Just applyLayoutW :: (Eq (Route m), Yesod m) => GWidget sub m () -> GHandler sub m RepHtml @@ -150,8 +151,10 @@ $forall scripts s %script!src=^s^ $forall stylesheets s %link!rel=stylesheet!href=^s^ -%style ^style^ -%script ^jscript^ +$maybe style s + %style ^s^ +$maybe jscript j + %script ^j^ ^head'^ |] return $ PageContent title head'' body diff --git a/hellowidget.hs b/hellowidget.hs index 11a330a0..f29aff1c 100644 --- a/hellowidget.hs +++ b/hellowidget.hs @@ -34,7 +34,6 @@ getRootR = applyLayoutW $ flip wrapWidget wrapper $ do |] addHead [$hamlet|%meta!keywords=haskell|] --- FIXME add coolness to day and html below handleFormR = do (res, form, enctype) <- runFormPost $ (,,,,,,,) <$> stringField (string "My Field") (string "Some tooltip info") Nothing @@ -52,6 +51,7 @@ handleFormR = do _ -> Nothing applyLayoutW $ do addStyle [$hamlet|\.tooltip{color:#666;font-style:italic}|] + addStyle [$hamlet|textarea.html{width:300px;height:150px};|] wrapWidget (fieldsToTable form) $ \h -> [$hamlet| %form!method=post!enctype=$show.enctype$ %table