By | Chris Done |
At | 2011-06-12 |
Title | Auto-collapse paste details heading with toggle button. |
Description |
Edit file src/HJScript/Objects/JQuery/Extra.hs 33188 → 33188
17 17 -- | Set the width of a DOM element.
18 18 setWidth :: IsJQuery o => Exp Int -> o -> HJScript ()
19 19 setWidth w o = do
20 20 runExp $ methodCall "width" w o
21 21 + 22 -- | Append an element to another.
+ 23 append :: IsJQuery o => Exp a -> o -> HJScript ()
+ 24 append w o = do
+ 25 runExp $ methodCall "append" w o
+ 26 + 27 -- | Prepend an element before another.
+ 28 prepend :: IsJQuery o => Exp a -> o -> HJScript ()
+ 29 prepend w o = do
+ 30 runExp $ methodCall "prepend" w o
+ 31 22 32 -- | Add a class to an object.
23 33 addClass :: IsJQuery o => String -> o -> HJScript ()
24 34 addClass w o = do
25 35 runExp $ methodCall "addClass" (string w) o
26 36 … … … … 46 56 47 57 -- | Get the width of a DOM element.
48 58 getWidth :: IsJQuery o => o -> Exp Int
49 59 getWidth o = do
50 60 methodCall "width" () o
+ 61 + 62 -- | Get siblings of an elements.
+ 63 siblings :: IsJQuery o => String -> o -> JObject JQuery
+ 64 siblings q o = do
+ 65 methodCall "siblings" (string q) o
51 66 52 67 -- | When toggling by clicking, run these events on this object.
53 68 toggle :: IsJQuery o => HJScript JBool -> HJScript JBool -> o -> HJScript ()
54 69 toggle on off query = do
55 70 fnon <- function $ \() -> on
… … … … Edit file src/Amelie/View/Paste.hs 33188 → 33188
124 124 125 125 -- | List the details of the page in a dark section.
126 126 pasteDetails :: [Channel] -> [Language] -> Paste -> Html
127 127 pasteDetails chans langs paste@Paste{..} =
128 128 darkNoTitleSection $ do
- 129 H.div ! aClass "paste-nav" $ do
- 130 href ("/edit/" ++ pack (show pasteId) ++ "") ("Annotate" :: Text)
+ 129 pasteNav paste
131 130 h2 $ toHtml $ fromStrict pasteTitle
132 131 ul ! aClass "paste-specs" $ do
133 132 detail "Paste" $ pasteLink paste $ "#" ++ show pasteId
134 133 detail "Author" $ pasteAuthor
135 134 detail "Language" $ showLanguage langs pasteLanguage
… … … … 138 137 detail "Raw" $ pasteRawLink paste $ ("View raw link" :: Text)
139 138 clear
140 139 141 140 where detail title content = do
142 141 li $ do strong (title ++ ":"); toHtml content
+ 142 + 143 -- | Individual paste navigation.
+ 144 pasteNav :: Paste -> Html
+ 145 pasteNav Paste {..} =
+ 146 H.div ! aClass "paste-nav" $ do
+ 147 href ("/edit/" ++ pack (show pasteId) ++ "") ("Annotate" :: Text)
143 148 144 149 -- | Show the paste content with highlighting.
145 150 pasteContent :: [Language] -> Paste -> Html
146 151 pasteContent langs paste =
147 152 lightNoTitleSection $ highlightPaste langs paste
… … … … Edit file src/Amelie/View/Script.hs 33188 → 33188
7 7 8 8 module Amelie.View.Script
9 9 (script)
10 10 where
11 11 - 12 import Data.Text.Lazy (Text,pack)
- 13 import HJScript
- 14 import HJScript.Objects.JQuery
- 15 import HJScript.Objects.JQuery.Extra
- 16 import Prelude hiding ((++),max)
+ 12 import Data.Text.Lazy (Text,pack)
+ 13 import HJScript
+ 14 import HJScript.Objects.JQuery hiding (prepend,append)
+ 15 import HJScript.Objects.JQuery.Extra
+ 16 import Prelude hiding ((++),max)
17 17 18 18 -- | All scripts on the site. Not much to do.
19 19 script :: Text
20 20 script = pack $ show $ snd $ evalHJScript $ do
21 21 ready $ do
22 22 resizePage
23 23 toggleHints
+ 24 togglePaste
24 25 25 26 -- | Resize the width of the page to match content width.
26 27 resizePage :: HJScript ()
27 28 resizePage = do
28 29 max <- varWith (int 0)
… … … … 56 57 css "overflow" "hidden" o
57 58 return false
58 59 expand o = do
59 60 css "height" "auto" o
60 61 return false
+ 62 + 63 -- | Toggle paste details.
+ 64 togglePaste :: HJScript ()
+ 65 togglePaste = do
+ 66 each (do btn <- varWith (j "<a href=\"\">Expand</a>")
+ 67 this <- varWith this'
+ 68 prepend (string " - ") this
+ 69 prepend (val btn) this
+ 70 details <- varWith (siblings ".amelie-paste-specs" this)
+ 71 display "none" details
+ 72 toggle (display "block" details)
+ 73 (display "none" details)
+ 74 btn
+ 75 return true)
+ 76 (j ".amelie-paste-nav")
+ 77 + 78 where display prop o = do
+ 79 css "display" prop o
+ 80 return false
… … … … Edit file src/Amelie/View/Style.hs 33188 → 33188
98 98 margin "0 0 0.5em 0"
99 99 100 100 subRule "h2" $ do
101 101 margin "0"
102 102 fontSize "1.2em"
- 103 padding "0 0 0.5em 0"
+ 103 padding "0"
104 104 105 105 classRule "section-dark" $ do
106 106 background "#453D5B"
107 107 borderColor "#A9A0D2"
108 108 color "#FFF"
… … … … 146 146 147 147 -- | Paste view styles.
148 148 paste :: CSS Rule
149 149 paste = do
150 150 classRule "paste-specs" $ do
- 151 margin "0"
+ 151 margin "0.5em 0 0 0"
152 152 padding "0"
153 153 listStyle "none"
154 154 lineHeight "1.5em"
155 155 156 156 subRule "strong" $ do
… … … … 214 214 home :: CSS Rule
215 215 home = do
216 216 rule "#new" wrap
217 217 classRule "browse-link" $ do
218 218 margin "1em 0 0 0"
+ 219 classRule "latest-pastes" $ do
+ 220 marginTop "0.5em"
219 221 220 222 where wrap = subRule ".amelie-wrap" $ do
221 223 width "50em"
222 224 223 225 -- | Browse page styles.
… … … …