-
Notifications
You must be signed in to change notification settings - Fork 0
/
hn-button.min.js
1 lines (1 loc) · 9.3 KB
/
hn-button.min.js
1
(function(){function require(path,parent,orig){var resolved=require.resolve(path);if(null==resolved){orig=orig||path;parent=parent||"root";var err=new Error('Failed to require "'+orig+'" from "'+parent+'"');err.path=orig;err.parent=parent;err.require=true;throw err}var module=require.modules[resolved];if(!module._resolving&&!module.exports){var mod={};mod.exports={};mod.client=mod.component=true;module._resolving=true;module.call(this,mod.exports,require.relative(resolved),mod);delete module._resolving;module.exports=mod.exports}return module.exports}require.modules={};require.aliases={};require.resolve=function(path){if(path.charAt(0)==="/")path=path.slice(1);var paths=[path,path+".js",path+".json",path+"/index.js",path+"/index.json"];for(var i=0;i<paths.length;i++){var path=paths[i];if(require.modules.hasOwnProperty(path))return path;if(require.aliases.hasOwnProperty(path))return require.aliases[path]}};require.normalize=function(curr,path){var segs=[];if("."!=path.charAt(0))return path;curr=curr.split("/");path=path.split("/");for(var i=0;i<path.length;++i){if(".."==path[i]){curr.pop()}else if("."!=path[i]&&""!=path[i]){segs.push(path[i])}}return curr.concat(segs).join("/")};require.register=function(path,definition){require.modules[path]=definition};require.alias=function(from,to){if(!require.modules.hasOwnProperty(from)){throw new Error('Failed to alias "'+from+'", it does not exist')}require.aliases[to]=from};require.relative=function(parent){var p=require.normalize(parent,"..");function lastIndexOf(arr,obj){var i=arr.length;while(i--){if(arr[i]===obj)return i}return-1}function localRequire(path){var resolved=localRequire.resolve(path);return require(resolved,parent,path)}localRequire.resolve=function(path){var c=path.charAt(0);if("/"==c)return path.slice(1);if("."==c)return require.normalize(p,path);var segs=parent.split("/");var i=lastIndexOf(segs,"deps")+1;if(!i)i=0;path=segs.slice(0,i+1).join("/")+"/deps/"+path;return path};localRequire.exists=function(path){return require.modules.hasOwnProperty(localRequire.resolve(path))};return localRequire};require.register("component-bind/index.js",function(exports,require,module){var slice=[].slice;module.exports=function(obj,fn){if("string"==typeof fn)fn=obj[fn];if("function"!=typeof fn)throw new Error("bind() requires a function");var args=[].slice.call(arguments,2);return function(){return fn.apply(obj,args.concat(slice.call(arguments)))}}});require.register("component-type/index.js",function(exports,require,module){var toString=Object.prototype.toString;module.exports=function(val){switch(toString.call(val)){case"[object Function]":return"function";case"[object Date]":return"date";case"[object RegExp]":return"regexp";case"[object Arguments]":return"arguments";case"[object Array]":return"array";case"[object String]":return"string"}if(val===null)return"null";if(val===undefined)return"undefined";if(val&&val.nodeType===1)return"element";if(val===Object(val))return"object";return typeof val}});require.register("component-each/index.js",function(exports,require,module){var type=require("type");var has=Object.prototype.hasOwnProperty;module.exports=function(obj,fn){switch(type(obj)){case"array":return array(obj,fn);case"object":if("number"==typeof obj.length)return array(obj,fn);return object(obj,fn);case"string":return string(obj,fn)}};function string(obj,fn){for(var i=0;i<obj.length;++i){fn(obj.charAt(i),i)}}function object(obj,fn){for(var key in obj){if(has.call(obj,key)){fn(key,obj[key])}}}function array(obj,fn){for(var i=0;i<obj.length;++i){fn(obj[i],i)}}});require.register("component-indexof/index.js",function(exports,require,module){var indexOf=[].indexOf;module.exports=function(arr,obj){if(indexOf)return arr.indexOf(obj);for(var i=0;i<arr.length;++i){if(arr[i]===obj)return i}return-1}});require.register("component-emitter/index.js",function(exports,require,module){var index=require("indexof");module.exports=Emitter;function Emitter(obj){if(obj)return mixin(obj)}function mixin(obj){for(var key in Emitter.prototype){obj[key]=Emitter.prototype[key]}return obj}Emitter.prototype.on=function(event,fn){this._callbacks=this._callbacks||{};(this._callbacks[event]=this._callbacks[event]||[]).push(fn);return this};Emitter.prototype.once=function(event,fn){var self=this;this._callbacks=this._callbacks||{};function on(){self.off(event,on);fn.apply(this,arguments)}fn._off=on;this.on(event,on);return this};Emitter.prototype.off=Emitter.prototype.removeListener=Emitter.prototype.removeAllListeners=function(event,fn){this._callbacks=this._callbacks||{};if(0==arguments.length){this._callbacks={};return this}var callbacks=this._callbacks[event];if(!callbacks)return this;if(1==arguments.length){delete this._callbacks[event];return this}var i=index(callbacks,fn._off||fn);if(~i)callbacks.splice(i,1);return this};Emitter.prototype.emit=function(event){this._callbacks=this._callbacks||{};var args=[].slice.call(arguments,1),callbacks=this._callbacks[event];if(callbacks){callbacks=callbacks.slice(0);for(var i=0,len=callbacks.length;i<len;++i){callbacks[i].apply(this,args)}}return this};Emitter.prototype.listeners=function(event){this._callbacks=this._callbacks||{};return this._callbacks[event]||[]};Emitter.prototype.hasListeners=function(event){return!!this.listeners(event).length}});require.register("component-event/index.js",function(exports,require,module){exports.bind=function(el,type,fn,capture){if(el.addEventListener){el.addEventListener(type,fn,capture||false)}else{el.attachEvent("on"+type,fn)}return fn};exports.unbind=function(el,type,fn,capture){if(el.removeEventListener){el.removeEventListener(type,fn,capture||false)}else{el.detachEvent("on"+type,fn)}return fn}});require.register("component-query/index.js",function(exports,require,module){function one(selector,el){return el.querySelector(selector)}exports=module.exports=function(selector,el){el=el||document;return one(selector,el)};exports.all=function(selector,el){el=el||document;return el.querySelectorAll(selector)};exports.engine=function(obj){if(!obj.one)throw new Error(".one callback required");if(!obj.all)throw new Error(".all callback required");one=obj.one;exports.all=obj.all}});require.register("matthewmueller-uid/index.js",function(exports,require,module){module.exports=uid;function uid(len){len=len||7;return Math.random().toString(35).substr(2,len)}});require.register("hn-button/index.js",function(exports,require,module){var bind=require("bind"),each=require("each"),Emitter=require("emitter"),on=require("event").bind,query=require("query"),uid=require("uid");var HN=new Emitter;HN.on("load",function(event){var iframe=event.target;iframe.width=Math.ceil(event.width)});HN.initialize=function(a){new Button(a)};function Button(a){var host=a.getAttribute("data-host")||"hn-button.herokuapp.com";this.origin=location.protocol+"//"+host;this.id="hn-button-"+uid();on(window,"message",bind(this,this.onMessage));this.render(a)}Button.prototype.render=function(a){var options={title:a.getAttribute("data-title")||document.title,url:a.getAttribute("data-url")||window.location.href,style:a.getAttribute("data-style"),count:a.getAttribute("data-count")};var iframe=this.iframe=document.createElement("iframe");iframe.src=this.origin+stringify(options);iframe.id=iframe.name=this.id;iframe.className="hn-button";iframe.setAttribute("data-title",options.title);iframe.setAttribute("data-url",options.url);if(options.style)iframe.setAttribute("data-style",options.style);if(options.count)iframe.setAttribute("data-count",options.count);iframe.title="Hacker News Button";iframe.height=options.count==="vertical"?62:20;iframe.width=100;iframe.frameBorder=0;a.parentNode.insertBefore(iframe,a);a.parentNode.removeChild(a)};Button.prototype.onMessage=function(message){if(message.origin!==this.origin)return;if(message.data.id!==this.id)return;var event=message.data.event,data=message.data.data;data.type=event;data.id=this.id;data.target=this.iframe;HN.emit(event,data)};function stringify(options){var query="";each(options,function(key,value){if("host"==key)return;query+=query?"&":"?";if(value)query+=key+"="+encodeURIComponent(value)});return query}each(query.all(".hn-button"),HN.initialize);if(window.HN)while(window.HN.length>0){var item=window.HN.shift();var method=item.shift();if(HN[method])HN[method].apply(HN,item)}module.exports=HN});require.alias("component-bind/index.js","hn-button/deps/bind/index.js");require.alias("component-bind/index.js","bind/index.js");require.alias("component-each/index.js","hn-button/deps/each/index.js");require.alias("component-each/index.js","each/index.js");require.alias("component-type/index.js","component-each/deps/type/index.js");require.alias("component-emitter/index.js","hn-button/deps/emitter/index.js");require.alias("component-emitter/index.js","emitter/index.js");require.alias("component-indexof/index.js","component-emitter/deps/indexof/index.js");require.alias("component-event/index.js","hn-button/deps/event/index.js");require.alias("component-event/index.js","event/index.js");require.alias("component-query/index.js","hn-button/deps/query/index.js");require.alias("component-query/index.js","query/index.js");require.alias("matthewmueller-uid/index.js","hn-button/deps/uid/index.js");require.alias("matthewmueller-uid/index.js","uid/index.js");if(typeof exports=="object"){module.exports=require("hn-button")}else if(typeof define=="function"&&define.amd){define([],function(){return require("hn-button")})}else{this["HN"]=require("hn-button")}})();