Rearrange source to src dir.
[redakcja.git] / src / redakcja / static / js / wiki / toolbar.js
diff --git a/src/redakcja/static/js/wiki/toolbar.js b/src/redakcja/static/js/wiki/toolbar.js
new file mode 100644 (file)
index 0000000..3eafdae
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * Toolbar plugin.
+ */
+(function($) {
+
+    $.fn.toolbarize = function(options) {
+        var $toolbar = $(this);
+        var $container = $('.button_group_container', $toolbar);
+
+        $('.button_group button', $toolbar).click(function(event){
+            event.preventDefault();
+
+            var params = eval("(" + $(this).attr('data-ui-action-params') + ")");
+
+            scriptletCenter.callInteractive({
+                action: $(this).attr('data-ui-action'),
+                context: options.actionContext,
+                extra: params
+            });
+        });
+
+        $toolbar.children().filter('select').change(function(event){
+            var slug = $(this).val();
+            $container.scrollLeft(0);
+            $('*[data-group]').hide().filter('[data-group=' + slug + ']').show();
+        }).change();
+
+        $('button.next', $toolbar).click(function() {
+            var $current_group = $('.button_group:visible', $toolbar);
+            var scroll = $container.scrollLeft();
+
+            var $hidden = $("li", $current_group).filter(function() {
+                return ($(this).position().left + $(this).outerWidth()) > $container.width();
+            }).first();
+
+            if($hidden.length > 0) {
+                scroll = $hidden.position().left + scroll + $hidden.outerWidth() - $container.width() + 1;
+                $container.scrollLeft(scroll);
+            };
+        });
+
+        $('button.prev', $toolbar).click(function() {
+            var $current_group = $('.button_group:visible', $toolbar);
+            var scroll = $container.scrollLeft();
+
+            /* first not visible element is: */
+            var $hidden = $("li", $current_group).filter(function() {
+                return $(this).position().left < 0;
+            }).last();
+
+            if( $hidden.length > 0)
+            {
+                scroll = scroll + $hidden.position().left;
+                $container.scrollLeft(scroll);
+            };
+        });
+
+    };
+
+})(jQuery);
\ No newline at end of file