zen 0.2.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (178) hide show
  1. data/.gems +34 -0
  2. data/.travis.yml +7 -0
  3. data/AUTHORS +5 -0
  4. data/CHANGELOG +14 -0
  5. data/{license.txt → LICENSE} +0 -0
  6. data/MANIFEST +67 -51
  7. data/README.md +18 -25
  8. data/Rakefile +2 -3
  9. data/bin/zen +2 -2
  10. data/lib/zen.rb +93 -57
  11. data/lib/zen/asset.rb +7 -8
  12. data/lib/zen/bin/app.rb +0 -2
  13. data/lib/zen/controller/admin_controller.rb +4 -9
  14. data/lib/zen/controller/base_controller.rb +0 -25
  15. data/lib/zen/controller/main_controller.rb +5 -5
  16. data/lib/zen/controller/preview.rb +50 -0
  17. data/lib/zen/helper/common.rb +4 -68
  18. data/lib/zen/helper/message.rb +82 -0
  19. data/lib/zen/helper/theme.rb +2 -2
  20. data/lib/zen/language.rb +68 -38
  21. data/lib/zen/language/en/zen_general.yml +1 -4
  22. data/lib/zen/language/nl/zen_general.yml +28 -0
  23. data/lib/zen/language/nl/zen_models.yml +13 -0
  24. data/lib/zen/layout/admin.xhtml +1 -1
  25. data/lib/zen/layout/login.xhtml +1 -1
  26. data/lib/zen/model/settings.rb +2 -0
  27. data/lib/zen/package.rb +29 -25
  28. data/lib/zen/package/all.rb +1 -1
  29. data/lib/zen/package/categories/lib/categories/controller/categories.rb +51 -63
  30. data/lib/zen/package/categories/lib/categories/controller/category_groups.rb +45 -52
  31. data/lib/zen/package/categories/lib/categories/language/en/categories.yml +2 -2
  32. data/lib/zen/package/categories/lib/categories/language/nl/categories.yml +39 -0
  33. data/lib/zen/package/categories/lib/categories/language/nl/category_groups.yml +33 -0
  34. data/lib/zen/package/categories/lib/categories/plugin/categories.rb +2 -2
  35. data/lib/zen/package/comments/lib/comments.rb +31 -2
  36. data/lib/zen/package/comments/lib/comments/controller/comments.rb +42 -57
  37. data/lib/zen/package/comments/lib/comments/controller/comments_form.rb +36 -51
  38. data/lib/zen/package/comments/lib/comments/language/en/comments.yml +7 -3
  39. data/lib/zen/package/comments/lib/comments/language/nl/comments.yml +48 -0
  40. data/lib/zen/package/comments/lib/comments/model/comment.rb +45 -4
  41. data/lib/zen/package/comments/lib/comments/plugin/anti_spam.rb +152 -0
  42. data/lib/zen/package/comments/lib/comments/plugin/comments.rb +5 -6
  43. data/lib/zen/package/comments/lib/comments/view/admin/comments/index.xhtml +2 -2
  44. data/lib/zen/package/custom_fields/lib/custom_fields/controller/custom_field_groups.rb +43 -52
  45. data/lib/zen/package/custom_fields/lib/custom_fields/controller/custom_fields.rb +68 -67
  46. data/lib/zen/package/custom_fields/lib/custom_fields/language/en/custom_fields.yml +1 -1
  47. data/lib/zen/package/custom_fields/lib/custom_fields/language/nl/custom_field_groups.yml +32 -0
  48. data/lib/zen/package/custom_fields/lib/custom_fields/language/nl/custom_fields.yml +52 -0
  49. data/lib/zen/package/custom_fields/lib/custom_fields/model/custom_field.rb +3 -3
  50. data/lib/zen/package/custom_fields/lib/custom_fields/model/custom_field_group.rb +4 -7
  51. data/lib/zen/package/custom_fields/lib/custom_fields/model/custom_field_value.rb +3 -3
  52. data/lib/zen/package/menus/lib/menus/controller/menu_items.rb +37 -44
  53. data/lib/zen/package/menus/lib/menus/controller/menus.rb +33 -43
  54. data/lib/zen/package/menus/lib/menus/helper/menu_item.rb +5 -10
  55. data/lib/zen/package/menus/lib/menus/language/nl/menu_items.yml +41 -0
  56. data/lib/zen/package/menus/lib/menus/language/nl/menus.yml +39 -0
  57. data/lib/zen/package/menus/lib/menus/model/menu.rb +3 -3
  58. data/lib/zen/package/menus/lib/menus/model/menu_item.rb +3 -3
  59. data/lib/zen/package/menus/lib/menus/plugin/menus.rb +5 -6
  60. data/lib/zen/package/menus/migrations/1297184342_create_schema.rb +1 -1
  61. data/lib/zen/package/sections/lib/sections.rb +20 -0
  62. data/lib/zen/package/sections/lib/sections/controller/section_entries.rb +85 -79
  63. data/lib/zen/package/sections/lib/sections/controller/sections.rb +58 -66
  64. data/lib/zen/package/sections/lib/sections/language/en/sections.yml +0 -1
  65. data/lib/zen/package/sections/lib/sections/language/nl/section_entries.yml +43 -0
  66. data/lib/zen/package/sections/lib/sections/language/nl/sections.yml +47 -0
  67. data/lib/zen/package/sections/lib/sections/model/section.rb +11 -15
  68. data/lib/zen/package/sections/lib/sections/model/section_entry.rb +9 -5
  69. data/lib/zen/package/sections/lib/sections/plugin/section_entries.rb +7 -8
  70. data/lib/zen/package/sections/lib/sections/plugin/sections.rb +3 -4
  71. data/lib/zen/package/sections/lib/sections/view/admin/section-entries/form.xhtml +0 -4
  72. data/lib/zen/package/sections/lib/sections/view/admin/section-entries/index.xhtml +8 -2
  73. data/lib/zen/package/sections/migrations/1306772479_remove_unique_slug.rb +28 -0
  74. data/lib/zen/package/settings/lib/settings.rb +21 -34
  75. data/lib/zen/package/settings/lib/settings/controller/settings.rb +29 -22
  76. data/lib/zen/package/settings/lib/settings/language/en/settings.yml +7 -5
  77. data/lib/zen/package/settings/lib/settings/language/nl/settings.yml +39 -0
  78. data/lib/zen/package/settings/lib/settings/model/setting.rb +3 -5
  79. data/lib/zen/package/settings/lib/settings/plugin/group_base.rb +3 -4
  80. data/lib/zen/package/settings/lib/settings/plugin/setting_base.rb +3 -5
  81. data/lib/zen/package/settings/lib/settings/plugin/settings.rb +11 -4
  82. data/lib/zen/package/settings/lib/settings/view/admin/settings/index.xhtml +5 -5
  83. data/lib/zen/package/settings/migrations/1299538742_add_language_key.rb +8 -8
  84. data/lib/zen/package/settings/migrations/1303196915_settings_plugin.rb +2 -5
  85. data/lib/zen/package/users/lib/users/controller/access_rules.rb +54 -61
  86. data/lib/zen/package/users/lib/users/controller/user_groups.rb +49 -57
  87. data/lib/zen/package/users/lib/users/controller/users.rb +58 -73
  88. data/lib/zen/package/users/lib/users/language/en/users.yml +6 -0
  89. data/lib/zen/package/users/lib/users/language/nl/access_rules.yml +37 -0
  90. data/lib/zen/package/users/lib/users/language/nl/user_groups.yml +31 -0
  91. data/lib/zen/package/users/lib/users/language/nl/users.yml +56 -0
  92. data/lib/zen/package/users/lib/users/model/user.rb +16 -1
  93. data/lib/zen/package/users/lib/users/view/admin/users/form.xhtml +27 -2
  94. data/lib/zen/package/users/lib/users/view/admin/users/index.xhtml +15 -3
  95. data/lib/zen/package/users/migrations/1304939855_user_settings.rb +15 -0
  96. data/lib/zen/plugin.rb +7 -9
  97. data/lib/zen/public/admin/css/{buttons.css → zen/buttons.css} +11 -7
  98. data/lib/zen/public/admin/css/{datepicker.css → zen/datepicker.css} +0 -0
  99. data/lib/zen/public/admin/css/{editor.css → zen/editor.css} +10 -5
  100. data/lib/zen/public/admin/css/{forms.css → zen/forms.css} +1 -1
  101. data/lib/zen/public/admin/css/{general.css → zen/general.css} +7 -7
  102. data/lib/zen/public/admin/css/{grid.css → zen/grid.css} +0 -0
  103. data/lib/zen/public/admin/css/{layout.css → zen/layout.css} +4 -5
  104. data/lib/zen/public/admin/css/zen/messages.css +61 -0
  105. data/lib/zen/public/admin/css/{notifications.css → zen/notifications.css} +4 -4
  106. data/lib/zen/public/admin/css/{reset.css → zen/reset.css} +0 -0
  107. data/lib/zen/public/admin/css/{tables.css → zen/tables.css} +3 -3
  108. data/lib/zen/public/admin/css/{tabs.css → zen/tabs.css} +5 -5
  109. data/lib/zen/public/admin/css/zen/window.css +79 -0
  110. data/lib/zen/public/admin/images/{icons → zen/icons}/accept.png +0 -0
  111. data/lib/zen/public/admin/images/{icons → zen/icons}/add.png +0 -0
  112. data/lib/zen/public/admin/images/{icons → zen/icons}/back.png +0 -0
  113. data/lib/zen/public/admin/images/{icons → zen/icons}/bold.png +0 -0
  114. data/lib/zen/public/admin/images/zen/icons/close.png +0 -0
  115. data/lib/zen/public/admin/images/{icons → zen/icons}/delete.png +0 -0
  116. data/lib/zen/public/admin/images/{icons → zen/icons}/edit.png +0 -0
  117. data/lib/zen/public/admin/images/{icons → zen/icons}/error.png +0 -0
  118. data/lib/zen/public/admin/images/{icons → zen/icons}/help.png +0 -0
  119. data/lib/zen/public/admin/images/{icons → zen/icons}/info.png +0 -0
  120. data/lib/zen/public/admin/images/{icons → zen/icons}/italic.png +0 -0
  121. data/lib/zen/public/admin/images/{icons → zen/icons}/large/error.png +0 -0
  122. data/lib/zen/public/admin/images/{icons → zen/icons}/large/notice.png +0 -0
  123. data/lib/zen/public/admin/images/{icons → zen/icons}/large/success.png +0 -0
  124. data/lib/zen/public/admin/images/{icons → zen/icons}/link.png +0 -0
  125. data/lib/zen/public/admin/images/{icons → zen/icons}/logout.png +0 -0
  126. data/lib/zen/public/admin/images/{icons → zen/icons}/ol.png +0 -0
  127. data/lib/zen/public/admin/images/{icons → zen/icons}/pdf.png +0 -0
  128. data/lib/zen/public/admin/images/zen/icons/preview.png +0 -0
  129. data/lib/zen/public/admin/images/{icons → zen/icons}/ul.png +0 -0
  130. data/lib/zen/public/admin/images/{icons → zen/icons}/user.png +0 -0
  131. data/lib/zen/public/admin/images/{icons → zen/icons}/view.png +0 -0
  132. data/lib/zen/public/admin/js/zen/core.js +73 -0
  133. data/lib/zen/public/admin/js/zen/editor.js +527 -0
  134. data/lib/zen/public/admin/js/zen/editor/markdown.js +84 -0
  135. data/lib/zen/public/admin/js/zen/editor/textile.js +84 -0
  136. data/lib/zen/public/admin/js/zen/init.js +12 -66
  137. data/lib/zen/public/admin/js/zen/tabs.js +5 -0
  138. data/lib/zen/public/admin/js/zen/window.js +206 -0
  139. data/lib/zen/task/build.rake +23 -6
  140. data/lib/zen/task/clean.rake +6 -7
  141. data/lib/zen/task/db.rake +7 -9
  142. data/lib/zen/task/package.rake +6 -6
  143. data/lib/zen/task/test.rake +6 -0
  144. data/lib/zen/task/theme.rake +3 -3
  145. data/lib/zen/theme.rb +3 -4
  146. data/lib/zen/validation.rb +7 -9
  147. data/lib/zen/version.rb +3 -4
  148. data/lib/zen/view/bottom.xhtml +0 -5
  149. data/lib/zen/view/main.xhtml +2 -0
  150. data/proto/app/app.rb +6 -4
  151. data/proto/app/config/config.rb +1 -7
  152. data/proto/app/config/database.rb +47 -43
  153. data/proto/app/config/middlewares.rb +0 -40
  154. data/proto/app/start.rb +1 -6
  155. data/proto/app/{vendor → theme}/.gitkeep +0 -0
  156. data/proto/migration.rb +3 -3
  157. data/proto/package/lib/package.rb +0 -1
  158. data/proto/package/lib/package/controller/controllers.rb +7 -40
  159. data/proto/package/lib/package/model/model.rb +3 -3
  160. metadata +106 -79
  161. data/CHANGELOG.md +0 -27
  162. data/ROADMAP.md +0 -53
  163. data/lib/zen/database.rb +0 -112
  164. data/lib/zen/logger.rb +0 -56
  165. data/lib/zen/public/admin/css/modals.css +0 -63
  166. data/lib/zen/public/admin/images/icons/close.png +0 -0
  167. data/lib/zen/public/admin/js/vendor/yepnope.js +0 -1
  168. data/lib/zen/public/admin/js/zen/editor/base.js +0 -262
  169. data/lib/zen/public/admin/js/zen/editor/drivers/html.js +0 -89
  170. data/lib/zen/public/admin/js/zen/editor/drivers/markdown.js +0 -87
  171. data/lib/zen/public/admin/js/zen/editor/drivers/textile.js +0 -87
  172. data/lib/zen/public/admin/js/zen/modal.js +0 -146
  173. data/lib/zen/public/admin/js/zen/notification.js +0 -211
  174. data/proto/app/config/requires.rb +0 -10
  175. data/proto/app/vendor/theme/.gitkeep +0 -0
  176. data/proto/package/lib/package/view/admin/package/edit.xhtml +0 -0
  177. data/proto/package/lib/package/view/admin/package/form.xhtml +0 -0
  178. data/proto/package/lib/package/view/admin/package/new.xhtml +0 -0
