diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..b4d5d88 Binary files /dev/null and b/.DS_Store differ diff --git a/Gemfile b/Gemfile index 445cdf9..a9648cf 100644 --- a/Gemfile +++ b/Gemfile @@ -34,7 +34,7 @@ end gem 'jquery-rails' # To use ActiveModel has_secure_password -# gem 'bcrypt-ruby', '~> 3.0.0' + gem 'bcrypt-ruby' # To use Jbuilder templates for JSON # gem 'jbuilder' @@ -42,6 +42,9 @@ gem 'jquery-rails' # Use unicorn as the app server gem 'unicorn' +# Pow related gem +gem 'powder' + # Deploy with Capistrano # gem 'capistrano' diff --git a/Gemfile.lock b/Gemfile.lock index 921ee6c..13e1b20 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -29,6 +29,7 @@ GEM i18n (= 0.6.1) multi_json (~> 1.0) arel (3.0.2) + bcrypt-ruby (3.0.1) brakeman (1.9.5) erubis (~> 2.6) fastercsv (~> 1.5) @@ -90,6 +91,8 @@ GEM mime-types (1.22) multi_json (1.7.2) polyglot (0.3.3) + powder (0.2.0) + thor (>= 0.11.5) pry (0.9.12) coderay (~> 1.0.5) method_source (~> 0.8) @@ -162,6 +165,7 @@ PLATFORMS ruby DEPENDENCIES + bcrypt-ruby brakeman bundler-audit coffee-rails (~> 3.2.1) @@ -169,6 +173,7 @@ DEPENDENCIES guard-brakeman guard-shell jquery-rails + powder rails (= 3.2.13) rb-fsevent sass-rails (~> 3.2.3) diff --git a/app/.DS_Store b/app/.DS_Store new file mode 100644 index 0000000..7d37f58 Binary files /dev/null and b/app/.DS_Store differ diff --git a/app/assets/.DS_Store b/app/assets/.DS_Store new file mode 100644 index 0000000..689329d Binary files /dev/null and b/app/assets/.DS_Store differ diff --git a/app/assets/fonts/.DS_Store b/app/assets/fonts/.DS_Store new file mode 100644 index 0000000..a757c17 Binary files /dev/null and b/app/assets/fonts/.DS_Store differ diff --git a/app/assets/fonts/icomoon.dev.svg b/app/assets/fonts/icomoon.dev.svg new file mode 100644 index 0000000..c882486 --- /dev/null +++ b/app/assets/fonts/icomoon.dev.svg @@ -0,0 +1,1930 @@ + + + + +This is a custom SVG font generated by IcoMoon. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/assets/fonts/icomoon.eot b/app/assets/fonts/icomoon.eot new file mode 100644 index 0000000..e016ca0 Binary files /dev/null and b/app/assets/fonts/icomoon.eot differ diff --git a/app/assets/fonts/icomoon.svg b/app/assets/fonts/icomoon.svg new file mode 100644 index 0000000..efb1718 --- /dev/null +++ b/app/assets/fonts/icomoon.svg @@ -0,0 +1,1930 @@ + + + + +This is a custom SVG font generated by IcoMoon. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/assets/fonts/icomoon.ttf b/app/assets/fonts/icomoon.ttf new file mode 100644 index 0000000..6ae9773 Binary files /dev/null and b/app/assets/fonts/icomoon.ttf differ diff --git a/app/assets/fonts/icomoon.woff b/app/assets/fonts/icomoon.woff new file mode 100644 index 0000000..7fef63d Binary files /dev/null and b/app/assets/fonts/icomoon.woff differ diff --git a/app/assets/images/.DS_Store b/app/assets/images/.DS_Store new file mode 100644 index 0000000..772a848 Binary files /dev/null and b/app/assets/images/.DS_Store differ diff --git a/app/assets/javascripts/.DS_Store b/app/assets/javascripts/.DS_Store new file mode 100644 index 0000000..2a579a9 Binary files /dev/null and b/app/assets/javascripts/.DS_Store differ diff --git a/app/assets/javascripts/alertify.min.js b/app/assets/javascripts/alertify.min.js new file mode 100644 index 0000000..88e76de --- /dev/null +++ b/app/assets/javascripts/alertify.min.js @@ -0,0 +1,12 @@ +/** + * alertify + * An unobtrusive customizable JavaScript notification system + * + * @author Fabien Doiron + * @copyright Fabien Doiron 2013 + * @license MIT + * @link http://fabien-d.github.com/alertify.js/ + * @module alertify + * @version 0.3.7 + */ +(function(e,t){"use strict";var n=e.document,r;r=function(){var e={},r={},i=!1,s={ENTER:13,ESC:27,SPACE:32},o=[],u,a,f,l,c,h,p,d,v,m,g,y;return r={buttons:{holder:'',submit:'',ok:'{{ok}}',cancel:'{{cancel}}'},input:'
',message:'

