'src/javascripts/cowhide-select.js',
'src/javascripts/cowhide-page.js',
'src/javascripts/cowhide-header.js',
- 'src/javascripts/cowhide-scrollable.js',
'src/javascripts/cowhide-simple-scrollable.js'
], dest: 'dist/cowhide.js'
},
--- /dev/null
+/* vi: set et sw=4 ts=4 si: */
+(function($, undefined) {
+ 'use strict';
+
+ var ChSimpleScrollable = function(element, options) {
+ $.fn.ch_widget.Constructor(element, options);
+ this.$element = $(element);
+ this.options = $.extend(
+ options,
+ $.fn.ch_widget.defaults,
+ {
+ });
+ };
+
+ ChSimpleScrollable.prototype = $.extend(
+ {},
+ $.fn.ch_widget.Constructor.prototype,
+ {
+ constructor: ChSimpleScrollable,
+
+ enable: function() {
+ var self = this,
+ $this = self.$element,
+ $up = $('<div/>').addClass('ch-simple-scrollable-up'),
+ $dn = $('<div/>').addClass('ch-simple-scrollable-dn'),
+ $child = $this.find('ul, ol, div, p'),
+ scrollAmount;
+
+ $child.addClass('ch-simple-scrollable-content');
+ $child.height($child.parent().height() - 160);
+ scrollAmount = $child.height() - 40;
+
+
+ $up.css({top: $child.offset().top});
+
+ $up.html('<a href="#"><i class="icon-chevron-up"></i></a>');
+ $dn.html('<a href="#"><i class="icon-chevron-down"></i></a>');
+
+ $dn.click(function() {
+ $child.animate({
+ scrollTop: $child.scrollTop() + scrollAmount
+ }, 200);
+ });
+
+ $up.click(function() {
+ $child.animate({
+ scrollTop: $child.scrollTop() - scrollAmount
+ }, 200);
+ });
+
+
+ $up.insertBefore($child);
+ $dn.insertAfter($child);
+ }
+ }
+ );
+
+ $.fn.ch_simple_scrollable = function(option) {
+ return this.each(function() {
+ var $this = $(this),
+ data = $this.data('ch_simple_scrollable'),
+ options = typeof option == 'object' && option;
+
+ if (!data) {
+ $this.data('ch_simple_scrollable', (data = new ChSimpleScrollable(this, options)));
+ data.register();
+ }
+
+ if(typeof option == 'string')
+ data[option]();
+ });
+ };
+
+ $.fn.ch_simple_scrollable.Constructor = ChSimpleScrollable;
+
+ /* CHSIMPLESCROLLABLE DATA-API
+ * ================= */
+ $(function() {
+ $('div.ch-simple-scrollable').ch_simple_scrollable('enable');
+ })
+})(window.jQuery);
<script src="../src/javascripts/cowhide-page.js"></script>
<script src="../src/javascripts/cowhide-radio-input.js"></script>
<script src="../src/javascripts/cowhide-select.js"></script>
+ <script src="../src/javascripts/cowhide-simple-scrollable.js"></script>
<!-- unit tests -->
<script src="unit/cowhide-page.js"></script>
<script src="unit/cowhide-radio-input.js"></script>
<script src="unit/cowhide-select.js"></script>
+ <script src="unit/cowhide-simple-scrollable.js"></script>
</head>
<body>
<div>
--- /dev/null
+$(function () {
+
+ module("cowhide-simple-scrollable")
+
+ test("widget has been made scrollable", function () {
+ var page = $('<div class="page"></div>')
+ var scrollable = $('<div class="ch-simple-scrollable"><p>Test</p></div>')
+
+ scrollable.appendTo(page)
+ scrollable.ch_simple_scrollable('enable')
+
+ ok(scrollable.find('.ch-simple-scrollable-content').length > 0, "element has ch-simple-scrollable-content child")
+ })
+})