@@ -0,0 +1,84 @@
1
+ /**
2
+ * Markdown driver for the text editor that ships with Zen.
3
+ *
4
+ * @author Yorick Peterse
5
+ * @since 0.2.6
6
+ * @namespace Zen
7
+ * @extend Editor
8
+ */
9
+ Zen.Editor.Markdown = new Class(
10
+ {
11
+ Extends: Zen.Editor,
12
+
13
+ /**
14
+ * Overrides Zen.Editor.bold.
15
+ *
16
+ * @author Yorick Peterse
17
+ * @since 0.2.6
18
+ * @param [Element] editor The textarea to insert the tags into.
19
+ */
20
+ bold: function(editor)
21
+ {
22
+ editor.insertAroundCursor({before: '**', after: '**'});
23
+ },
24
+
25
+ /**
26
+ * Overrides Zen.Editor.italic.
27
+ *
28
+ * @author Yorick Peterse
29
+ * @since 0.2.6
30
+ * @param [Element] editor The textarea to insert the tags into.
31
+ */
32
+ italic: function(editor)
33
+ {
34
+ editor.insertAroundCursor({before: '*', after: '*'});
35
+ },
36
+
37
+ /**
38
+ * Overrides Zen.Editor.link.
39
+ *
40
+ * @author Yorick Peterse
41
+ * @since 0.2.6
42
+ * @param [Element] editor The textarea to insert the tags into.
43
+ */
44
+ link: function(editor)
45
+ {
46
+ var link = prompt('URL', 'http://');
47
+
48
+ editor.insertAroundCursor(
49
+ {
50
+ before: '[',
51
+ after: '](' + link + ')'
52
+ });
53
+ },
54
+
55
+ /**
56
+ * Overrides Zen.Editor.ul.
57
+ *
58
+ * @author Yorick Peterse
59
+ * @since 0.2.6
60
+ * @param [Element] editor The textarea to insert the tags into.
61
+ */
62
+ ul: function(editor)
63
+ {
64
+ editor.insertAroundCursor(
65
+ {
66
+ before: "\n* "
67
+ });
68
+ },
69
+
70
+ /**
71
+ * Overrides Zen.Editor.ol.
72
+ *
73
+ * @author Yorick Peterse
74
+ * @since 0.2.6
75
+ * @param [Element] editor The textarea to insert the tags into.
76
+ */
77
+ ol: function(editor)
78
+ {
79
+ editor.insertAroundCursor(
80
+ {
81
+ before: "\n1. "
82
+ });
83
+ }
84
+ });
@@ -0,0 +1,84 @@
1
+ /**
2
+ * Textile driver for the text editor that ships with Zen.
3
+ *
4
+ * @author Yorick Peterse
5
+ * @since 0.2.6
6
+ * @namespace Zen
7
+ * @extend Editor
8
+ */
9
+ Zen.Editor.Textile = new Class(
10
+ {
11
+ Extends: Zen.Editor,
12
+
13
+ /**
14
+ * Overrides Zen.Editor.bold.
15
+ *
16
+ * @author Yorick Peterse
17
+ * @since 0.2.6
18
+ * @param [Element] editor The textarea to insert the tags into.
19
+ */
20
+ bold: function(editor)
21
+ {
22
+ editor.insertAroundCursor({before: '*', after: '*'});
23
+ },
24
+
25
+ /**
26
+ * Overrides Zen.Editor.italic.
27
+ *
28
+ * @author Yorick Peterse
29
+ * @since 0.2.6
30
+ * @param [Element] editor The textarea to insert the tags into.
31
+ */
32
+ italic: function(editor)
33
+ {
34
+ editor.insertAroundCursor({before: '_', after: '_'});
35
+ },
36
+
37
+ /**
38
+ * Overrides Zen.Editor.link.
39
+ *
40
+ * @author Yorick Peterse
41
+ * @since 0.2.6
42
+ * @param [Element] editor The textarea to insert the tags into.
43
+ */
44
+ link: function(editor)
45
+ {
46
+ var link = prompt('URL', 'http://');
47
+
48
+ editor.insertAroundCursor(
49
+ {
50
+ before: '"',
51
+ after: '":' + link
52
+ });
53
+ },
54
+
55
+ /**
56
+ * Overrides Zen.Editor.ul.
57
+ *
58
+ * @author Yorick Peterse
59
+ * @since 0.2.6
60
+ * @param [Element] editor The textarea to insert the tags into.
61
+ */
62
+ ul: function(editor)
63
+ {
64
+ editor.insertAroundCursor(
65
+ {
66
+ before: "\n* "
67
+ });
68
+ },
69
+
70
+ /**
71
+ * Overrides Zen.Editor.ol.
72
+ *
73
+ * @author Yorick Peterse
74
+ * @since 0.2.6
75
+ * @param [Element] editor The textarea to insert the tags into.
76
+ */
77
+ ol: function(editor)
78
+ {
79
+ editor.insertAroundCursor(
80
+ {
81
+ before: "\n# "
82
+ });
83
+ }
84
+ });
@@ -1,20 +1,5 @@
1
1
  window.addEvent('domready', function()
2
2
  {
3
- /**
4
- * Show a notification whenever we find an error, success or notice hash in the
5
- * Zen.Flash object.
6
- */
7
- if ( Zen.Flash.notification )
8
- {
9
- new Zen.Notification(
10
- {
11
- title: Zen.Flash.notification.title,
12
- content: Zen.Flash.notification.content,
13
- image: Zen.Flash.notification.image,
14
- sticky: Zen.Flash.notification.sticky
15
- });
16
- }
17
-
18
3
  /**
19
4
  * Enable the automatic checking of all checkboxes in a table with a class of "table".
20
5
  * Perhaps I'll use a class for this in the future but for now this is good enough.
@@ -50,19 +35,11 @@ window.addEvent('domready', function()
50
35
  var tab_selector = 'div.tabs ul';
51
36
  var tab_elements = $$(tab_selector).length;
52
37
 
53
- yepnope(
38
+ // Double check there are any elements
39
+ if ( tab_elements > 0 )
54
40
  {
55
- test: !Zen.Tabs && tab_elements > 0,
56
- yep: ['/admin/css/tabs.css', '/admin/js/zen/tabs.js'],
57
- complete: function()
58
- {
59
- // Double check there are any elements
60
- if ( tab_elements > 0 )
61
- {
62
- new Zen.Tabs(tab_selector);
63
- }
64
- }
65
- });
41
+ new Zen.Tabs(tab_selector);
42
+ }
66
43
 
67
44
  /**
68
45
  * Initialize our editor for all elements with a class of "visual_editor" and
@@ -72,39 +49,16 @@ window.addEvent('domready', function()
72
49
 
73
50
  if ( editor_elements.length > 0 )
74
51
  {
75
- var editor_files = ['/admin/css/editor.css', '/admin/js/zen/editor/base.js'];
76
-
77
- // Determine what drivers to load
78
52
  editor_elements.each(function(editor)
79
53
  {
80
- var driver = editor.get('data-format');
54
+ var markup = editor.get('data-format');
81
55
 
82
- // Screw you, you should've set the attribute!
83
- if ( !driver )
56
+ if ( typeOf(markup) === 'undefined' )
84
57
  {
85
- return console.error(
86
- "Missing attribute data-format for the editor with ID "
87
- + editor.get('id')
88
- );
58
+ markup = 'html';
89
59
  }
90
60
 
91
- editor_files.include('/admin/js/zen/editor/drivers/' + driver + '.js');
92
- });
93
-
94
- // Load all the files we need
95
- yepnope(
96
- {
97
- test: Zen.Editor,
98
- nope: editor_files,
99
- complete: function()
100
- {
101
- editor_elements.each(function(editor)
102
- {
103
- new Zen.Editor.Base(
104
- editor, {format: editor.get('data-format')}
105
- ).display();
106
- });
107
- }
61
+ Zen.Editor.init(markup, editor);
108
62
  });
109
63
  }
110
64
 
@@ -116,19 +70,11 @@ window.addEvent('domready', function()
116
70
 
117
71
  if ( date_elements.length > 0 )
118
72
  {
119
- yepnope(
73
+ new Picker.Date(date_elements,
120
74
  {
121
- test : typeof Picker === 'undefined',
122
- yep : ['/admin/css/datepicker.css', '/admin/js/vendor/datepicker.js'],
123
- complete: function()
124
- {
125
- new Picker.Date(date_elements,
126
- {
127
- timePicker: true,
128
- pickerClass: 'datepicker',
129
- format: '%Y-%m-%d %H:%M:%S'
130
- });
131
- }
75
+ timePicker: true,
76
+ pickerClass: 'datepicker',
77
+ format: '%Y-%m-%d %H:%M:%S'
132
78
  });
133
79
  }
134
80
  });
@@ -70,6 +70,11 @@ Zen.Tabs = new Class(
70
70
  {
71
71
  Implements: Options,
72
72
 
73
+ Depends:
74
+ {
75
+ stylesheet: ['zen/tabs']
76
+ },
77
+
73
78
  /**
74
79
  * Object containing all options for each tab instance.
75
80
  *
@@ -0,0 +1,206 @@
1
+ /**
2
+ * The Window class can be used to create basic windows with a title and a set of buttons.
3
+ * These windows can be used for a preview of an article, showing an image or asking for a
4
+ * confirmation.
5
+ *
6
+ * ## Usage
7
+ *
8
+ * In order to create a new window you simply need to create a new instance of the class.
9
+ * The first parameter is the content to display and is required, the second parameter is
10
+ * an object containing all custom options to use such as the title.
11
+ *
12
+ * var modal = new Zen.Window('Hello, world!');
13
+ *
14
+ * If you want to set a title you'd do the following:
15
+ *
16
+ * var modal = new Zen.Window('Hello, world!', {title: 'My Window'});
17
+ *
18
+ * For a full list of options see Zen.Window.options.
19
+ *
20
+ * ## Buttons
21
+ *
22
+ * Buttons can be added by setting the "buttons" key in the options object to an array of
23
+ * objects. Each object should have the following three keys:
24
+ *
25
+ * * name: the name of the button, also used as the class (should be unique).
26
+ * * label: the text to display in the button.
27
+ * * onClick: a function that will be called whenever the button is clicked. This function
28
+ * takes a single parameter which is set to the instance of the window the button belongs
29
+ * to.
30
+ *
31
+ * An example of setting a button can be seen below.
32
+ *
33
+ * var modal = new Zen.Window(
34
+ * 'A window with buttons',
35
+ * {
36
+ * buttons:
37
+ * [
38
+ * {
39
+ * name: 'close',
40
+ * label: 'Close',
41
+ * onClick: function(instance)
42
+ * {
43
+ * instance.destroy();
44
+ * }
45
+ * }
46
+ * ]
47
+ * }
48
+ * );
49
+ *
50
+ * @author Yorick Peterse
51
+ * @since 0.2.6
52
+ */
53
+ Zen.Window = new Class(
54
+ {
55
+ Implements: Options,
56
+
57
+ Depends:
58
+ {
59
+ stylesheet: ['zen/window']
60
+ },
61
+
62
+ /**
63
+ * Object containing all the custom options as well as the ones specified by the user.
64
+ *
65
+ * @author Yorick Peterse
66
+ * @since 0.2.6
67
+ */
68
+ options:
69
+ {
70
+ // The height of the window
71
+ height: null,
72
+
73
+ // The width of the window
74
+ width: 400,
75
+
76
+ // The title of the window, set to null for no title
77
+ title: null,
78
+
79
+ // When set to true the window can be resized
80
+ resize: false,
81
+
82
+ // When set to true the user can drag the window around
83
+ move: false,
84
+
85
+ // A collection of buttons to display inside the window
86
+ buttons: []
87
+ },
88
+
89
+ /**
90
+ * DOM element for the current window instance.
91
+ *
92
+ * @author Yorick Peterse
93
+ * @since 0.2.6
94
+ * @var [Element]
95
+ */
96
+ element: null,
97
+
98
+ /**
99
+ * Creates a new instance of the class and displays the window.
100
+ *
101
+ * @author Yorick Peterse
102
+ * @since 0.2.6
103
+ * @param [String] content The content to display inside the window.
104
+ * @param [Object] options Object containing a collection of custom options for the
105
+ * window.
106
+ */
107
+ initialize: function(content, options)
108
+ {
109
+ if ( !content )
110
+ {
111
+ throw new SyntaxError("You need to specify the content to display.");
112
+ }
113
+
114
+ this.setOptions(options);
115
+
116
+ // Create the HTML for the window
117
+ var container = new Element(
118
+ 'article',
119
+ {
120
+ 'class': 'window',
121
+ styles:
122
+ {
123
+ width: this.options.width,
124
+ height: this.options.height
125
+ }
126
+ }
127
+ );
128
+
129
+ var header = new Element('header', {'class': 'clearfix'});
130
+ var close = new Element('div' , {'class': 'close'});
131
+ var body = new Element('div' , {'class': 'body', html: content});
132
+ var current = this;
133
+
134
+ // Do we have a title?
135
+ if ( this.options.title !== null )
136
+ {
137
+ var title = new Element('h1', {html: this.options.title});
138
+ title.inject(header);
139
+ }
140
+
141
+ close.addEvent('click', function()
142
+ {
143
+ current.destroy();
144
+ });
145
+
146
+ // Inject the base elements
147
+ close.inject(header);
148
+ header.inject(container);
149
+ body.inject(container);
150
+
151
+ // Add all the buttons
152
+ if ( this.options.buttons.length > 0 )
153
+ {
154
+ var buttons_container = new Element('div', {'class': 'buttons clearfix'});
155
+
156
+ this.options.buttons.each(function(button)
157
+ {
158
+ var div = new Element('div' , {'class': 'button ' + button.name});
159
+ var btn = new Element('button', {text: button.label});
160
+
161
+ btn.addEvent('click', function()
162
+ {
163
+ button.onClick(current);
164
+ });
165
+
166
+ btn.inject(div);
167
+ div.inject(buttons_container);
168
+ });
169
+
170
+ buttons_container.inject(container);
171
+ }
172
+
173
+ // Allow the window to be resized if this has been specified
174
+ if ( this.options.resize === true )
175
+ {
176
+ container.addClass('resize');
177
+ container.makeResizable();
178
+ }
179
+
180
+ if ( this.options.move === true )
181
+ {
182
+ container.addClass('move');
183
+ container.makeDraggable();
184
+ }
185
+
186
+ // Set a negative margin so that the window can be aligned when positioning it
187
+ // absolute.
188
+ var margin = this.options.width - ( this.options.width * 1.5 );
189
+ container.setStyle('margin-left', margin);
190
+
191
+ // Last step: inject the HTML into the DOM
192
+ this.element = container;
193
+ this.element.inject(document.body);
194
+ },
195
+
196
+ /**
197
+ * Removes the window from the DOM.
198
+ *
199
+ * @author Yorick Peterse
200
+ * @since 0.2.6
201
+ */
202
+ destroy: function()
203
+ {
204
+ this.element.destroy();
205
+ }
206
+ });