1/** 2 * Growler 1.0.0 3 * 4 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) 5 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses. 6 * 7 * Written by Kevin Armstrong <[email protected]> 8 * Last updated: 2008.10.14 9 * 10 * Growler is a PrototypeJS based class that displays unobtrusive notices on a page. 11 * It functions much like the Growl (http://growl.info) available on the Mac OS X. 12 * 13 * Changes in 1.0.1: 14 * - 15 * 16 * @todo 17 */ 18Growler = (function(){ 19 20 var noticeOptions = { 21 header: ' ' 22 ,speedin: 0.3 23 ,speedout: 0.5 24 ,outDirection: { y: -20 } 25 ,life: 5 26 ,sticky: false 27 ,className: "" 28 }; 29 var growlerOptions = { 30 location: "tr" 31 ,width: "250px" 32 }; 33 var IE = (Prototype.Browser.IE) ? parseFloat(navigator.appVersion.split("MSIE ")[1]) || 0 : 0; 34 function removeNotice(n, o){ 35 o = o || noticeOptions; 36 new Effect.Parallel([ 37 new Effect.Move(n, Object.extend({ sync: true, mode: 'relative' }, o.outDirection)), 38 new Effect.Opacity(n, { sync: true, to: 0 }) 39 ], { 40 duration: o.speedout 41 ,afterFinish: function(){ 42 try { 43 var ne = n.down("div.notice-exit"); 44 if(ne != undefined){ 45 ne.stopObserving("click", removeNotice); 46 } 47 if(o.created && Object.isFunction(o.created)){ 48 n.stopObserving("notice:created", o.created); 49 } 50 if(o.destroyed && Object.isFunction(o.destroyed)){ 51 n.fire("notice:destroyed"); 52 n.stopObserving("notice:destroyed", o.destroyed); 53 } 54 } catch(e){} 55 try { 56 n.remove(); 57 } catch(e){} 58 } 59 }); 60 } 61 function createNotice(growler, msg, options){ 62 var opt = Object.clone(noticeOptions); 63 options = options || {}; 64 Object.extend(opt, options); 65 var notice; 66 if (opt.className != ""){ 67 notice = new Element("div", {"class": opt.className}).setStyle({display: "block", opacity: 0}); 68 } else { 69 notice = new Element("div", {"class": "Growler-notice"}).setStyle({display: "block", opacity: 0}); 70 } 71 if(opt.created && Object.isFunction(opt.created)){ 72 notice.observe("notice:created", opt.created); 73 } 74 if(opt.destroyed && Object.isFunction(opt.destroyed)){ 75 notice.observe("notice:destroyed", opt.destroyed); 76 } 77 if (opt.sticky){ 78 var noticeExit = new Element("div", {"class": "Growler-notice-exit"}).update("×"); 79 noticeExit.observe("click", function(){ removeNotice(notice, opt); }); 80 notice.insert(noticeExit); 81 } 82 notice.insert(new Element("div", {"class": "Growler-notice-head"}).update(opt.header)); 83 notice.insert(new Element("div", {"class": "Growler-notice-body"}).update(msg)); 84 growler.insert(notice); 85 new Effect.Opacity(notice, { to: 0.85, duration: opt.speedin }); 86 if (!opt.sticky){ 87 removeNotice.delay(opt.life, notice, opt); 88 } 89 notice.fire("notice:created"); 90 return notice; 91 } 92 function specialNotice(g, m, o, t, b, c){ 93 o.header = o.header || t; 94 var n = createNotice(g, m, o); 95 n.setStyle({ backgroundColor: b, color: c }); 96 return n; 97 } 98 return Class.create({ 99 initialize: function(options){ 100 var opt = Object.clone(growlerOptions); 101 options = options || {}; 102 Object.extend(opt, options); 103 this.growler = new Element("div", { "class": "Growler", "id": "Growler" }); 104 this.growler.setStyle({ position: ((IE==6)?"absolute":"fixed"), padding: "10px", "width": opt.width, "z-index": "50000" }); 105 if(IE==6){ 106 var offset = { w: parseInt(this.growler.style.width)+parseInt(this.growler.style.padding)*3, h: parseInt(this.growler.style.height)+parseInt(this.growler.style.padding)*3 }; 107 switch(opt.location){ 108 case "br": 109 this.growler.style.setExpression("left", "( 0 - Growler.offsetWidth + ( document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.clientWidth ) + ( ignoreMe2 = document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ) ) + 'px'"); 110 this.growler.style.setExpression("top", "( 0 - Growler.offsetHeight + ( document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight ) + ( ignoreMe = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ) ) + 'px'"); 111 break; 112 case "tl": 113 this.growler.style.setExpression("left", "( 0 + ( ignoreMe2 = document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ) ) + 'px'"); 114 this.growler.style.setExpression("top", "( 0 + ( ignoreMe = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ) ) + 'px'"); 115 break; 116 case "bl": 117 this.growler.style.setExpression("left", "( 0 + ( ignoreMe2 = document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ) ) + 'px'"); 118 this.growler.style.setExpression("top", "( 0 - Growler.offsetHeight + ( document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight ) + ( ignoreMe = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ) ) + 'px'"); 119 break; 120 default: 121 this.growler.setStyle({right: "auto", bottom: "auto"}); 122 this.growler.style.setExpression("left", "( 0 - Growler.offsetWidth + ( document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.clientWidth ) + ( ignoreMe2 = document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ) ) + 'px'"); 123 this.growler.style.setExpression("top", "( 0 + ( ignoreMe = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ) ) + 'px'"); 124 break; 125 } 126 } else { 127 switch(opt.location){ 128 case "br": 129 this.growler.setStyle({bottom: 0, right: 0}); 130 break; 131 case "tl": 132 this.growler.setStyle({top: 0, left: 0}); 133 break; 134 case "bl": 135 this.growler.setStyle({top: 0, right: 0}); 136 break; 137 case "tc": 138 this.growler.setStyle({top: 0, left: "25%", width: "50%"}); 139 break; 140 case "bc": 141 this.growler.setStyle({bottom: 0, left: "25%", width: "50%"}); 142 break; 143 default: 144 this.growler.setStyle({top: 0, right: 0}); 145 break; 146 } 147 } 148 this.growler.wrap( document.body ); 149 } 150 ,growl: function(msg, options) { 151 return createNotice(this.growler, msg, options); 152 } 153 ,warn: function(msg, options){ 154 return specialNotice(this.growler, msg, options, "Warning!", "#F6BD6F", "#000"); 155 } 156 ,error: function(msg, options){ 157 return specialNotice(this.growler, msg, options, "Critical!", "#F66F82", "#000"); 158 } 159 ,info: function(msg, options){ 160 return specialNotice(this.growler, msg, options, "Information!", "#BBF66F", "#000"); 161 }
162 ,ungrowl: function(n, o){ 163 removeNotice(n, o); 164 } 165 }); 166 167})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.