{{message}}

',log:'
{{message}}
'},y=function(){var e,r=n.createElement("fakeelement"),i={WebkitTransition:"webkitTransitionEnd",MozTransition:"transitionend",OTransition:"otransitionend",transition:"transitionend"};for(e in i)if(r.style[e]!==t)return i[e]},u=function(e){return n.getElementById(e)},e={labels:{ok:"OK",cancel:"Cancel"},delay:5e3,buttonReverse:!1,buttonFocus:"ok",transition:t,addListeners:function(e){var t=typeof f!="undefined",r=typeof a!="undefined",i=typeof g!="undefined",o="",u=this,c,h,p,d,v;c=function(t){return typeof t.preventDefault!="undefined"&&t.preventDefault(),p(t),typeof g!="undefined"&&(o=g.value),typeof e=="function"&&(typeof g!="undefined"?e(!0,o):e(!0)),!1},h=function(t){return typeof t.preventDefault!="undefined"&&t.preventDefault(),p(t),typeof e=="function"&&e(!1),!1},p=function(e){u.hide(),u.unbind(n.body,"keyup",d),u.unbind(l,"focus",v),i&&u.unbind(m,"submit",c),t&&u.unbind(f,"click",c),r&&u.unbind(a,"click",h)},d=function(e){var t=e.keyCode;t===s.SPACE&&!i&&c(e),t===s.ESC&&r&&h(e)},v=function(e){i?g.focus():r?a.focus():f.focus()},this.bind(l,"focus",v),t&&this.bind(f,"click",c),r&&this.bind(a,"click",h),this.bind(n.body,"keyup",d),i&&this.bind(m,"submit",c),typeof this.transition=="undefined"&&this.setFocus()},bind:function(e,t,n){typeof e.addEventListener=="function"?e.addEventListener(t,n,!1):e.attachEvent&&e.attachEvent("on"+t,n)},appendButtons:function(e,t){return this.buttonReverse?t+e:e+t},build:function(t){var n="",i=t.type,s=t.message,o=t.cssClass||"";n+='
',e.buttonFocus==="none"&&(n+=''),i==="prompt"&&(n+='
'),n+='
',n+=r.message.replace("{{message}}",s),i==="prompt"&&(n+=r.input),n+=r.buttons.holder,n+="
",i==="prompt"&&(n+="
"),n+='Reset Focus',n+="
";switch(i){case"confirm":n=n.replace("{{buttons}}",this.appendButtons(r.buttons.cancel,r.buttons.ok)),n=n.replace("{{ok}}",this.labels.ok).replace("{{cancel}}",this.labels.cancel);break;case"prompt":n=n.replace("{{buttons}}",this.appendButtons(r.buttons.cancel,r.buttons.submit)),n=n.replace("{{ok}}",this.labels.ok).replace("{{cancel}}",this.labels.cancel);break;case"alert":n=n.replace("{{buttons}}",r.buttons.ok),n=n.replace("{{ok}}",this.labels.ok);break;default:}return d.className="alertify alertify-show alertify-"+i+" "+o,p.className="alertify-cover",n},close:function(e,t){var n=t&&!isNaN(t)?+t:this.delay,r=this,i,s;this.bind(e,"click",function(){i(e)}),s=function(e){e.stopPropagation(),r.unbind(this,r.transition,s),v.removeChild(this),v.hasChildNodes()||(v.className+=" alertify-logs-hidden")},i=function(e){typeof e!="undefined"&&e.parentNode===v&&(typeof r.transition!="undefined"?(r.bind(e,r.transition,s),e.className+=" alertify-log-hide"):(v.removeChild(e),v.hasChildNodes()||(v.className+=" alertify-logs-hidden")))};if(t===0)return;setTimeout(function(){i(e)},n)},dialog:function(e,t,r,s,u){h=n.activeElement;var a=function(){if(d&&d.scrollTop!==null)return;a()};if(typeof e!="string")throw new Error("message must be a string");if(typeof t!="string")throw new Error("type must be a string");if(typeof r!="undefined"&&typeof r!="function")throw new Error("fn must be a function");return typeof this.init=="function"&&(this.init(),a()),o.push({type:t,message:e,callback:r,placeholder:s,cssClass:u}),i||this.setup(),this},extend:function(e){if(typeof e!="string")throw new Error("extend method must have exactly one paramter");return function(t,n){return this.log(t,e,n),this}},hide:function(){var e,t=this;o.splice(0,1),o.length>0?this.setup():(i=!1,e=function(n){n.stopPropagation(),d.className+=" alertify-isHidden",t.unbind(d,t.transition,e)},typeof this.transition!="undefined"?(this.bind(d,this.transition,e),d.className="alertify alertify-hide alertify-hidden"):d.className="alertify alertify-hide alertify-hidden alertify-isHidden",p.className="alertify-cover alertify-cover-hidden",h.focus())},init:function(){n.createElement("nav"),n.createElement("article"),n.createElement("section"),p=n.createElement("div"),p.setAttribute("id","alertify-cover"),p.className="alertify-cover alertify-cover-hidden",n.body.appendChild(p),d=n.createElement("section"),d.setAttribute("id","alertify"),d.className="alertify alertify-hidden",n.body.appendChild(d),v=n.createElement("section"),v.setAttribute("id","alertify-logs"),v.className="alertify-logs alertify-logs-hidden",n.body.appendChild(v),n.body.setAttribute("tabindex","0"),this.transition=y(),delete this.init},log:function(e,t,n){var r=function(){if(v&&v.scrollTop!==null)return;r()};return typeof this.init=="function"&&(this.init(),r()),v.className="alertify-logs",this.notify(e,t,n),this},notify:function(e,t,r){var i=n.createElement("article");i.className="alertify-log"+(typeof t=="string"&&t!==""?" alertify-log-"+t:""),i.innerHTML=e,v.insertBefore(i,v.firstChild),setTimeout(function(){i.className=i.className+" alertify-log-show"},50),this.close(i,r)},set:function(e){var t;if(typeof e!="object"&&e instanceof Array)throw new Error("args must be an object");for(t in e)e.hasOwnProperty(t)&&(this[t]=e[t])},setFocus:function(){g?(g.focus(),g.select()):c.focus()},setup:function(){var n=o[0],r=this,s;i=!0,s=function(e){e.stopPropagation(),r.setFocus(),r.unbind(d,r.transition,s)},typeof this.transition!="undefined"&&this.bind(d,this.transition,s),d.innerHTML=this.build(n),l=u("alertify-resetFocus"),f=u("alertify-ok")||t,a=u("alertify-cancel")||t,c=e.buttonFocus==="cancel"?a:e.buttonFocus==="none"?u("alertify-noneFocus"):f,g=u("alertify-text")||t,m=u("alertify-form")||t,typeof n.placeholder=="string"&&n.placeholder!==""&&(g.value=n.placeholder),this.addListeners(n.callback)},unbind:function(e,t,n){typeof e.removeEventListener=="function"?e.removeEventListener(t,n,!1):e.detachEvent&&e.detachEvent("on"+t,n)}},{alert:function(t,n,r){return e.dialog(t,"alert",n,"",r),this},confirm:function(t,n,r){return e.dialog(t,"confirm",n,"",r),this},extend:e.extend,init:e.init,log:function(t,n,r){return e.log(t,n,r),this},prompt:function(t,n,r,i){return e.dialog(t,"prompt",n,r,i),this},success:function(t,n){return e.log(t,"success",n),this},error:function(t,n){return e.log(t,"error",n),this},set:function(t){e.set(t)},labels:e.labels}},typeof define=="function"?define([],function(){return new r}):typeof e.alertify=="undefined"&&(e.alertify=new r)})(this); \ No newline at end of file diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 9097d83..d6f96ab 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -12,4 +12,12 @@ // //= require jquery //= require jquery_ujs -//= require_tree . +//= require wysiwyg/wysihtml5-0.3.0.js +//= require jquery.min.js +//= require bootstrap.js +//= require jquery.scrollUp.js +//= require wysiwyg/bootstrap-wysihtml5.js +//= require date-picker/date.js +//= require date-picker/daterangepicker.js +//= require jquery.sparkline.js +//= require tiny-scrollbar.js \ No newline at end of file diff --git a/app/assets/javascripts/bootstrap-colorpicker.js b/app/assets/javascripts/bootstrap-colorpicker.js new file mode 100644 index 0000000..6a0fc8a --- /dev/null +++ b/app/assets/javascripts/bootstrap-colorpicker.js @@ -0,0 +1,540 @@ +/* ========================================================= + * bootstrap-colorpicker.js + * http://www.eyecon.ro/bootstrap-colorpicker + * ========================================================= + * Copyright 2012 Stefan Petre + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ========================================================= */ + +!function( $ ) { + + // Color object + + var Color = function(val) { + this.value = { + h: 1, + s: 1, + b: 1, + a: 1 + }; + this.setColor(val); + }; + + Color.prototype = { + constructor: Color, + + //parse a string to HSB + setColor: function(val){ + val = val.toLowerCase(); + var that = this; + $.each( CPGlobal.stringParsers, function( i, parser ) { + var match = parser.re.exec( val ), + values = match && parser.parse( match ), + space = parser.space||'rgba'; + if ( values ) { + if (space === 'hsla') { + that.value = CPGlobal.RGBtoHSB.apply(null, CPGlobal.HSLtoRGB.apply(null, values)); + } else { + that.value = CPGlobal.RGBtoHSB.apply(null, values); + } + return false; + } + }); + }, + + setHue: function(h) { + this.value.h = 1- h; + }, + + setSaturation: function(s) { + this.value.s = s; + }, + + setLightness: function(b) { + this.value.b = 1- b; + }, + + setAlpha: function(a) { + this.value.a = parseInt((1 - a)*100, 10)/100; + }, + + // HSBtoRGB from RaphaelJS + // https://github.com/DmitryBaranovskiy/raphael/ + toRGB: function(h, s, b, a) { + if (!h) { + h = this.value.h; + s = this.value.s; + b = this.value.b; + } + h *= 360; + var R, G, B, X, C; + h = (h % 360) / 60; + C = b * s; + X = C * (1 - Math.abs(h % 2 - 1)); + R = G = B = b - C; + + h = ~~h; + R += [C, X, 0, 0, X, C][h]; + G += [X, C, C, X, 0, 0][h]; + B += [0, 0, X, C, C, X][h]; + return { + r: Math.round(R*255), + g: Math.round(G*255), + b: Math.round(B*255), + a: a||this.value.a + }; + }, + + toHex: function(h, s, b, a){ + var rgb = this.toRGB(h, s, b, a); + return '#'+((1 << 24) | (parseInt(rgb.r) << 16) | (parseInt(rgb.g) << 8) | parseInt(rgb.b)).toString(16).substr(1); + }, + + toHSL: function(h, s, b, a){ + if (!h) { + h = this.value.h; + s = this.value.s; + b = this.value.b; + } + var H = h, + L = (2 - s) * b, + S = s * b; + if (L > 0 && L <= 1) { + S /= L; + } else { + S /= 2 - L; + } + L /= 2; + if (S > 1) { + S = 1; + } + return { + h: H, + s: S, + l: L, + a: a||this.value.a + }; + } + }; + + // Picker object + + var Colorpicker = function(element, options){ + this.element = $(element); + var format = options.format||this.element.data('color-format')||'hex'; + this.format = CPGlobal.translateFormats[format]; + this.isInput = this.element.is('input'); + this.component = this.element.is('.color') ? this.element.find('.add-on') : false; + + this.picker = $(CPGlobal.template) + .appendTo('body') + .on('mousedown', $.proxy(this.mousedown, this)); + + if (this.isInput) { + this.element.on({ + 'focus': $.proxy(this.show, this), + 'keyup': $.proxy(this.update, this) + }); + } else if (this.component){ + this.component.on({ + 'click': $.proxy(this.show, this) + }); + } else { + this.element.on({ + 'click': $.proxy(this.show, this) + }); + } + if (format === 'rgba' || format === 'hsla') { + this.picker.addClass('alpha'); + this.alpha = this.picker.find('.colorpicker-alpha')[0].style; + } + + if (this.component){ + this.picker.find('.colorpicker-color').hide(); + this.preview = this.element.find('i')[0].style; + } else { + this.preview = this.picker.find('div:last')[0].style; + } + + this.base = this.picker.find('div:first')[0].style; + this.update(); + }; + + Colorpicker.prototype = { + constructor: Colorpicker, + + show: function(e) { + this.picker.show(); + this.height = this.component ? this.component.outerHeight() : this.element.outerHeight(); + this.place(); + $(window).on('resize', $.proxy(this.place, this)); + if (!this.isInput) { + if (e) { + e.stopPropagation(); + e.preventDefault(); + } + } + $(document).on({ + 'mousedown': $.proxy(this.hide, this) + }); + this.element.trigger({ + type: 'show', + color: this.color + }); + }, + + update: function(){ + this.color = new Color(this.isInput ? this.element.prop('value') : this.element.data('color')); + this.picker.find('i') + .eq(0).css({left: this.color.value.s*100, top: 100 - this.color.value.b*100}).end() + .eq(1).css('top', 100 * (1 - this.color.value.h)).end() + .eq(2).css('top', 100 * (1 - this.color.value.a)); + this.previewColor(); + }, + + setValue: function(newColor) { + this.color = new Color(newColor); + this.picker.find('i') + .eq(0).css({left: this.color.value.s*100, top: 100 - this.color.value.b*100}).end() + .eq(1).css('top', 100 * (1 - this.color.value.h)).end() + .eq(2).css('top', 100 * (1 - this.color.value.a)); + this.previewColor(); + this.element.trigger({ + type: 'changeColor', + color: this.color + }); + }, + + hide: function(){ + this.picker.hide(); + $(window).off('resize', this.place); + if (!this.isInput) { + $(document).off({ + 'mousedown': this.hide + }); + if (this.component){ + this.element.find('input').prop('value', this.format.call(this)); + } + this.element.data('color', this.format.call(this)); + } else { + this.element.prop('value', this.format.call(this)); + } + this.element.trigger({ + type: 'hide', + color: this.color + }); + }, + + place: function(){ + var offset = this.component ? this.component.offset() : this.element.offset(); + this.picker.css({ + top: offset.top + this.height, + left: offset.left + }); + }, + + //preview color change + previewColor: function(){ + try { + this.preview.backgroundColor = this.format.call(this); + } catch(e) { + this.preview.backgroundColor = this.color.toHex(); + } + //set the color for brightness/saturation slider + this.base.backgroundColor = this.color.toHex(this.color.value.h, 1, 1, 1); + //set te color for alpha slider + if (this.alpha) { + this.alpha.backgroundColor = this.color.toHex(); + } + }, + + pointer: null, + + slider: null, + + mousedown: function(e){ + e.stopPropagation(); + e.preventDefault(); + + var target = $(e.target); + + //detect the slider and set the limits and callbacks + var zone = target.closest('div'); + if (!zone.is('.colorpicker')) { + if (zone.is('.colorpicker-saturation')) { + this.slider = $.extend({}, CPGlobal.sliders.saturation); + } + else if (zone.is('.colorpicker-hue')) { + this.slider = $.extend({}, CPGlobal.sliders.hue); + } + else if (zone.is('.colorpicker-alpha')) { + this.slider = $.extend({}, CPGlobal.sliders.alpha); + } else { + return false; + } + var offset = zone.offset(); + //reference to knob's style + this.slider.knob = zone.find('i')[0].style; + this.slider.left = e.pageX - offset.left; + this.slider.top = e.pageY - offset.top; + this.pointer = { + left: e.pageX, + top: e.pageY + }; + //trigger mousemove to move the knob to the current position + $(document).on({ + mousemove: $.proxy(this.mousemove, this), + mouseup: $.proxy(this.mouseup, this) + }).trigger('mousemove'); + } + return false; + }, + + mousemove: function(e){ + e.stopPropagation(); + e.preventDefault(); + var left = Math.max( + 0, + Math.min( + this.slider.maxLeft, + this.slider.left + ((e.pageX||this.pointer.left) - this.pointer.left) + ) + ); + var top = Math.max( + 0, + Math.min( + this.slider.maxTop, + this.slider.top + ((e.pageY||this.pointer.top) - this.pointer.top) + ) + ); + this.slider.knob.left = left + 'px'; + this.slider.knob.top = top + 'px'; + if (this.slider.callLeft) { + this.color[this.slider.callLeft].call(this.color, left/100); + } + if (this.slider.callTop) { + this.color[this.slider.callTop].call(this.color, top/100); + } + this.previewColor(); + this.element.trigger({ + type: 'changeColor', + color: this.color + }); + return false; + }, + + mouseup: function(e){ + e.stopPropagation(); + e.preventDefault(); + $(document).off({ + mousemove: this.mousemove, + mouseup: this.mouseup + }); + return false; + } + } + + $.fn.colorpicker = function ( option ) { + return this.each(function () { + var $this = $(this), + data = $this.data('colorpicker'), + options = typeof option === 'object' && option; + if (!data) { + $this.data('colorpicker', (data = new Colorpicker(this, $.extend({}, $.fn.colorpicker.defaults,options)))); + } + if (typeof option === 'string') data[option](); + }); + }; + + $.fn.colorpicker.defaults = { + }; + + $.fn.colorpicker.Constructor = Colorpicker; + + var CPGlobal = { + + // translate a format from Color object to a string + translateFormats: { + 'rgb': function(){ + var rgb = this.color.toRGB(); + return 'rgb('+rgb.r+','+rgb.g+','+rgb.b+')'; + }, + + 'rgba': function(){ + var rgb = this.color.toRGB(); + return 'rgba('+rgb.r+','+rgb.g+','+rgb.b+','+rgb.a+')'; + }, + + 'hsl': function(){ + var hsl = this.color.toHSL(); + return 'hsl('+Math.round(hsl.h*360)+','+Math.round(hsl.s*100)+'%,'+Math.round(hsl.l*100)+'%)'; + }, + + 'hsla': function(){ + var hsl = this.color.toHSL(); + return 'hsla('+Math.round(hsl.h*360)+','+Math.round(hsl.s*100)+'%,'+Math.round(hsl.l*100)+'%,'+hsl.a+')'; + }, + + 'hex': function(){ + return this.color.toHex(); + } + }, + + sliders: { + saturation: { + maxLeft: 100, + maxTop: 100, + callLeft: 'setSaturation', + callTop: 'setLightness' + }, + + hue: { + maxLeft: 0, + maxTop: 100, + callLeft: false, + callTop: 'setHue' + }, + + alpha: { + maxLeft: 0, + maxTop: 100, + callLeft: false, + callTop: 'setAlpha' + } + }, + + // HSBtoRGB from RaphaelJS + // https://github.com/DmitryBaranovskiy/raphael/ + RGBtoHSB: function (r, g, b, a){ + r /= 255; + g /= 255; + b /= 255; + + var H, S, V, C; + V = Math.max(r, g, b); + C = V - Math.min(r, g, b); + H = (C === 0 ? null : + V == r ? (g - b) / C : + V == g ? (b - r) / C + 2 : + (r - g) / C + 4 + ); + H = ((H + 360) % 6) * 60 / 360; + S = C === 0 ? 0 : C / V; + return {h: H||1, s: S, b: V, a: a||1}; + }, + + HueToRGB: function (p, q, h) { + if (h < 0) + h += 1; + else if (h > 1) + h -= 1; + + if ((h * 6) < 1) + return p + (q - p) * h * 6; + else if ((h * 2) < 1) + return q; + else if ((h * 3) < 2) + return p + (q - p) * ((2 / 3) - h) * 6; + else + return p; + }, + + HSLtoRGB: function (h, s, l, a) + { + if (s < 0) { + s = 0; + } + var q; + if (l <= 0.5) { + q = l * (1 + s); + } else { + q = l + s - (l * s); + } + + var p = 2 * l - q; + + var tr = h + (1 / 3); + var tg = h; + var tb = h - (1 / 3); + + var r = Math.round(CPGlobal.HueToRGB(p, q, tr) * 255); + var g = Math.round(CPGlobal.HueToRGB(p, q, tg) * 255); + var b = Math.round(CPGlobal.HueToRGB(p, q, tb) * 255); + return [r, g, b, a||1]; + }, + + // a set of RE's that can match strings and generate color tuples. + // from John Resig color plugin + // https://github.com/jquery/jquery-color/ + stringParsers: [ + { + re: /rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*(?:,\s*(\d+(?:\.\d+)?)\s*)?\)/, + parse: function( execResult ) { + return [ + execResult[ 1 ], + execResult[ 2 ], + execResult[ 3 ], + execResult[ 4 ] + ]; + } + }, { + re: /rgba?\(\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*(?:,\s*(\d+(?:\.\d+)?)\s*)?\)/, + parse: function( execResult ) { + return [ + 2.55 * execResult[1], + 2.55 * execResult[2], + 2.55 * execResult[3], + execResult[ 4 ] + ]; + } + }, { + re: /#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/, + parse: function( execResult ) { + return [ + parseInt( execResult[ 1 ], 16 ), + parseInt( execResult[ 2 ], 16 ), + parseInt( execResult[ 3 ], 16 ) + ]; + } + }, { + re: /#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/, + parse: function( execResult ) { + return [ + parseInt( execResult[ 1 ] + execResult[ 1 ], 16 ), + parseInt( execResult[ 2 ] + execResult[ 2 ], 16 ), + parseInt( execResult[ 3 ] + execResult[ 3 ], 16 ) + ]; + } + }, { + re: /hsla?\(\s*(\d+(?:\.\d+)?)\s*,\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*(?:,\s*(\d+(?:\.\d+)?)\s*)?\)/, + space: 'hsla', + parse: function( execResult ) { + return [ + execResult[1]/360, + execResult[2] / 100, + execResult[3] / 100, + execResult[4] + ]; + } + } + ], + template: '