"!==m[1]||ha.test(g)?0:i:i.firstChild,f=g&&g.childNodes.length;while(f--)n.nodeName(k=g.childNodes[f],"tbody")&&!k.childNodes.length&&g.removeChild(k)}n.merge(q,i.childNodes),i.textContent="";while(i.firstChild)i.removeChild(i.firstChild);i=p.lastChild}else q.push(b.createTextNode(g));i&&p.removeChild(i),l.appendChecked||n.grep(ea(q,"input"),ia),r=0;while(g=q[r++])if(d&&n.inArray(g,d)>-1)e&&e.push(g);else if(h=n.contains(g.ownerDocument,g),i=ea(p.appendChild(g),"script"),h&&fa(i),c){f=0;while(g=i[f++])_.test(g.type||"")&&c.push(g)}return i=null,p}!function(){var b,c,e=d.createElement("div");for(b in{submit:!0,change:!0,focusin:!0})c="on"+b,(l[b]=c in a)||(e.setAttribute(c,"t"),l[b]=e.attributes[c].expando===!1);e=null}();var ka=/^(?:input|select|textarea)$/i,la=/^key/,ma=/^(?:mouse|pointer|contextmenu|drag|drop)|click/,na=/^(?:focusinfocus|focusoutblur)$/,oa=/^([^.]*)(?:\.(.+)|)/;function pa(){return!0}function qa(){return!1}function ra(){try{return d.activeElement}catch(a){}}function sa(a,b,c,d,e,f){var g,h;if("object"==typeof b){"string"!=typeof c&&(d=d||c,c=void 0);for(h in b)sa(a,h,c,d,b[h],f);return a}if(null==d&&null==e?(e=c,d=c=void 0):null==e&&("string"==typeof c?(e=d,d=void 0):(e=d,d=c,c=void 0)),e===!1)e=qa;else if(!e)return a;return 1===f&&(g=e,e=function(a){return n().off(a),g.apply(this,arguments)},e.guid=g.guid||(g.guid=n.guid++)),a.each(function(){n.event.add(this,b,e,d,c)})}n.event={global:{},add:function(a,b,c,d,e){var f,g,h,i,j,k,l,m,o,p,q,r=n._data(a);if(r){c.handler&&(i=c,c=i.handler,e=i.selector),c.guid||(c.guid=n.guid++),(g=r.events)||(g=r.events={}),(k=r.handle)||(k=r.handle=function(a){return"undefined"==typeof n||a&&n.event.triggered===a.type?void 0:n.event.dispatch.apply(k.elem,arguments)},k.elem=a),b=(b||"").match(G)||[""],h=b.length;while(h--)f=oa.exec(b[h])||[],o=q=f[1],p=(f[2]||"").split(".").sort(),o&&(j=n.event.special[o]||{},o=(e?j.delegateType:j.bindType)||o,j=n.event.special[o]||{},l=n.extend({type:o,origType:q,data:d,handler:c,guid:c.guid,selector:e,needsContext:e&&n.expr.match.needsContext.test(e),namespace:p.join(".")},i),(m=g[o])||(m=g[o]=[],m.delegateCount=0,j.setup&&j.setup.call(a,d,p,k)!==!1||(a.addEventListener?a.addEventListener(o,k,!1):a.attachEvent&&a.attachEvent("on"+o,k))),j.add&&(j.add.call(a,l),l.handler.guid||(l.handler.guid=c.guid)),e?m.splice(m.delegateCount++,0,l):m.push(l),n.event.global[o]=!0);a=null}},remove:function(a,b,c,d,e){var f,g,h,i,j,k,l,m,o,p,q,r=n.hasData(a)&&n._data(a);if(r&&(k=r.events)){b=(b||"").match(G)||[""],j=b.length;while(j--)if(h=oa.exec(b[j])||[],o=q=h[1],p=(h[2]||"").split(".").sort(),o){l=n.event.special[o]||{},o=(d?l.delegateType:l.bindType)||o,m=k[o]||[],h=h[2]&&new RegExp("(^|\\.)"+p.join("\\.(?:.*\\.|)")+"(\\.|$)"),i=f=m.length;while(f--)g=m[f],!e&&q!==g.origType||c&&c.guid!==g.guid||h&&!h.test(g.namespace)||d&&d!==g.selector&&("**"!==d||!g.selector)||(m.splice(f,1),g.selector&&m.delegateCount--,l.remove&&l.remove.call(a,g));i&&!m.length&&(l.teardown&&l.teardown.call(a,p,r.handle)!==!1||n.removeEvent(a,o,r.handle),delete k[o])}else for(o in k)n.event.remove(a,o+b[j],c,d,!0);n.isEmptyObject(k)&&(delete r.handle,n._removeData(a,"events"))}},trigger:function(b,c,e,f){var g,h,i,j,l,m,o,p=[e||d],q=k.call(b,"type")?b.type:b,r=k.call(b,"namespace")?b.namespace.split("."):[];if(i=m=e=e||d,3!==e.nodeType&&8!==e.nodeType&&!na.test(q+n.event.triggered)&&(q.indexOf(".")>-1&&(r=q.split("."),q=r.shift(),r.sort()),h=q.indexOf(":")<0&&"on"+q,b=b[n.expando]?b:new n.Event(q,"object"==typeof b&&b),b.isTrigger=f?2:3,b.namespace=r.join("."),b.rnamespace=b.namespace?new RegExp("(^|\\.)"+r.join("\\.(?:.*\\.|)")+"(\\.|$)"):null,b.result=void 0,b.target||(b.target=e),c=null==c?[b]:n.makeArray(c,[b]),l=n.event.special[q]||{},f||!l.trigger||l.trigger.apply(e,c)!==!1)){if(!f&&!l.noBubble&&!n.isWindow(e)){for(j=l.delegateType||q,na.test(j+q)||(i=i.parentNode);i;i=i.parentNode)p.push(i),m=i;m===(e.ownerDocument||d)&&p.push(m.defaultView||m.parentWindow||a)}o=0;while((i=p[o++])&&!b.isPropagationStopped())b.type=o>1?j:l.bindType||q,g=(n._data(i,"events")||{})[b.type]&&n._data(i,"handle"),g&&g.apply(i,c),g=h&&i[h],g&&g.apply&&M(i)&&(b.result=g.apply(i,c),b.result===!1&&b.preventDefault());if(b.type=q,!f&&!b.isDefaultPrevented()&&(!l._default||l._default.apply(p.pop(),c)===!1)&&M(e)&&h&&e[q]&&!n.isWindow(e)){m=e[h],m&&(e[h]=null),n.event.triggered=q;try{e[q]()}catch(s){}n.event.triggered=void 0,m&&(e[h]=m)}return b.result}},dispatch:function(a){a=n.event.fix(a);var b,c,d,f,g,h=[],i=e.call(arguments),j=(n._data(this,"events")||{})[a.type]||[],k=n.event.special[a.type]||{};if(i[0]=a,a.delegateTarget=this,!k.preDispatch||k.preDispatch.call(this,a)!==!1){h=n.event.handlers.call(this,a,j),b=0;while((f=h[b++])&&!a.isPropagationStopped()){a.currentTarget=f.elem,c=0;while((g=f.handlers[c++])&&!a.isImmediatePropagationStopped())(!a.rnamespace||a.rnamespace.test(g.namespace))&&(a.handleObj=g,a.data=g.data,d=((n.event.special[g.origType]||{}).handle||g.handler).apply(f.elem,i),void 0!==d&&(a.result=d)===!1&&(a.preventDefault(),a.stopPropagation()))}return k.postDispatch&&k.postDispatch.call(this,a),a.result}},handlers:function(a,b){var c,d,e,f,g=[],h=b.delegateCount,i=a.target;if(h&&i.nodeType&&("click"!==a.type||isNaN(a.button)||a.button<1))for(;i!=this;i=i.parentNode||this)if(1===i.nodeType&&(i.disabled!==!0||"click"!==a.type)){for(d=[],c=0;h>c;c++)f=b[c],e=f.selector+" ",void 0===d[e]&&(d[e]=f.needsContext?n(e,this).index(i)>-1:n.find(e,this,null,[i]).length),d[e]&&d.push(f);d.length&&g.push({elem:i,handlers:d})}return h]","i"),va=/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:-]+)[^>]*)\/>/gi,wa=/");
tf.li.tagAdded = 1;
}
if (callback) tf.li.initCB.push(callback);
}
}
}
,isLinkedServer: function(cb) {
var user = getLoggedInUser();
return user && user.li_mt;
}
,isLinkedClient: function(cb) {
return tf.li.ovd.mt;
}
,parseDate: function(liDateObj) {
if (liDateObj && liDateObj.year) {
var date, precision = liDateObj.month?tf.dp.m:tf.dp.y;
if (liDateObj.month) {
date = new Date(liDateObj.year, liDateObj.month-1,1);
} else {
date = new Date(liDateObj.year, 1,1);
}
return {d: date.getTime(), p: precision};
} else{
return undefined;
}
}
,importProfile: function(successCB, errorCB) {
function callbackErrors() {
errorCB("Error getting profile from linkedin");
}
function doImportProfile(loginStatus) {
function callbackProfile(data,status) {
var stat = tf.status(data,status);
if (stat == "success") {
successCB(data, loginStatus);
} else {
errorCB("Error importing linkedin profile: " + stat);
}
}
$.ajax({
type: "POST",
url: getHost()+"/servlet/LinkedinJSONService/profile",
dataType: "json",
data: {ovd_linkedin_access_token:tf.li.ovd.at, ovd_linkedin_access_secret:tf.li.ovd.ats},
success:callbackProfile,
error: tf.ajaxError
});
}
var window_loggedInUser = properties.loggedInUser();
if (tf.li.isLinkedClient()) {
doImportProfile("anonymous");
} else if (tf.li.isLinkedServer()) {
doImportProfile("success");
} else {
tf.li.login(function(data, status) {
if (status == "anonymous" || status == "login" || status == "newaccount" || status == "success") {
doImportProfile(status);
} else {
errorCB("Error: unexpected status: " + status);
}
});
}
} // end of tf.li.importProfile
,unlink: function(cb) {
// callback should take (success, errormsg) as arguments
$.ajax({
type: "POST",
url: getHost()+"/servlet/LinkedinJSONService/unlink",
dataType: "json",
success: function(data, status) {
var status = tf.status(data, status),
window_loggedInUser = properties.loggedInUser();
if (status == "success" || status == "error_cant_change_li") {
if(window_loggedInUser) {
window_loggedInUser.li_mt = undefined;
window_loggedInUser.li_comments = undefined;
}
announceClear();
if (cb) cb(1);
} else {
if (cb) cb(0,"An error occurred while contacting the server (" + status + "). Please try again later.");
}
},
error: tf.ajaxError
});
}
,permLink: function(comments, models, callback) {
// callback should expect data, status (on err, can put message in data.msg)
var window_loggedInUser = properties.loggedInUser();
function doServerSave(data, loginStatus) {
function successHandler(data, status) {
var stat = tf.status(data,status);
if (stat == "success") {
if(window_loggedInUser) {
window_loggedInUser.li_mt = data.mt;
if (comments === 1 || comments === 0)
window_loggedInUser.li_comments = comments;
}
if (callback)callback({},loginStatus);
} else {
if (callback)callback({msg:"Error linking Linkedin account: "+stat}, stat);
}
}
$.ajax({
type: "POST",
url: getHost()+"/servlet/LinkedinJSONService/link",
dataType: "json",
data: data,
success: successHandler,
error: function(){if (callback)callback({}, "error_unknown")}
});
}
var linkData = {};
if(comments === 1 || comments === 0)
linkData.c = comments;
if(models === 1 || models === 0)
linkData.m = models;
if (tf.li.isLinkedClient()) {
if (window_loggedInUser) {
// we new have a logged in user, so associate with the account.
$.extend(linkData, tf.li.ovd);
doServerSave(linkData, "newaccount");
} else {
// no user, skip the save.
if (callback) callback({}, "anonymous");
}
} else if (tf.li.isLinkedServer()) {
doServerSave(linkData, "success");
} else {
tf.li.login(function(data,status) {
// - anonymous: the user is still anonymous, but we have obtained an access token in data.mt, data.at and data.ats
// - login: the user is now logged in, but was not previously. data.loggedInUser will hold the serialized logged in user.
// - newaccount: the user has not changed, but is now associated with a new linkedin user. data.mt holds the new member token.
// - success: the user has not changed, and is linked to the same linkedin user as before.
if (status == "login" || status == 'success' || status == 'newaccount') {
doServerSave(linkData, status)
} else if (status =="anonymous") {
tf.li.setOvd(data.member_token, data.token, data.secret);
// skip the server save, since there's no logged in user
if (callback) callback({}, status);
} else {
if (callback) callback({msg:"An error occurred while contacting the server, status " + status}, status);
}
});
}
}
,popupWin:null
,open:function(url, callback) {
if (tf.li.popupWin) tf.li.popupWin.close();
tf.li.popupWin = open(url, "linkedin","resizable=1,width=830,height=500,scrollbars=1");
tf.li.popupWin.focus();
$("#linkedinSignal").one("click",function () {
var c = $("#linkedinData"),
v = c.val(),
d = tf.JSONparse(v),
sc = $("#linkedinStatus"),
st = sc.val();
tf.li.popupWin.close();
if (st == "anonymous")
tf.li.setOvd(d.mt, d.at,d.ats);
else if (st == "login" || st == "newaccount" || st == "success")
tf.li.clearOvd();
if (st == "login") {
window.loggedInUser = d.loggedInUser;
// attempt to add facebook link if we're linked on the client.
tf.fb.isLinked(function(){
tf.fb.permLinkServer(null,null,null);
});
}
if (st == "newaccount")
window.loggedInUser.li_mt = d.mt;
if (callback)
callback(d,st);
});
}
,login: function(callback) {
// callback should expect (data, status) as arguments, and should NOT need to call tf.status.
// statuses include:
// - anonymous: the user is still anonymous, but we have obtained an access token in data.mt, data.at and data.ats
// - login: the user is now logged in, but was not previously. data.loggedInUser will hold the serialized logged in user.
// - newaccount: the user has not changed, but is now associated with a new linkedin user. data.mt holds the new member token.
// - success: the user has not changed, and is linked to the same linkedin user as before.
// - user_refused: the user refused to link
// - error_: various error conditions
//
// does a server rpc to check if the current user has a non-null linkedin access token. If the user does not,
// it pops up a dialog prompting the user to log in.
// Note: the access token is NOT saved in the database by this call! If you want that, try the tf.li.permLink function.
var sync = $.browser.webkit, needopen = 0;
$.ajax({
type:"POST",
async: !sync,
url: getHost()+"/servlet/LinkedinJSONService/haslink",
success:function(data,status) {
var stat = tf.status(data,status);
if (stat == "needauth") {
needopen = data.url;
// delay window opening on sync calls until stack is shallower.
if (!sync)
tf.li.open(needopen, callback);
} else {
if (stat != "success")
announce("Error, got status: " + stat, 1);
callback(data, stat);
}
},
error: tf.ajaxError
});
if (sync && needopen)
tf.li.open(needopen, callback);
}
});
// this is actually a callback that is called by the linkedin initialization, we just call name it the same as the facebook asynch init.
window.liAsyncInit = function() {
tf.li.inited = 1;
// call all the callbacks.
$.each(tf.li.initCB, function(i,x) {
x();
});
};
;;
// lib/jquery.min.js
// @include common.js
// @include tf/li.js
// @include tf/status.js
// @include properties.js
tf = window.tf || {};
tf.fb = $.extend(tf.fb || {}, {
inited: 0
,tagAdded: 0
,initCB: [] // these callbacks are only called in window.fbAsyncInit
,init: function(callback) {
if (tf.fb.inited) {
if (callback) callback();
} else {
// TREF-5336: run social network scripts only on prod domain, not on private environments
if(getHost().indexOf('www.trefis.com') > 0) {
if (!tf.fb.tagAdded) { // only add script tag if we haven't already added it.
$('body').append("");
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
tf.fb.tagAdded = 1;
}
if (callback) tf.fb.initCB.push(callback);
}
}
}
,getSession: function(cb) {
tf.fb.init(function() {
FB.getLoginStatus(function(response) {
cb(response?response.session:response);
});
});
}
,isLinked: function(cb) {
tf.fb.getSession(function(session){
cb(!!session);
});
}
,linkClient: function(callback) {
// callback should take (data, status) as arguments. It should NOT call tf.status, as data.status is never set.
// status can be
// "error_fb_init" , facebook was not initialized
// "error_fb_perm", user didn't grant permissions
// "success", client was linked.
// in both error conditions, data.msg will be set to an appropriate user message.
var permerr = "In order to link to your Facebook account, you must grant Trefis extended permissions",
initerr = "Error: facebook not initialized, please try again.";
if (tf.fb.inited) {
FB.login(function(response) {
if (response && response.session) {
callback({},"success");
} else {
callback({msg:permerr}, "error_fb_perm");
}
}, {perms:'publish_stream,offline_access,user_education_history,user_work_history,email,user_website,user_interests'});
} else {
// we can't call FB.login in chrome from a callback, because it will
tf.fb.init(function(){callback({msg:initerr}, "error_fb_init")});
}
}
,permLink: function(comments, models, callback) {
tf.fb.linkClient(function(data, status) {
if (status == "success")
tf.fb.permLinkServer(comments, models, callback);
else
if (callback) callback(data, status);
});
}
,permLinkServer: function(comments, models, callback) {
var servererr= "An error occurred while contacting the server. Please try again later.";
// callback should take (data, status) as arguments. It should NOT call tf.status, as data.status is never set.
// - anonymous: the user is still anonymous, but data.uid holds the new facebook userid.
// - login: the user is now logged in, but was not previously. data.loggedInUser will hold the serialized logged in user.
// - newaccount: the user has not changed, but is now associated with a new facebook account. data.uid holds the new facebook userid.
// - success: the user has not changed, and is linked to the same facebook account as before.
// - error_fb_init, facebook was not initialized, data.msg holds user visible message
// - error_fb_perm, user didn't grant permissions, data.msg holds suggested user visible message
// - error_unknown, other error
function successHandler(data, status) {
var st = tf.status(data, status);
if(st == "anonymous" || st == "login" || st == "newaccount" || st == "success") {
if (st == "login") {
window.loggedInUser = data.loggedInUser;
// attempt to add linkedin link if we're linked on the client.
if (tf.li.isLinkedClient())
tf.li.permLink(null,null,null);
}
if (st == "newaccount")
window.loggedInUser.fb_uid = data.uid;
var window_loggedInUser = properties.loggedInUser();
if(window_loggedInUser) {
if (comments === 1 || comments === 0)
window_loggedInUser.fb_comments = comments;
}
if (callback)
callback(data,st);
} else {
if (callback)
callback({}, status);
}
}
function doServerSave() {
var data = {};
if(comments === 1 || comments === 0)
data.c = comments;
if(models === 1 || models === 0)
data.m = models;
$.ajax({
type: "POST",
url: getHost()+"/servlet/FBService/link",
dataType: "json",
data: data,
success: successHandler,
error: function(){if (callback) callback({}, "error_unknown")}
});
}
doServerSave();
}
,unlinkClient: function(cb) {
FB.logout(function(response){
cb(1);
});
}
,unlink: function(cb) {
// callback should take (success, errormsg) as arguments
$.ajax({
type: "POST",
url: getHost()+"/servlet/FBService/unlink",
dataType: "json",
success: function(data, status) {
var status = tf.status(data, status),
window_loggedInUser = properties.loggedInUser();
if(status == "success") {
if(window_loggedInUser) {
window_loggedInUser.fb_uid = undefined;
window_loggedInUser.fb_comments = undefined;
}
tf.fb.init(function(){FB.logout();});
announceClear();
if (cb) cb(1);
} else if (status == "error_cant_change_fb") {
// the Trefis app may still appear on their facebook account, but we don't have access any longer.
if (cb) cb(1);
} else {
if (cb) cb(0,"An error occurred while contacting the server (" + status + "). Please try again later.");
}
},
error: tf.ajaxError
});
}
,parseDate: function(fbDateString) {
var date, precision = tf.dp.m;
switch(fbDateString.length) {
// empty string
case 0:
return null;
// MM
case 1:
case 2:
date = new Date(2010, parseInt(fbDateString)-1, 1);
break;
// YYYY
case 4:
date = new Date(fbDateString, 1, 1);
precision = tf.dp.y;
break;
// YYYY-MM
case 6:
case 7:
date = new Date(fbDateString.substr(0,4), parseInt(fbDateString.substr(5))-1, 1);
break;
default:
// TODO: some kind of error message?
return null;
}
return {d: date.getTime(), p: precision};
}
,importProfileDirect:function(dointerests,doProfileImport, cberr) {
FB.api('/me', function(response) {
if (!response) {
cberr();
} else if (response.error) {
announce("Error " + response.error.type +": " + response.error.message, 1);
cberr();
} else {
var work = [],
education = [],
urls = [],
interests = [],
tempStart,
tempEnd,
email = response.email
,firstName = response.first_name
,lastName = response.last_name
;
if(email && email.match(/@proxymail\.facebook\.com$/i))
email = undefined;
if (response.link) urls.push({u:response.link});
if (response.website) urls.push({u:response.website});
if (response.education) {
$.each(response.education, function(index, item) {
if(education.length)
education.push('\n');
if(item.degree)
education.push(item.degree.name);
if(item.school) {
if(item.degree)
education.push(', ');
education.push(item.school.name);
}
if(item.year)
education.push(' ' + item.year.name);
});
}
if (response.work) {
$.each(response.work, function(index, item) {
if(work.length)
work.push('\n');
if(item.position)
work.push(item.position.name);
if(item.employer) {
if(item.position)
work.push(', ');
work.push(item.employer.name);
}
if(item.start_date || item.end_date) {
work.push(' ');
if(item.start_date)
work.push(item.start_date);
work.push(' -- ');
if(item.end_date)
work.push(item.end_date);
}
});
}
if (dointerests) {
FB.api('/me/interests', function(response) {
if (!response) {
cberr();
} else if (response.error) {
announce("Error " + response.error.type +": " + response.error.message, 1);
cberr();
} else {
if(response.data) {
$.each(response.data, function(i,x) {
interests.push(x.name);
});
}
doProfileImport({
experience: work.join(''),
education: education.join(''),
interests:interests.length>0?interests.join(", "):"",
urls: urls,
email: email,
first: firstName,
last: lastName
});
}
});
} else {
doProfileImport({
experience: work.join(''),
education: education.join(''),
interests:"",
urls: urls,
email: email,
first: firstName,
last: lastName});
}
}
});
}
,importProfile: function(comments, models, dointerests,doProfileImport, cberr) {
tf.fb.isLinked(function(linked){
if (linked) {
tf.fb.importProfileDirect(0, doProfileImport);
} else {
tf.fb.permLink(comments, models, function(data, status) {
if (status == "success" || status == "login" || status == "newaccount" || status == "anonymous") {
tf.fb.importProfileDirect(dointerests,doProfileImport, cberr);
} else {
announce(data.msg || "Unexpected status: " + status, 1);
cberr();
}
});
}
});
}
,post:function(postObj, cb) {
// this method will fail if there is not already a facebook link set up
// postObj can have the following: message, picture, link, name, caption, description, source
// cb should expect success, message, postid
if (tf.fb.inited) {
FB.api('/me/feed', 'post', function(response) {
if (cb) {
if (!response) {
cb(0, 0);// this happens when the user skips
} else if (response.error) {
cb(0,"Error " + error.type +": " + error.message);
} else {
cb(1,0, response.id);
}
}
});
} else {
// we can't call FB.login in chrome from a callback, because it will
tf.fb.init(function(){cb(0, "Error: facebook not initialized, please try again.")});
}
}
,publish:function(message, linktext, href, cb) {
// this method will prompt user if they are not already linked, then show an editable dialog.
if (tf.fb.inited) {
FB.ui({method:'stream.publish',
message: message,
action_links: [{text:linktext, href:href}]
}, function(response) {
if (!response) {
cb(0, 0);// this happens when the user skips
} else if (response.error) {
cb(0, "Error " + error.type +": " + error.message);
} else {
cb(1, 0, response.post_id);
}
});
} else {
// we can't call FB.login in chrome from a callback, because it will
tf.fb.init(function(){cb(0, "Error: facebook not initialized, please try again.")});
}
}
});
window.fbAsyncInit = function() {
FB.init({
appId : properties.fb_key(),
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
tf.fb.inited = 1;
// call all the callbacks.
$.each(tf.fb.initCB, function(i,x) {
x();
});
};
;;
// lib/jquery.min.js
// @include lib/underscore.js
/*
New-style slideshow, based on designs by Clinton.
This manages a slides show with indicators for each slide. For example,
if there are four slides, there should be four indicators that are
always visible. When the second slide is being shown, the second
indicator is visually flagged as active. A user can click on, for
example, the third indicator to show the third slide instead.
The implementation allows multiple sections that change in sync from
slide to slide and interspersing them with sections that stay the same
on all slides.
Example HTML that works with slideshowFancy.css and defaults:
* MIT license
*
* Includes enhancements by Scott Trenda
* and Kris Kowal
*
* Accepts a date, a mask, or a date and a mask.
* Returns a formatted version of the given date.
* The date defaults to the current date/time.
* The mask defaults to dateFormat.masks.default.
*/
(function(global) {
'use strict';
var dateFormat = (function() {
var token = /d{1,4}|m{1,4}|yy(?:yy)?|([HhMsTt])\1?|[LloSZWN]|'[^']*'|'[^']*'/g;
var timezone = /\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g;
var timezoneClip = /[^-+\dA-Z]/g;
// Regexes and supporting functions are cached through closure
return function (date, mask, utc, gmt) {
// You can't provide utc if you skip other args (use the 'UTC:' mask prefix)
if (arguments.length === 1 && kindOf(date) === 'string' && !/\d/.test(date)) {
mask = date;
date = undefined;
}
date = date || new Date;
if(!(date instanceof Date)) {
date = new Date(date);
}
if (isNaN(date)) {
throw TypeError('Invalid date');
}
mask = String(dateFormat.masks[mask] || mask || dateFormat.masks['default']);
// Allow setting the utc/gmt argument via the mask
var maskSlice = mask.slice(0, 4);
if (maskSlice === 'UTC:' || maskSlice === 'GMT:') {
mask = mask.slice(4);
utc = true;
if (maskSlice === 'GMT:') {
gmt = true;
}
}
var _ = utc ? 'getUTC' : 'get';
var d = date[_ + 'Date']();
var D = date[_ + 'Day']();
var m = date[_ + 'Month']();
var y = date[_ + 'FullYear']();
var H = date[_ + 'Hours']();
var M = date[_ + 'Minutes']();
var s = date[_ + 'Seconds']();
var L = date[_ + 'Milliseconds']();
var o = utc ? 0 : date.getTimezoneOffset();
var W = getWeek(date);
var N = getDayOfWeek(date);
var flags = {
d: d,
dd: pad(d),
ddd: dateFormat.i18n.dayNames[D],
dddd: dateFormat.i18n.dayNames[D + 7],
m: m + 1,
mm: pad(m + 1),
mmm: dateFormat.i18n.monthNames[m],
mmmm: dateFormat.i18n.monthNames[m + 12],
yy: String(y).slice(2),
yyyy: y,
h: H % 12 || 12,
hh: pad(H % 12 || 12),
H: H,
HH: pad(H),
M: M,
MM: pad(M),
s: s,
ss: pad(s),
l: pad(L, 3),
L: pad(Math.round(L / 10)),
t: H < 12 ? 'a' : 'p',
tt: H < 12 ? 'am' : 'pm',
T: H < 12 ? 'A' : 'P',
TT: H < 12 ? 'AM' : 'PM',
Z: gmt ? 'GMT' : utc ? 'UTC' : (String(date).match(timezone) || ['']).pop().replace(timezoneClip, ''),
o: (o > 0 ? '-' : '+') + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4),
S: ['th', 'st', 'nd', 'rd'][d % 10 > 3 ? 0 : (d % 100 - d % 10 != 10) * d % 10],
W: W,
N: N
};
return mask.replace(token, function (match) {
if (match in flags) {
return flags[match];
}
return match.slice(1, match.length - 1);
});
};
})();
dateFormat.masks = {
'default': 'ddd mmm dd yyyy HH:MM:ss',
'shortDate': 'm/d/yy',
'mediumDate': 'mmm d, yyyy',
'longDate': 'mmmm d, yyyy',
'fullDate': 'dddd, mmmm d, yyyy',
'shortTime': 'h:MM TT',
'mediumTime': 'h:MM:ss TT',
'longTime': 'h:MM:ss TT Z',
'isoDate': 'yyyy-mm-dd',
'isoTime': 'HH:MM:ss',
'isoDateTime': 'yyyy-mm-dd\'T\'HH:MM:sso',
'isoUtcDateTime': 'UTC:yyyy-mm-dd\'T\'HH:MM:ss\'Z\'',
'expiresHeaderFormat': 'ddd, dd mmm yyyy HH:MM:ss Z'
};
// Internationalization strings
dateFormat.i18n = {
dayNames: [
'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat',
'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'
],
monthNames: [
'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec',
'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'
]
};
function pad(val, len) {
val = String(val);
len = len || 2;
while (val.length < len) {
val = '0' + val;
}
return val;
}
/**
* Get the ISO 8601 week number
* Based on comments from
* http://techblog.procurios.nl/k/n618/news/view/33796/14863/Calculate-ISO-8601-week-and-year-in-javascript.html
*
* @param {Object} `date`
* @return {Number}
*/
function getWeek(date) {
// Remove time components of date
var targetThursday = new Date(date.getFullYear(), date.getMonth(), date.getDate());
// Change date to Thursday same week
targetThursday.setDate(targetThursday.getDate() - ((targetThursday.getDay() + 6) % 7) + 3);
// Take January 4th as it is always in week 1 (see ISO 8601)
var firstThursday = new Date(targetThursday.getFullYear(), 0, 4);
// Change date to Thursday same week
firstThursday.setDate(firstThursday.getDate() - ((firstThursday.getDay() + 6) % 7) + 3);
// Check if daylight-saving-time-switch occured and correct for it
var ds = targetThursday.getTimezoneOffset() - firstThursday.getTimezoneOffset();
targetThursday.setHours(targetThursday.getHours() - ds);
// Number of weeks between target Thursday and first Thursday
var weekDiff = (targetThursday - firstThursday) / (86400000*7);
return 1 + Math.floor(weekDiff);
}
/**
* Get ISO-8601 numeric representation of the day of the week
* 1 (for Monday) through 7 (for Sunday)
*
* @param {Object} `date`
* @return {Number}
*/
function getDayOfWeek(date) {
var dow = date.getDay();
if(dow === 0) {
dow = 7;
}
return dow;
}
/**
* kind-of shortcut
* @param {*} val
* @return {String}
*/
function kindOf(val) {
if (val === null) {
return 'null';
}
if (val === undefined) {
return 'undefined';
}
if (typeof val !== 'object') {
return typeof val;
}
if (Array.isArray(val)) {
return 'array';
}
return {}.toString.call(val)
.slice(8, -1).toLowerCase();
};
if (typeof define === 'function' && define.amd) {
define(function () {
return dateFormat;
});
} else if (typeof exports === 'object') {
module.exports = dateFormat;
} else {
global.dateFormat = dateFormat;
}
})(this);
;;
// @include lib/dateformat.js
/**
* tfDate:
* wrapper around dateformat for both browser and node/module system
* keeps a default (only 1 right now)
* can be applied directly to DOM elements:
* 27 Oct 2016 2:54
* Oct/2016
*
* By default, a tag with these data attributes will render automatically. However, in some cases,
* we may want to render manually -
* see https://github.com/felixge/node-dateformat
*/
(function(global) {
var defaultFormat = 'd mmm yyyy h:MM TT';
// i believe we are moving away from the tf.date syntax, but labeling as such to keep clear
// that this is not a Date, and is a wrapper around dateformat.
var tfDate = {
/**
* get a formatted date
* @param timestamp
* @param formatString - see dateformat
* @returns {*} a dateFormatted string
*/
'format': function (timestamp, formatString, UTC) {
var string = formatString ? formatString : defaultFormat;
string = UTC ? 'UTC:'+ string : string;
return dateFormat(parseInt(timestamp), string);
},
/**
* useful if we want to display a formatted date in a datepicker.
* @returns {string}
*/
'getDefault': function () {
return defaultFormat;
},
/**
* set the default string for a module
* @param formatString
*/
'setDefault': function(formatString){
defaultFormat = formatString
},
'renderAll': function(){
var elements = document.querySelectorAll("[data-timestamp]");
for (var i = 0; i < elements.length; i++) {
tfDate.render(elements[i]);
}
},
'render': function(el){
var timestamp = el.getAttribute("data-timestamp");
var formatString = el.getAttribute("data-formatString");
var UTC = el.getAttribute("data-utc");
// this will get set to false when the autorender for other elements hits it
// this way the update can happen when manually called.
if (el.getAttribute("data-manualRender") === "true"){
el.setAttribute("data-manualRender", false);
return;
} else {
el.innerHTML = tfDate.format(timestamp,formatString,UTC);
}
}
};
// wire them up for convenience on load.
document.addEventListener('DOMContentLoaded', function(){
tfDate.renderAll();
}, false);
// return for environment.
if (typeof exports === 'object') {
module.exports = tfDate;
} else {
global.tfDate = tfDate;
}
}(this))
;;
// lib/jquery.min.js
// @include lib/underscore.js
// @include lib/jquery.ui.min.js
// @include lib/timer.js
// @include lib/jquery.jqote2.min.js
// @include lib/jquery.browser.js
// @include lib/json2.js
// @include lib/DD_belatedPNG_0.0.8a-min.js
// @include tf/mailRE.js
// @include tf/ga.js
// @include tf/luckyOrangeTag.js
// @include tf/status.js
// @include loginPopup.js
// @include feedback.js
// @include components/ghostText.js
// @include tf/loginIframe.js
// @include tf/fb.js
// @include showOverlay.js
// @include tf/initPopup.js
// @include page/subscribeEmailSiteLicense.js
// @include tf/isDebug.js
// @include properties.js
// @include infrastructure/date.js
// @inlcude widgetCommon/clearInput.js
// global trefis object
tf = window.tf || {};
$.extend(tf, {
ajax:function(args, useOvd) {
args.error = args.error || tf.ajaxError;
args.data = args.data || {};
args.data.widgetType = window.widgetType;
if (useOvd && window.loggedInUser && loggedInUser.userId) {
args.data.ovd_uid = loggedInUser.userId;
args.data.ovd_uchk = loggedInUser.userCheck;
}
$.ajax(args);
}
// cross platform location.hash, see http://stackoverflow.com/questions/1703552/encoding-of-window-location-hash/1704557
,getHash:function(){
var href = location.href,
pos = href.indexOf("#");
return pos<0?"":href.substr(pos);
}
,entityDecode:function(x){return $("").html(x).text()}
,getSecureHost:function(){return "https"+getHost().substring(getHost().indexOf(":"))}
,getHttpHost:function(){return "http"+getHost().substring(getHost().indexOf(":"))}
,pathAfterContext:function(){ return window.location.href.substr(getHost().length)}
,isSecure:function() {
return location.protocol == "https:";
}
,log:function(data, container) {
if (!tf.isDebug()) {
return;
}
if (window.console && console.log) {
console.log(data);
}
if (container) {
if (typeof data !== "string") {
data = JSON.stringify(data);
}
$(container).append($('').text(data));
}
}
// returns 1 if a popup was shown, undefined if silent
,ajaxError:function(xmlHttpRequest, textStatus, errorThrown) {
if (tf.isDebug()) {
alert("error: " + textStatus + "\n" + errorThrown + "\nresponseText: " + xmlHttpRequest.responseText);
return 1;
}
}
,error: function(errMsg, useFlash) {
try {
if (useFlash) {
var errFlash = $(_.template($('#error-flash-template').html())({ message: errMsg }))
$('#flash-errors').append(errFlash)
$(window).scrollTop(0)
errFlash.fadeIn(1000)
}
else {
var errModal = $(_.template($('#bootstrap-modal-template').html())({
title: 'Error',
body: '
'+ (errMsg || "We're sorry, an unexpected error occurred") +'
'
}))
errModal.find('.modal-header').prepend($('', { 'class': 'fa fa-cogs fa-1-5x text-muted pull-left' }))
errModal.modal({})
}
} catch (e) {
// if modal or flash notification doesn't work, use an alert
alert(errMsg)
}
}
,track:function(token) {
if (token) {
$.ajax({
type: "POST",
url: getHost()+"/servlet/TrackService/track",
data: {token: token},
dataType: "json"
});
} else {
tf.isDebug() && alert("undefined token");
}
}
,checkEmail:function(email, takenMsg) {
if(email.length > 0) {
function successHandler(data, status) {
var statusCode = tf.status(data, status);
// if(statusCode == "errornotinvited")
//announce("Sorry, that email address is not on the beta invite list. Please email help@trefis.com if you think there is a mistake or want an invite.", true);
// else
if(statusCode == "errorduplicateemail")
announce(takenMsg, 1);
else if(statusCode == "errorinvalid")
announce("Sorry, that doesn't look like a valid email address -- check for typos, and try re-entering it", 1);
}
$.ajax({
type: "POST",
url: getHost()+"/servlet/HtmlService/checkEmail",
data: {e: email},
dataType: "json",
success: successHandler,
error: successHandler
});
}
}
,parseModelId:function(modelId) {
if (!modelId) return null;
var parts = modelId.split('.');
if(parts.length != 2) return null;
if ("trefis" == parts[1]) {
return {symbol:parts[0],isTrefis:true};
} else {
return {symbol:parts[0],userId:parseInt(parts[1],10)};
}
}
// expects {symbol, userId, isTrefis}
,serializeModelId:function(modelIdObj) {
return modelIdObj.symbol +"."+(modelIdObj.isTrefis?"trefis":modelIdObj.userId);
}
,parseBuyCode:function(buyCode) {
if (!buyCode || buyCode.length < 8) return null;
var parts = buyCode.split('.'),
type = parts[0].substr(7),
nParts = parts.length;
//type enum: PRIVACY, SECTOR, OTHER
if (type == 1) {
return {type:'sector', sectorId:parts[1], symbol:(nParts>2?parts[2]:null)};
} else {
return {type:(type==0?'privacy':'other'), symbol:(nParts>1?parts[1]:null)};
}
}
// expects {type, sectorId, symbol}
,serializeBuyCode:function(buyCodeObj) {
var baseChunk =buyCodeObj.type=='sector'
?'1.'+buyCodeObj.sectorId
:buyCodeObj.type=='privacy'?'0':'2',
symbolChunk = buyCodeObj.symbol?'.'+buyCodeObj.symbol:'';
return 'buycode'+baseChunk+symbolChunk;
}
// date precisions (for editProfile.js and related)
// these should match the values in com.insightguru.giraffe.server.domain.ProfileDatePrecision
,dp: {y: 0, m: 1}
,profImport_getCurrentData: function(rowJquery, dataClass) {
return getTextFromGhosted(rowJquery.find("." + dataClass)[0].id);
}
,mergeUrls: function(component, inputInfo, tableLoad, allurls) {
// delete any existing URLs which match newly imported URLs
var urls = [];
$.each(allurls, function(j, importedObject) {
var hasMatch;
$("#" + component + " ." + inputInfo.url.p + "s tbody tr").each(function(i, currentRow) {
if(importedObject.u == tf.profImport_getCurrentData($(currentRow), "u")) {
hasMatch = 1;
return false;
}
});
if (!hasMatch)
urls.push(importedObject);
});
// add in all newly imported URLs
tableLoad(component, inputInfo.url, urls);
}
,getNonNullUser: function() {
return properties.loggedInUser() || {};
}
,setButtonText: function(obj, text) {
if(obj.is('.gbutton'))
obj.find('span').text(text);
else if(obj.is('.gbutton2') || obj.is('.smallGreyButton'))
obj.text(text).prepend('');
else
obj.text(text);
}
,initDraggable: function(popupQueryObject, handleQueryObject) {
var dragOffsetX, dragOffsetY,
mouseUpListener = function() {
$(document)
.unbind("mousemove", mouseMoveListener)
.unbind("mouseup", mouseUpListener);
},
mouseMoveListener = function(e) {
popupQueryObject
.css("left", e.pageX - dragOffsetX + "px")
.css("top", e.pageY - dragOffsetY + "px");
};
handleQueryObject.mousedown(function(e) {
var node = e.target,
topString,
leftString;
while(node != null && node != e.currentTarget) {
if(node.tagName == "A") {
return;
}
node = node.parentNode;
}
topString = popupQueryObject.css("top");
leftString = popupQueryObject.css("left");
dragOffsetX = e.pageX - leftString.substr(0, leftString.length - 2); // remove the trailing 'px'
dragOffsetY = e.pageY - topString.substr(0, topString.length - 2);
$(document)
.mousemove(mouseMoveListener)
.mouseup(mouseUpListener);
return false;
});
}
,post: function(url, params) {
// will build a form and submit it to cause a page navigation.
var form = $("")
.appendTo("body")
.submit();
}
,doLoginRedirect:function(options) {
if (!options.isNewUser && !options.href) {
location.reload(true);
} else {
var toURL = options.href?options.href:
getHost() + (options.isNewUser?"/subscribe/services":"/");
if (options.isLoggedIn && !options.isNewUser) {
var toParam = tf.getParameterByName('to');
if(toParam) {
toURL = getHost() + toParam + tf.getHash();
}
}
if (toURL.url) {
tf.post(toURL.url, toURL.p);
} else {
location.href = toURL;
}
}
}
,scrollY: function() {
return $(window).scrollTop();
}
,gbuttonAddEvents: function(jqObj) {
function gbuttonUpListener() {
$(this).removeClass("gbutton-down");
};
jqObj.mouseover(function(){
$(this).addClass("gbutton-moused")
})
.mouseout(function(){
$(this).removeClass("gbutton-moused")
})
.mousedown(function(){
$(this).addClass("gbutton-down")
})
.mouseout(gbuttonUpListener)
.mouseup(gbuttonUpListener);
}
,gbutton2AddEvents: function(jqObj) {
function gbutton2UpListener() {
$(this).removeClass("gbutton2-down");
};
jqObj.mouseover(function(){
$(this).addClass("gbutton2-moused")
})
.mouseout(function(){
$(this).removeClass("gbutton2-moused")
})
.mousedown(function(){
$(this).addClass("gbutton2-down")
})
.mouseout(gbutton2UpListener)
.mouseup(gbutton2UpListener);
}
// this is intended to be used in a double-quoted href attribute
,safeLink: function(unsafe) {
var fullURL = (unsafe.indexOf("https://") != 0 && unsafe.indexOf("http://") != 0)?"http://"+unsafe:unsafe;
return fullURL.replace('"','%22');
}
,getLockDiv:function(islocked, alttext) {
return "" +
""+
""
;
}
,getLockSpan:function(islocked, alttext) {
return "";
}
,getSubscribeSmallSpan:function(alttext) {
return "";
}
// sets up a company search autocomplete on the textbox with the given id
,autocomplete: function(textBoxId, resultCallback) {
return tf.autocompleteObj($("#" + textBoxId),resultCallback);
}
,autocompleteHighlight: function(string, term) {
return string
? string.replace(
new RegExp(
"(?![^&;]+;)(?!<[^<>]*)(" +
$.ui.autocomplete.escapeRegex(term) +
")(?![^<>]*>)(?![^&;]+;)", "gi"),
"$1")
: '';
}
,autocompleteObj: function(textBoxObj, resultCallback) {
textBoxObj
.autocomplete({
source: function(request, response) {
$.getJSON(
getHost()+'/autocomplete/company',
request,
function(data) {
if(data && data.data) {
$.each(data.data, function(i, item) {
item.displaySymbol = tf.autocompleteHighlight(item.symbol, request.term);
item.displayName = tf.autocompleteHighlight(item.name, request.term);
});
response(data.data);
} else {
response([]);
}
});
},
delay: 100,
autoFocus: true,
select: function(event, ui) {
resultCallback(ui.item);
},
open: function( event, ui ) {
$( this ).autocomplete( 'widget' )
.css({zIndex: 9})
.find( 'ac_odd' )
.removeClass( 'ac_odd' )
.end()
.find( 'li.ui-menu-item:odd' )
.addClass( 'ac_odd' );
}
})
.data('ui-autocomplete')._renderItem = function(ul, item) {
return $('
;
* }
* });
*
* The class specification supports a specific protocol of methods that have
* special meaning (e.g. `render`). See `ReactClassInterface` for
* more the comprehensive protocol. Any other properties and methods in the
* class specification will be available on the prototype.
*
* @interface ReactClassInterface
* @internal
*/
var ReactClassInterface = {
/**
* An array of Mixin objects to include when defining your component.
*
* @type {array}
* @optional
*/
mixins: 'DEFINE_MANY',
/**
* An object containing properties and methods that should be defined on
* the component's constructor instead of its prototype (static methods).
*
* @type {object}
* @optional
*/
statics: 'DEFINE_MANY',
/**
* Definition of prop types for this component.
*
* @type {object}
* @optional
*/
propTypes: 'DEFINE_MANY',
/**
* Definition of context types for this component.
*
* @type {object}
* @optional
*/
contextTypes: 'DEFINE_MANY',
/**
* Definition of context types this component sets for its children.
*
* @type {object}
* @optional
*/
childContextTypes: 'DEFINE_MANY',
// ==== Definition methods ====
/**
* Invoked when the component is mounted. Values in the mapping will be set on
* `this.props` if that prop is not specified (i.e. using an `in` check).
*
* This method is invoked before `getInitialState` and therefore cannot rely
* on `this.state` or use `this.setState`.
*
* @return {object}
* @optional
*/
getDefaultProps: 'DEFINE_MANY_MERGED',
/**
* Invoked once before the component is mounted. The return value will be used
* as the initial value of `this.state`.
*
* getInitialState: function() {
* return {
* isOn: false,
* fooBaz: new BazFoo()
* }
* }
*
* @return {object}
* @optional
*/
getInitialState: 'DEFINE_MANY_MERGED',
/**
* @return {object}
* @optional
*/
getChildContext: 'DEFINE_MANY_MERGED',
/**
* Uses props from `this.props` and state from `this.state` to render the
* structure of the component.
*
* No guarantees are made about when or how often this method is invoked, so
* it must not have side effects.
*
* render: function() {
* var name = this.props.name;
* return
Hello, {name}!
;
* }
*
* @return {ReactComponent}
* @required
*/
render: 'DEFINE_ONCE',
// ==== Delegate methods ====
/**
* Invoked when the component is initially created and about to be mounted.
* This may have side effects, but any external subscriptions or data created
* by this method must be cleaned up in `componentWillUnmount`.
*
* @optional
*/
componentWillMount: 'DEFINE_MANY',
/**
* Invoked when the component has been mounted and has a DOM representation.
* However, there is no guarantee that the DOM node is in the document.
*
* Use this as an opportunity to operate on the DOM when the component has
* been mounted (initialized and rendered) for the first time.
*
* @param {DOMElement} rootNode DOM element representing the component.
* @optional
*/
componentDidMount: 'DEFINE_MANY',
/**
* Invoked before the component receives new props.
*
* Use this as an opportunity to react to a prop transition by updating the
* state using `this.setState`. Current props are accessed via `this.props`.
*
* componentWillReceiveProps: function(nextProps, nextContext) {
* this.setState({
* likesIncreasing: nextProps.likeCount > this.props.likeCount
* });
* }
*
* NOTE: There is no equivalent `componentWillReceiveState`. An incoming prop
* transition may cause a state change, but the opposite is not true. If you
* need it, you are probably looking for `componentWillUpdate`.
*
* @param {object} nextProps
* @optional
*/
componentWillReceiveProps: 'DEFINE_MANY',
/**
* Invoked while deciding if the component should be updated as a result of
* receiving new props, state and/or context.
*
* Use this as an opportunity to `return false` when you're certain that the
* transition to the new props/state/context will not require a component
* update.
*
* shouldComponentUpdate: function(nextProps, nextState, nextContext) {
* return !equal(nextProps, this.props) ||
* !equal(nextState, this.state) ||
* !equal(nextContext, this.context);
* }
*
* @param {object} nextProps
* @param {?object} nextState
* @param {?object} nextContext
* @return {boolean} True if the component should update.
* @optional
*/
shouldComponentUpdate: 'DEFINE_ONCE',
/**
* Invoked when the component is about to update due to a transition from
* `this.props`, `this.state` and `this.context` to `nextProps`, `nextState`
* and `nextContext`.
*
* Use this as an opportunity to perform preparation before an update occurs.
*
* NOTE: You **cannot** use `this.setState()` in this method.
*
* @param {object} nextProps
* @param {?object} nextState
* @param {?object} nextContext
* @param {ReactReconcileTransaction} transaction
* @optional
*/
componentWillUpdate: 'DEFINE_MANY',
/**
* Invoked when the component's DOM representation has been updated.
*
* Use this as an opportunity to operate on the DOM when the component has
* been updated.
*
* @param {object} prevProps
* @param {?object} prevState
* @param {?object} prevContext
* @param {DOMElement} rootNode DOM element representing the component.
* @optional
*/
componentDidUpdate: 'DEFINE_MANY',
/**
* Invoked when the component is about to be removed from its parent and have
* its DOM representation destroyed.
*
* Use this as an opportunity to deallocate any external resources.
*
* NOTE: There is no `componentDidUnmount` since your component will have been
* destroyed by that point.
*
* @optional
*/
componentWillUnmount: 'DEFINE_MANY',
// ==== Advanced methods ====
/**
* Updates the component's currently mounted DOM representation.
*
* By default, this implements React's rendering and reconciliation algorithm.
* Sophisticated clients may wish to override this.
*
* @param {ReactReconcileTransaction} transaction
* @internal
* @overridable
*/
updateComponent: 'OVERRIDE_BASE'
};
/**
* Mapping from class specification keys to special processing functions.
*
* Although these are declared like instance properties in the specification
* when defining classes using `React.createClass`, they are actually static
* and are accessible on the constructor instead of the prototype. Despite
* being static, they must be defined outside of the "statics" key under
* which all other static methods are defined.
*/
var RESERVED_SPEC_KEYS = {
displayName: function (Constructor, displayName) {
Constructor.displayName = displayName;
},
mixins: function (Constructor, mixins) {
if (mixins) {
for (var i = 0; i < mixins.length; i++) {
mixSpecIntoComponent(Constructor, mixins[i]);
}
}
},
childContextTypes: function (Constructor, childContextTypes) {
if ("development" !== 'production') {
validateTypeDef(Constructor, childContextTypes, 'childContext');
}
Constructor.childContextTypes = _assign({}, Constructor.childContextTypes, childContextTypes);
},
contextTypes: function (Constructor, contextTypes) {
if ("development" !== 'production') {
validateTypeDef(Constructor, contextTypes, 'context');
}
Constructor.contextTypes = _assign({}, Constructor.contextTypes, contextTypes);
},
/**
* Special case getDefaultProps which should move into statics but requires
* automatic merging.
*/
getDefaultProps: function (Constructor, getDefaultProps) {
if (Constructor.getDefaultProps) {
Constructor.getDefaultProps = createMergedResultFunction(Constructor.getDefaultProps, getDefaultProps);
} else {
Constructor.getDefaultProps = getDefaultProps;
}
},
propTypes: function (Constructor, propTypes) {
if ("development" !== 'production') {
validateTypeDef(Constructor, propTypes, 'prop');
}
Constructor.propTypes = _assign({}, Constructor.propTypes, propTypes);
},
statics: function (Constructor, statics) {
mixStaticSpecIntoComponent(Constructor, statics);
},
autobind: function () {} };
function validateTypeDef(Constructor, typeDef, location) {
for (var propName in typeDef) {
if (typeDef.hasOwnProperty(propName)) {
// use a warning instead of an invariant so components
// don't show up in prod but only in __DEV__
"development" !== 'production' ? warning(typeof typeDef[propName] === 'function', '%s: %s type `%s` is invalid; it must be a function, usually from ' + 'React.PropTypes.', Constructor.displayName || 'ReactClass', ReactPropTypeLocationNames[location], propName) : void 0;
}
}
}
function validateMethodOverride(isAlreadyDefined, name) {
var specPolicy = ReactClassInterface.hasOwnProperty(name) ? ReactClassInterface[name] : null;
// Disallow overriding of base class methods unless explicitly allowed.
if (ReactClassMixin.hasOwnProperty(name)) {
!(specPolicy === 'OVERRIDE_BASE') ? "development" !== 'production' ? invariant(false, 'ReactClassInterface: You are attempting to override `%s` from your class specification. Ensure that your method names do not overlap with React methods.', name) : _prodInvariant('73', name) : void 0;
}
// Disallow defining methods more than once unless explicitly allowed.
if (isAlreadyDefined) {
!(specPolicy === 'DEFINE_MANY' || specPolicy === 'DEFINE_MANY_MERGED') ? "development" !== 'production' ? invariant(false, 'ReactClassInterface: You are attempting to define `%s` on your component more than once. This conflict may be due to a mixin.', name) : _prodInvariant('74', name) : void 0;
}
}
/**
* Mixin helper which handles policy validation and reserved
* specification keys when building React classes.
*/
function mixSpecIntoComponent(Constructor, spec) {
if (!spec) {
if ("development" !== 'production') {
var typeofSpec = typeof spec;
var isMixinValid = typeofSpec === 'object' && spec !== null;
"development" !== 'production' ? warning(isMixinValid, '%s: You\'re attempting to include a mixin that is either null ' + 'or not an object. Check the mixins included by the component, ' + 'as well as any mixins they include themselves. ' + 'Expected object but got %s.', Constructor.displayName || 'ReactClass', spec === null ? null : typeofSpec) : void 0;
}
return;
}
!(typeof spec !== 'function') ? "development" !== 'production' ? invariant(false, 'ReactClass: You\'re attempting to use a component class or function as a mixin. Instead, just use a regular object.') : _prodInvariant('75') : void 0;
!!ReactElement.isValidElement(spec) ? "development" !== 'production' ? invariant(false, 'ReactClass: You\'re attempting to use a component as a mixin. Instead, just use a regular object.') : _prodInvariant('76') : void 0;
var proto = Constructor.prototype;
var autoBindPairs = proto.__reactAutoBindPairs;
// By handling mixins before any other properties, we ensure the same
// chaining order is applied to methods with DEFINE_MANY policy, whether
// mixins are listed before or after these methods in the spec.
if (spec.hasOwnProperty(MIXINS_KEY)) {
RESERVED_SPEC_KEYS.mixins(Constructor, spec.mixins);
}
for (var name in spec) {
if (!spec.hasOwnProperty(name)) {
continue;
}
if (name === MIXINS_KEY) {
// We have already handled mixins in a special case above.
continue;
}
var property = spec[name];
var isAlreadyDefined = proto.hasOwnProperty(name);
validateMethodOverride(isAlreadyDefined, name);
if (RESERVED_SPEC_KEYS.hasOwnProperty(name)) {
RESERVED_SPEC_KEYS[name](Constructor, property);
} else {
// Setup methods on prototype:
// The following member methods should not be automatically bound:
// 1. Expected ReactClass methods (in the "interface").
// 2. Overridden methods (that were mixed in).
var isReactClassMethod = ReactClassInterface.hasOwnProperty(name);
var isFunction = typeof property === 'function';
var shouldAutoBind = isFunction && !isReactClassMethod && !isAlreadyDefined && spec.autobind !== false;
if (shouldAutoBind) {
autoBindPairs.push(name, property);
proto[name] = property;
} else {
if (isAlreadyDefined) {
var specPolicy = ReactClassInterface[name];
// These cases should already be caught by validateMethodOverride.
!(isReactClassMethod && (specPolicy === 'DEFINE_MANY_MERGED' || specPolicy === 'DEFINE_MANY')) ? "development" !== 'production' ? invariant(false, 'ReactClass: Unexpected spec policy %s for key %s when mixing in component specs.', specPolicy, name) : _prodInvariant('77', specPolicy, name) : void 0;
// For methods which are defined more than once, call the existing
// methods before calling the new property, merging if appropriate.
if (specPolicy === 'DEFINE_MANY_MERGED') {
proto[name] = createMergedResultFunction(proto[name], property);
} else if (specPolicy === 'DEFINE_MANY') {
proto[name] = createChainedFunction(proto[name], property);
}
} else {
proto[name] = property;
if ("development" !== 'production') {
// Add verbose displayName to the function, which helps when looking
// at profiling tools.
if (typeof property === 'function' && spec.displayName) {
proto[name].displayName = spec.displayName + '_' + name;
}
}
}
}
}
}
}
function mixStaticSpecIntoComponent(Constructor, statics) {
if (!statics) {
return;
}
for (var name in statics) {
var property = statics[name];
if (!statics.hasOwnProperty(name)) {
continue;
}
var isReserved = name in RESERVED_SPEC_KEYS;
!!isReserved ? "development" !== 'production' ? invariant(false, 'ReactClass: You are attempting to define a reserved property, `%s`, that shouldn\'t be on the "statics" key. Define it as an instance property instead; it will still be accessible on the constructor.', name) : _prodInvariant('78', name) : void 0;
var isInherited = name in Constructor;
!!isInherited ? "development" !== 'production' ? invariant(false, 'ReactClass: You are attempting to define `%s` on your component more than once. This conflict may be due to a mixin.', name) : _prodInvariant('79', name) : void 0;
Constructor[name] = property;
}
}
/**
* Merge two objects, but throw if both contain the same key.
*
* @param {object} one The first object, which is mutated.
* @param {object} two The second object
* @return {object} one after it has been mutated to contain everything in two.
*/
function mergeIntoWithNoDuplicateKeys(one, two) {
!(one && two && typeof one === 'object' && typeof two === 'object') ? "development" !== 'production' ? invariant(false, 'mergeIntoWithNoDuplicateKeys(): Cannot merge non-objects.') : _prodInvariant('80') : void 0;
for (var key in two) {
if (two.hasOwnProperty(key)) {
!(one[key] === undefined) ? "development" !== 'production' ? invariant(false, 'mergeIntoWithNoDuplicateKeys(): Tried to merge two objects with the same key: `%s`. This conflict may be due to a mixin; in particular, this may be caused by two getInitialState() or getDefaultProps() methods returning objects with clashing keys.', key) : _prodInvariant('81', key) : void 0;
one[key] = two[key];
}
}
return one;
}
/**
* Creates a function that invokes two functions and merges their return values.
*
* @param {function} one Function to invoke first.
* @param {function} two Function to invoke second.
* @return {function} Function that invokes the two argument functions.
* @private
*/
function createMergedResultFunction(one, two) {
return function mergedResult() {
var a = one.apply(this, arguments);
var b = two.apply(this, arguments);
if (a == null) {
return b;
} else if (b == null) {
return a;
}
var c = {};
mergeIntoWithNoDuplicateKeys(c, a);
mergeIntoWithNoDuplicateKeys(c, b);
return c;
};
}
/**
* Creates a function that invokes two functions and ignores their return vales.
*
* @param {function} one Function to invoke first.
* @param {function} two Function to invoke second.
* @return {function} Function that invokes the two argument functions.
* @private
*/
function createChainedFunction(one, two) {
return function chainedFunction() {
one.apply(this, arguments);
two.apply(this, arguments);
};
}
/**
* Binds a method to the component.
*
* @param {object} component Component whose method is going to be bound.
* @param {function} method Method to be bound.
* @return {function} The bound method.
*/
function bindAutoBindMethod(component, method) {
var boundMethod = method.bind(component);
if ("development" !== 'production') {
boundMethod.__reactBoundContext = component;
boundMethod.__reactBoundMethod = method;
boundMethod.__reactBoundArguments = null;
var componentName = component.constructor.displayName;
var _bind = boundMethod.bind;
boundMethod.bind = function (newThis) {
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
// User is trying to bind() an autobound method; we effectively will
// ignore the value of "this" that the user is trying to use, so
// let's warn.
if (newThis !== component && newThis !== null) {
"development" !== 'production' ? warning(false, 'bind(): React component methods may only be bound to the ' + 'component instance. See %s', componentName) : void 0;
} else if (!args.length) {
"development" !== 'production' ? warning(false, 'bind(): You are binding a component method to the component. ' + 'React does this for you automatically in a high-performance ' + 'way, so you can safely remove this call. See %s', componentName) : void 0;
return boundMethod;
}
var reboundMethod = _bind.apply(boundMethod, arguments);
reboundMethod.__reactBoundContext = component;
reboundMethod.__reactBoundMethod = method;
reboundMethod.__reactBoundArguments = args;
return reboundMethod;
};
}
return boundMethod;
}
/**
* Binds all auto-bound methods in a component.
*
* @param {object} component Component whose method is going to be bound.
*/
function bindAutoBindMethods(component) {
var pairs = component.__reactAutoBindPairs;
for (var i = 0; i < pairs.length; i += 2) {
var autoBindKey = pairs[i];
var method = pairs[i + 1];
component[autoBindKey] = bindAutoBindMethod(component, method);
}
}
/**
* Add more to the ReactClass base class. These are all legacy features and
* therefore not already part of the modern ReactComponent.
*/
var ReactClassMixin = {
/**
* TODO: This will be deprecated because state should always keep a consistent
* type signature and the only use case for this, is to avoid that.
*/
replaceState: function (newState, callback) {
this.updater.enqueueReplaceState(this, newState);
if (callback) {
this.updater.enqueueCallback(this, callback, 'replaceState');
}
},
/**
* Checks whether or not this composite component is mounted.
* @return {boolean} True if mounted, false otherwise.
* @protected
* @final
*/
isMounted: function () {
return this.updater.isMounted(this);
}
};
var ReactClassComponent = function () {};
_assign(ReactClassComponent.prototype, ReactComponent.prototype, ReactClassMixin);
var didWarnDeprecated = false;
/**
* Module for creating composite components.
*
* @class ReactClass
*/
var ReactClass = {
/**
* Creates a composite component class given a class specification.
* See https://facebook.github.io/react/docs/top-level-api.html#react.createclass
*
* @param {object} spec Class specification (which must define `render`).
* @return {function} Component constructor function.
* @public
*/
createClass: function (spec) {
if ("development" !== 'production') {
"development" !== 'production' ? warning(didWarnDeprecated, '%s: React.createClass is deprecated and will be removed in version 16. ' + 'Use plain JavaScript classes instead. If you\'re not yet ready to ' + 'migrate, create-react-class is available on npm as a ' + 'drop-in replacement.', spec && spec.displayName || 'A Component') : void 0;
didWarnDeprecated = true;
}
// To keep our warnings more understandable, we'll use a little hack here to
// ensure that Constructor.name !== 'Constructor'. This makes sure we don't
// unnecessarily identify a class without displayName as 'Constructor'.
var Constructor = identity(function (props, context, updater) {
// This constructor gets overridden by mocks. The argument is used
// by mocks to assert on what gets mounted.
if ("development" !== 'production') {
"development" !== 'production' ? warning(this instanceof Constructor, 'Something is calling a React component directly. Use a factory or ' + 'JSX instead. See: https://fb.me/react-legacyfactory') : void 0;
}
// Wire up auto-binding
if (this.__reactAutoBindPairs.length) {
bindAutoBindMethods(this);
}
this.props = props;
this.context = context;
this.refs = emptyObject;
this.updater = updater || ReactNoopUpdateQueue;
this.state = null;
// ReactClasses doesn't have constructors. Instead, they use the
// getInitialState and componentWillMount methods for initialization.
var initialState = this.getInitialState ? this.getInitialState() : null;
if ("development" !== 'production') {
// We allow auto-mocks to proceed as if they're returning null.
if (initialState === undefined && this.getInitialState._isMockFunction) {
// This is probably bad practice. Consider warning here and
// deprecating this convenience.
initialState = null;
}
}
!(typeof initialState === 'object' && !Array.isArray(initialState)) ? "development" !== 'production' ? invariant(false, '%s.getInitialState(): must return an object or null', Constructor.displayName || 'ReactCompositeComponent') : _prodInvariant('82', Constructor.displayName || 'ReactCompositeComponent') : void 0;
this.state = initialState;
});
Constructor.prototype = new ReactClassComponent();
Constructor.prototype.constructor = Constructor;
Constructor.prototype.__reactAutoBindPairs = [];
injectedMixins.forEach(mixSpecIntoComponent.bind(null, Constructor));
mixSpecIntoComponent(Constructor, spec);
// Initialize the defaultProps property after all mixins have been merged.
if (Constructor.getDefaultProps) {
Constructor.defaultProps = Constructor.getDefaultProps();
}
if ("development" !== 'production') {
// This is a tag to indicate that the use of these method names is ok,
// since it's used with createClass. If it's not, then it's likely a
// mistake so we'll warn you to use the static property, property
// initializer or constructor respectively.
if (Constructor.getDefaultProps) {
Constructor.getDefaultProps.isReactClassApproved = {};
}
if (Constructor.prototype.getInitialState) {
Constructor.prototype.getInitialState.isReactClassApproved = {};
}
}
!Constructor.prototype.render ? "development" !== 'production' ? invariant(false, 'createClass(...): Class specification must implement a `render` method.') : _prodInvariant('83') : void 0;
if ("development" !== 'production') {
"development" !== 'production' ? warning(!Constructor.prototype.componentShouldUpdate, '%s has a method called ' + 'componentShouldUpdate(). Did you mean shouldComponentUpdate()? ' + 'The name is phrased as a question because the function is ' + 'expected to return a value.', spec.displayName || 'A component') : void 0;
"development" !== 'production' ? warning(!Constructor.prototype.componentWillRecieveProps, '%s has a method called ' + 'componentWillRecieveProps(). Did you mean componentWillReceiveProps()?', spec.displayName || 'A component') : void 0;
}
// Reduce time spent doing lookups by setting these on the prototype.
for (var methodName in ReactClassInterface) {
if (!Constructor.prototype[methodName]) {
Constructor.prototype[methodName] = null;
}
}
return Constructor;
},
injection: {
injectMixin: function (mixin) {
injectedMixins.push(mixin);
}
}
};
module.exports = ReactClass;
},{"10":10,"13":13,"14":14,"25":25,"28":28,"29":29,"30":30,"31":31,"6":6}],6:[function(_dereq_,module,exports){
/**
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
'use strict';
var _prodInvariant = _dereq_(25);
var ReactNoopUpdateQueue = _dereq_(13);
var canDefineProperty = _dereq_(20);
var emptyObject = _dereq_(28);
var invariant = _dereq_(29);
var warning = _dereq_(30);
/**
* Base class helpers for the updating state of a component.
*/
function ReactComponent(props, context, updater) {
this.props = props;
this.context = context;
this.refs = emptyObject;
// We initialize the default updater but the real one gets injected by the
// renderer.
this.updater = updater || ReactNoopUpdateQueue;
}
ReactComponent.prototype.isReactComponent = {};
/**
* Sets a subset of the state. Always use this to mutate
* state. You should treat `this.state` as immutable.
*
* There is no guarantee that `this.state` will be immediately updated, so
* accessing `this.state` after calling this method may return the old value.
*
* There is no guarantee that calls to `setState` will run synchronously,
* as they may eventually be batched together. You can provide an optional
* callback that will be executed when the call to setState is actually
* completed.
*
* When a function is provided to setState, it will be called at some point in
* the future (not synchronously). It will be called with the up to date
* component arguments (state, props, context). These values can be different
* from this.* because your function may be called after receiveProps but before
* shouldComponentUpdate, and this new state, props, and context will not yet be
* assigned to this.
*
* @param {object|function} partialState Next partial state or function to
* produce next partial state to be merged with current state.
* @param {?function} callback Called after state is updated.
* @final
* @protected
*/
ReactComponent.prototype.setState = function (partialState, callback) {
!(typeof partialState === 'object' || typeof partialState === 'function' || partialState == null) ? "development" !== 'production' ? invariant(false, 'setState(...): takes an object of state variables to update or a function which returns an object of state variables.') : _prodInvariant('85') : void 0;
this.updater.enqueueSetState(this, partialState);
if (callback) {
this.updater.enqueueCallback(this, callback, 'setState');
}
};
/**
* Forces an update. This should only be invoked when it is known with
* certainty that we are **not** in a DOM transaction.
*
* You may want to call this when you know that some deeper aspect of the
* component's state has changed but `setState` was not called.
*
* This will not invoke `shouldComponentUpdate`, but it will invoke
* `componentWillUpdate` and `componentDidUpdate`.
*
* @param {?function} callback Called after update is complete.
* @final
* @protected
*/
ReactComponent.prototype.forceUpdate = function (callback) {
this.updater.enqueueForceUpdate(this);
if (callback) {
this.updater.enqueueCallback(this, callback, 'forceUpdate');
}
};
/**
* Deprecated APIs. These APIs used to exist on classic React classes but since
* we would like to deprecate them, we're not going to move them over to this
* modern base class. Instead, we define a getter that warns if it's accessed.
*/
if ("development" !== 'production') {
var deprecatedAPIs = {
isMounted: ['isMounted', 'Instead, make sure to clean up subscriptions and pending requests in ' + 'componentWillUnmount to prevent memory leaks.'],
replaceState: ['replaceState', 'Refactor your code to use setState instead (see ' + 'https://github.com/facebook/react/issues/3236).']
};
var defineDeprecationWarning = function (methodName, info) {
if (canDefineProperty) {
Object.defineProperty(ReactComponent.prototype, methodName, {
get: function () {
"development" !== 'production' ? warning(false, '%s(...) is deprecated in plain JavaScript React classes. %s', info[0], info[1]) : void 0;
return undefined;
}
});
}
};
for (var fnName in deprecatedAPIs) {
if (deprecatedAPIs.hasOwnProperty(fnName)) {
defineDeprecationWarning(fnName, deprecatedAPIs[fnName]);
}
}
}
module.exports = ReactComponent;
},{"13":13,"20":20,"25":25,"28":28,"29":29,"30":30}],7:[function(_dereq_,module,exports){
/**
* Copyright 2016-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*
*/
'use strict';
var _prodInvariant = _dereq_(25);
var ReactCurrentOwner = _dereq_(8);
var invariant = _dereq_(29);
var warning = _dereq_(30);
function isNative(fn) {
// Based on isNative() from Lodash
var funcToString = Function.prototype.toString;
var hasOwnProperty = Object.prototype.hasOwnProperty;
var reIsNative = RegExp('^' + funcToString
// Take an example native function source for comparison
.call(hasOwnProperty)
// Strip regex characters so we can use it for regex
.replace(/[\\^$.*+?()[\]{}|]/g, '\\$&')
// Remove hasOwnProperty from the template to make it generic
.replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$');
try {
var source = funcToString.call(fn);
return reIsNative.test(source);
} catch (err) {
return false;
}
}
var canUseCollections =
// Array.from
typeof Array.from === 'function' &&
// Map
typeof Map === 'function' && isNative(Map) &&
// Map.prototype.keys
Map.prototype != null && typeof Map.prototype.keys === 'function' && isNative(Map.prototype.keys) &&
// Set
typeof Set === 'function' && isNative(Set) &&
// Set.prototype.keys
Set.prototype != null && typeof Set.prototype.keys === 'function' && isNative(Set.prototype.keys);
var setItem;
var getItem;
var removeItem;
var getItemIDs;
var addRoot;
var removeRoot;
var getRootIDs;
if (canUseCollections) {
var itemMap = new Map();
var rootIDSet = new Set();
setItem = function (id, item) {
itemMap.set(id, item);
};
getItem = function (id) {
return itemMap.get(id);
};
removeItem = function (id) {
itemMap['delete'](id);
};
getItemIDs = function () {
return Array.from(itemMap.keys());
};
addRoot = function (id) {
rootIDSet.add(id);
};
removeRoot = function (id) {
rootIDSet['delete'](id);
};
getRootIDs = function () {
return Array.from(rootIDSet.keys());
};
} else {
var itemByKey = {};
var rootByKey = {};
// Use non-numeric keys to prevent V8 performance issues:
// https://github.com/facebook/react/pull/7232
var getKeyFromID = function (id) {
return '.' + id;
};
var getIDFromKey = function (key) {
return parseInt(key.substr(1), 10);
};
setItem = function (id, item) {
var key = getKeyFromID(id);
itemByKey[key] = item;
};
getItem = function (id) {
var key = getKeyFromID(id);
return itemByKey[key];
};
removeItem = function (id) {
var key = getKeyFromID(id);
delete itemByKey[key];
};
getItemIDs = function () {
return Object.keys(itemByKey).map(getIDFromKey);
};
addRoot = function (id) {
var key = getKeyFromID(id);
rootByKey[key] = true;
};
removeRoot = function (id) {
var key = getKeyFromID(id);
delete rootByKey[key];
};
getRootIDs = function () {
return Object.keys(rootByKey).map(getIDFromKey);
};
}
var unmountedIDs = [];
function purgeDeep(id) {
var item = getItem(id);
if (item) {
var childIDs = item.childIDs;
removeItem(id);
childIDs.forEach(purgeDeep);
}
}
function describeComponentFrame(name, source, ownerName) {
return '\n in ' + (name || 'Unknown') + (source ? ' (at ' + source.fileName.replace(/^.*[\\\/]/, '') + ':' + source.lineNumber + ')' : ownerName ? ' (created by ' + ownerName + ')' : '');
}
function getDisplayName(element) {
if (element == null) {
return '#empty';
} else if (typeof element === 'string' || typeof element === 'number') {
return '#text';
} else if (typeof element.type === 'string') {
return element.type;
} else {
return element.type.displayName || element.type.name || 'Unknown';
}
}
function describeID(id) {
var name = ReactComponentTreeHook.getDisplayName(id);
var element = ReactComponentTreeHook.getElement(id);
var ownerID = ReactComponentTreeHook.getOwnerID(id);
var ownerName;
if (ownerID) {
ownerName = ReactComponentTreeHook.getDisplayName(ownerID);
}
"development" !== 'production' ? warning(element, 'ReactComponentTreeHook: Missing React element for debugID %s when ' + 'building stack', id) : void 0;
return describeComponentFrame(name, element && element._source, ownerName);
}
var ReactComponentTreeHook = {
onSetChildren: function (id, nextChildIDs) {
var item = getItem(id);
!item ? "development" !== 'production' ? invariant(false, 'Item must have been set') : _prodInvariant('144') : void 0;
item.childIDs = nextChildIDs;
for (var i = 0; i < nextChildIDs.length; i++) {
var nextChildID = nextChildIDs[i];
var nextChild = getItem(nextChildID);
!nextChild ? "development" !== 'production' ? invariant(false, 'Expected hook events to fire for the child before its parent includes it in onSetChildren().') : _prodInvariant('140') : void 0;
!(nextChild.childIDs != null || typeof nextChild.element !== 'object' || nextChild.element == null) ? "development" !== 'production' ? invariant(false, 'Expected onSetChildren() to fire for a container child before its parent includes it in onSetChildren().') : _prodInvariant('141') : void 0;
!nextChild.isMounted ? "development" !== 'production' ? invariant(false, 'Expected onMountComponent() to fire for the child before its parent includes it in onSetChildren().') : _prodInvariant('71') : void 0;
if (nextChild.parentID == null) {
nextChild.parentID = id;
// TODO: This shouldn't be necessary but mounting a new root during in
// componentWillMount currently causes not-yet-mounted components to
// be purged from our tree data so their parent id is missing.
}
!(nextChild.parentID === id) ? "development" !== 'production' ? invariant(false, 'Expected onBeforeMountComponent() parent and onSetChildren() to be consistent (%s has parents %s and %s).', nextChildID, nextChild.parentID, id) : _prodInvariant('142', nextChildID, nextChild.parentID, id) : void 0;
}
},
onBeforeMountComponent: function (id, element, parentID) {
var item = {
element: element,
parentID: parentID,
text: null,
childIDs: [],
isMounted: false,
updateCount: 0
};
setItem(id, item);
},
onBeforeUpdateComponent: function (id, element) {
var item = getItem(id);
if (!item || !item.isMounted) {
// We may end up here as a result of setState() in componentWillUnmount().
// In this case, ignore the element.
return;
}
item.element = element;
},
onMountComponent: function (id) {
var item = getItem(id);
!item ? "development" !== 'production' ? invariant(false, 'Item must have been set') : _prodInvariant('144') : void 0;
item.isMounted = true;
var isRoot = item.parentID === 0;
if (isRoot) {
addRoot(id);
}
},
onUpdateComponent: function (id) {
var item = getItem(id);
if (!item || !item.isMounted) {
// We may end up here as a result of setState() in componentWillUnmount().
// In this case, ignore the element.
return;
}
item.updateCount++;
},
onUnmountComponent: function (id) {
var item = getItem(id);
if (item) {
// We need to check if it exists.
// `item` might not exist if it is inside an error boundary, and a sibling
// error boundary child threw while mounting. Then this instance never
// got a chance to mount, but it still gets an unmounting event during
// the error boundary cleanup.
item.isMounted = false;
var isRoot = item.parentID === 0;
if (isRoot) {
removeRoot(id);
}
}
unmountedIDs.push(id);
},
purgeUnmountedComponents: function () {
if (ReactComponentTreeHook._preventPurging) {
// Should only be used for testing.
return;
}
for (var i = 0; i < unmountedIDs.length; i++) {
var id = unmountedIDs[i];
purgeDeep(id);
}
unmountedIDs.length = 0;
},
isMounted: function (id) {
var item = getItem(id);
return item ? item.isMounted : false;
},
getCurrentStackAddendum: function (topElement) {
var info = '';
if (topElement) {
var name = getDisplayName(topElement);
var owner = topElement._owner;
info += describeComponentFrame(name, topElement._source, owner && owner.getName());
}
var currentOwner = ReactCurrentOwner.current;
var id = currentOwner && currentOwner._debugID;
info += ReactComponentTreeHook.getStackAddendumByID(id);
return info;
},
getStackAddendumByID: function (id) {
var info = '';
while (id) {
info += describeID(id);
id = ReactComponentTreeHook.getParentID(id);
}
return info;
},
getChildIDs: function (id) {
var item = getItem(id);
return item ? item.childIDs : [];
},
getDisplayName: function (id) {
var element = ReactComponentTreeHook.getElement(id);
if (!element) {
return null;
}
return getDisplayName(element);
},
getElement: function (id) {
var item = getItem(id);
return item ? item.element : null;
},
getOwnerID: function (id) {
var element = ReactComponentTreeHook.getElement(id);
if (!element || !element._owner) {
return null;
}
return element._owner._debugID;
},
getParentID: function (id) {
var item = getItem(id);
return item ? item.parentID : null;
},
getSource: function (id) {
var item = getItem(id);
var element = item ? item.element : null;
var source = element != null ? element._source : null;
return source;
},
getText: function (id) {
var element = ReactComponentTreeHook.getElement(id);
if (typeof element === 'string') {
return element;
} else if (typeof element === 'number') {
return '' + element;
} else {
return null;
}
},
getUpdateCount: function (id) {
var item = getItem(id);
return item ? item.updateCount : 0;
},
getRootIDs: getRootIDs,
getRegisteredIDs: getItemIDs
};
module.exports = ReactComponentTreeHook;
},{"25":25,"29":29,"30":30,"8":8}],8:[function(_dereq_,module,exports){
/**
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*
*/
'use strict';
/**
* Keeps track of the current owner.
*
* The current owner is the component who should own any components that are
* currently being constructed.
*/
var ReactCurrentOwner = {
/**
* @internal
* @type {ReactComponent}
*/
current: null
};
module.exports = ReactCurrentOwner;
},{}],9:[function(_dereq_,module,exports){
/**
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
'use strict';
var ReactElement = _dereq_(10);
/**
* Create a factory that creates HTML tag elements.
*
* @private
*/
var createDOMFactory = ReactElement.createFactory;
if ("development" !== 'production') {
var ReactElementValidator = _dereq_(12);
createDOMFactory = ReactElementValidator.createFactory;
}
/**
* Creates a mapping from supported HTML tags to `ReactDOMComponent` classes.
* This is also accessible via `React.DOM`.
*
* @public
*/
var ReactDOMFactories = {
a: createDOMFactory('a'),
abbr: createDOMFactory('abbr'),
address: createDOMFactory('address'),
area: createDOMFactory('area'),
article: createDOMFactory('article'),
aside: createDOMFactory('aside'),
audio: createDOMFactory('audio'),
b: createDOMFactory('b'),
base: createDOMFactory('base'),
bdi: createDOMFactory('bdi'),
bdo: createDOMFactory('bdo'),
big: createDOMFactory('big'),
blockquote: createDOMFactory('blockquote'),
body: createDOMFactory('body'),
br: createDOMFactory('br'),
button: createDOMFactory('button'),
canvas: createDOMFactory('canvas'),
caption: createDOMFactory('caption'),
cite: createDOMFactory('cite'),
code: createDOMFactory('code'),
col: createDOMFactory('col'),
colgroup: createDOMFactory('colgroup'),
data: createDOMFactory('data'),
datalist: createDOMFactory('datalist'),
dd: createDOMFactory('dd'),
del: createDOMFactory('del'),
details: createDOMFactory('details'),
dfn: createDOMFactory('dfn'),
dialog: createDOMFactory('dialog'),
div: createDOMFactory('div'),
dl: createDOMFactory('dl'),
dt: createDOMFactory('dt'),
em: createDOMFactory('em'),
embed: createDOMFactory('embed'),
fieldset: createDOMFactory('fieldset'),
figcaption: createDOMFactory('figcaption'),
figure: createDOMFactory('figure'),
footer: createDOMFactory('footer'),
form: createDOMFactory('form'),
h1: createDOMFactory('h1'),
h2: createDOMFactory('h2'),
h3: createDOMFactory('h3'),
h4: createDOMFactory('h4'),
h5: createDOMFactory('h5'),
h6: createDOMFactory('h6'),
head: createDOMFactory('head'),
header: createDOMFactory('header'),
hgroup: createDOMFactory('hgroup'),
hr: createDOMFactory('hr'),
html: createDOMFactory('html'),
i: createDOMFactory('i'),
iframe: createDOMFactory('iframe'),
img: createDOMFactory('img'),
input: createDOMFactory('input'),
ins: createDOMFactory('ins'),
kbd: createDOMFactory('kbd'),
keygen: createDOMFactory('keygen'),
label: createDOMFactory('label'),
legend: createDOMFactory('legend'),
li: createDOMFactory('li'),
link: createDOMFactory('link'),
main: createDOMFactory('main'),
map: createDOMFactory('map'),
mark: createDOMFactory('mark'),
menu: createDOMFactory('menu'),
menuitem: createDOMFactory('menuitem'),
meta: createDOMFactory('meta'),
meter: createDOMFactory('meter'),
nav: createDOMFactory('nav'),
noscript: createDOMFactory('noscript'),
object: createDOMFactory('object'),
ol: createDOMFactory('ol'),
optgroup: createDOMFactory('optgroup'),
option: createDOMFactory('option'),
output: createDOMFactory('output'),
p: createDOMFactory('p'),
param: createDOMFactory('param'),
picture: createDOMFactory('picture'),
pre: createDOMFactory('pre'),
progress: createDOMFactory('progress'),
q: createDOMFactory('q'),
rp: createDOMFactory('rp'),
rt: createDOMFactory('rt'),
ruby: createDOMFactory('ruby'),
s: createDOMFactory('s'),
samp: createDOMFactory('samp'),
script: createDOMFactory('script'),
section: createDOMFactory('section'),
select: createDOMFactory('select'),
small: createDOMFactory('small'),
source: createDOMFactory('source'),
span: createDOMFactory('span'),
strong: createDOMFactory('strong'),
style: createDOMFactory('style'),
sub: createDOMFactory('sub'),
summary: createDOMFactory('summary'),
sup: createDOMFactory('sup'),
table: createDOMFactory('table'),
tbody: createDOMFactory('tbody'),
td: createDOMFactory('td'),
textarea: createDOMFactory('textarea'),
tfoot: createDOMFactory('tfoot'),
th: createDOMFactory('th'),
thead: createDOMFactory('thead'),
time: createDOMFactory('time'),
title: createDOMFactory('title'),
tr: createDOMFactory('tr'),
track: createDOMFactory('track'),
u: createDOMFactory('u'),
ul: createDOMFactory('ul'),
'var': createDOMFactory('var'),
video: createDOMFactory('video'),
wbr: createDOMFactory('wbr'),
// SVG
circle: createDOMFactory('circle'),
clipPath: createDOMFactory('clipPath'),
defs: createDOMFactory('defs'),
ellipse: createDOMFactory('ellipse'),
g: createDOMFactory('g'),
image: createDOMFactory('image'),
line: createDOMFactory('line'),
linearGradient: createDOMFactory('linearGradient'),
mask: createDOMFactory('mask'),
path: createDOMFactory('path'),
pattern: createDOMFactory('pattern'),
polygon: createDOMFactory('polygon'),
polyline: createDOMFactory('polyline'),
radialGradient: createDOMFactory('radialGradient'),
rect: createDOMFactory('rect'),
stop: createDOMFactory('stop'),
svg: createDOMFactory('svg'),
text: createDOMFactory('text'),
tspan: createDOMFactory('tspan')
};
module.exports = ReactDOMFactories;
},{"10":10,"12":12}],10:[function(_dereq_,module,exports){
/**
* Copyright 2014-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
'use strict';
var _assign = _dereq_(31);
var ReactCurrentOwner = _dereq_(8);
var warning = _dereq_(30);
var canDefineProperty = _dereq_(20);
var hasOwnProperty = Object.prototype.hasOwnProperty;
var REACT_ELEMENT_TYPE = _dereq_(11);
var RESERVED_PROPS = {
key: true,
ref: true,
__self: true,
__source: true
};
var specialPropKeyWarningShown, specialPropRefWarningShown;
function hasValidRef(config) {
if ("development" !== 'production') {
if (hasOwnProperty.call(config, 'ref')) {
var getter = Object.getOwnPropertyDescriptor(config, 'ref').get;
if (getter && getter.isReactWarning) {
return false;
}
}
}
return config.ref !== undefined;
}
function hasValidKey(config) {
if ("development" !== 'production') {
if (hasOwnProperty.call(config, 'key')) {
var getter = Object.getOwnPropertyDescriptor(config, 'key').get;
if (getter && getter.isReactWarning) {
return false;
}
}
}
return config.key !== undefined;
}
function defineKeyPropWarningGetter(props, displayName) {
var warnAboutAccessingKey = function () {
if (!specialPropKeyWarningShown) {
specialPropKeyWarningShown = true;
"development" !== 'production' ? warning(false, '%s: `key` is not a prop. Trying to access it will result ' + 'in `undefined` being returned. If you need to access the same ' + 'value within the child component, you should pass it as a different ' + 'prop. (https://fb.me/react-special-props)', displayName) : void 0;
}
};
warnAboutAccessingKey.isReactWarning = true;
Object.defineProperty(props, 'key', {
get: warnAboutAccessingKey,
configurable: true
});
}
function defineRefPropWarningGetter(props, displayName) {
var warnAboutAccessingRef = function () {
if (!specialPropRefWarningShown) {
specialPropRefWarningShown = true;
"development" !== 'production' ? warning(false, '%s: `ref` is not a prop. Trying to access it will result ' + 'in `undefined` being returned. If you need to access the same ' + 'value within the child component, you should pass it as a different ' + 'prop. (https://fb.me/react-special-props)', displayName) : void 0;
}
};
warnAboutAccessingRef.isReactWarning = true;
Object.defineProperty(props, 'ref', {
get: warnAboutAccessingRef,
configurable: true
});
}
/**
* Factory method to create a new React element. This no longer adheres to
* the class pattern, so do not use new to call it. Also, no instanceof check
* will work. Instead test $$typeof field against Symbol.for('react.element') to check
* if something is a React Element.
*
* @param {*} type
* @param {*} key
* @param {string|object} ref
* @param {*} self A *temporary* helper to detect places where `this` is
* different from the `owner` when React.createElement is called, so that we
* can warn. We want to get rid of owner and replace string `ref`s with arrow
* functions, and as long as `this` and owner are the same, there will be no
* change in behavior.
* @param {*} source An annotation object (added by a transpiler or otherwise)
* indicating filename, line number, and/or other information.
* @param {*} owner
* @param {*} props
* @internal
*/
var ReactElement = function (type, key, ref, self, source, owner, props) {
var element = {
// This tag allow us to uniquely identify this as a React Element
$$typeof: REACT_ELEMENT_TYPE,
// Built-in properties that belong on the element
type: type,
key: key,
ref: ref,
props: props,
// Record the component responsible for creating this element.
_owner: owner
};
if ("development" !== 'production') {
// The validation flag is currently mutative. We put it on
// an external backing store so that we can freeze the whole object.
// This can be replaced with a WeakMap once they are implemented in
// commonly used development environments.
element._store = {};
// To make comparing ReactElements easier for testing purposes, we make
// the validation flag non-enumerable (where possible, which should
// include every environment we run tests in), so the test framework
// ignores it.
if (canDefineProperty) {
Object.defineProperty(element._store, 'validated', {
configurable: false,
enumerable: false,
writable: true,
value: false
});
// self and source are DEV only properties.
Object.defineProperty(element, '_self', {
configurable: false,
enumerable: false,
writable: false,
value: self
});
// Two elements created in two different places should be considered
// equal for testing purposes and therefore we hide it from enumeration.
Object.defineProperty(element, '_source', {
configurable: false,
enumerable: false,
writable: false,
value: source
});
} else {
element._store.validated = false;
element._self = self;
element._source = source;
}
if (Object.freeze) {
Object.freeze(element.props);
Object.freeze(element);
}
}
return element;
};
/**
* Create and return a new ReactElement of the given type.
* See https://facebook.github.io/react/docs/top-level-api.html#react.createelement
*/
ReactElement.createElement = function (type, config, children) {
var propName;
// Reserved names are extracted
var props = {};
var key = null;
var ref = null;
var self = null;
var source = null;
if (config != null) {
if (hasValidRef(config)) {
ref = config.ref;
}
if (hasValidKey(config)) {
key = '' + config.key;
}
self = config.__self === undefined ? null : config.__self;
source = config.__source === undefined ? null : config.__source;
// Remaining properties are added to a new props object
for (propName in config) {
if (hasOwnProperty.call(config, propName) && !RESERVED_PROPS.hasOwnProperty(propName)) {
props[propName] = config[propName];
}
}
}
// Children can be more than one argument, and those are transferred onto
// the newly allocated props object.
var childrenLength = arguments.length - 2;
if (childrenLength === 1) {
props.children = children;
} else if (childrenLength > 1) {
var childArray = Array(childrenLength);
for (var i = 0; i < childrenLength; i++) {
childArray[i] = arguments[i + 2];
}
if ("development" !== 'production') {
if (Object.freeze) {
Object.freeze(childArray);
}
}
props.children = childArray;
}
// Resolve default props
if (type && type.defaultProps) {
var defaultProps = type.defaultProps;
for (propName in defaultProps) {
if (props[propName] === undefined) {
props[propName] = defaultProps[propName];
}
}
}
if ("development" !== 'production') {
if (key || ref) {
if (typeof props.$$typeof === 'undefined' || props.$$typeof !== REACT_ELEMENT_TYPE) {
var displayName = typeof type === 'function' ? type.displayName || type.name || 'Unknown' : type;
if (key) {
defineKeyPropWarningGetter(props, displayName);
}
if (ref) {
defineRefPropWarningGetter(props, displayName);
}
}
}
}
return ReactElement(type, key, ref, self, source, ReactCurrentOwner.current, props);
};
/**
* Return a function that produces ReactElements of a given type.
* See https://facebook.github.io/react/docs/top-level-api.html#react.createfactory
*/
ReactElement.createFactory = function (type) {
var factory = ReactElement.createElement.bind(null, type);
// Expose the type on the factory and the prototype so that it can be
// easily accessed on elements. E.g. `.type === Foo`.
// This should not be named `constructor` since this may not be the function
// that created the element, and it may not even be a constructor.
// Legacy hook TODO: Warn if this is accessed
factory.type = type;
return factory;
};
ReactElement.cloneAndReplaceKey = function (oldElement, newKey) {
var newElement = ReactElement(oldElement.type, newKey, oldElement.ref, oldElement._self, oldElement._source, oldElement._owner, oldElement.props);
return newElement;
};
/**
* Clone and return a new ReactElement using element as the starting point.
* See https://facebook.github.io/react/docs/top-level-api.html#react.cloneelement
*/
ReactElement.cloneElement = function (element, config, children) {
var propName;
// Original props are copied
var props = _assign({}, element.props);
// Reserved names are extracted
var key = element.key;
var ref = element.ref;
// Self is preserved since the owner is preserved.
var self = element._self;
// Source is preserved since cloneElement is unlikely to be targeted by a
// transpiler, and the original source is probably a better indicator of the
// true owner.
var source = element._source;
// Owner will be preserved, unless ref is overridden
var owner = element._owner;
if (config != null) {
if (hasValidRef(config)) {
// Silently steal the ref from the parent.
ref = config.ref;
owner = ReactCurrentOwner.current;
}
if (hasValidKey(config)) {
key = '' + config.key;
}
// Remaining properties override existing props
var defaultProps;
if (element.type && element.type.defaultProps) {
defaultProps = element.type.defaultProps;
}
for (propName in config) {
if (hasOwnProperty.call(config, propName) && !RESERVED_PROPS.hasOwnProperty(propName)) {
if (config[propName] === undefined && defaultProps !== undefined) {
// Resolve default props
props[propName] = defaultProps[propName];
} else {
props[propName] = config[propName];
}
}
}
}
// Children can be more than one argument, and those are transferred onto
// the newly allocated props object.
var childrenLength = arguments.length - 2;
if (childrenLength === 1) {
props.children = children;
} else if (childrenLength > 1) {
var childArray = Array(childrenLength);
for (var i = 0; i < childrenLength; i++) {
childArray[i] = arguments[i + 2];
}
props.children = childArray;
}
return ReactElement(element.type, key, ref, self, source, owner, props);
};
/**
* Verifies the object is a ReactElement.
* See https://facebook.github.io/react/docs/top-level-api.html#react.isvalidelement
* @param {?object} object
* @return {boolean} True if `object` is a valid component.
* @final
*/
ReactElement.isValidElement = function (object) {
return typeof object === 'object' && object !== null && object.$$typeof === REACT_ELEMENT_TYPE;
};
module.exports = ReactElement;
},{"11":11,"20":20,"30":30,"31":31,"8":8}],11:[function(_dereq_,module,exports){
/**
* Copyright 2014-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*
*/
'use strict';
// The Symbol used to tag the ReactElement type. If there is no native Symbol
// nor polyfill, then a plain number is used for performance.
var REACT_ELEMENT_TYPE = typeof Symbol === 'function' && Symbol['for'] && Symbol['for']('react.element') || 0xeac7;
module.exports = REACT_ELEMENT_TYPE;
},{}],12:[function(_dereq_,module,exports){
/**
* Copyright 2014-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
/**
* ReactElementValidator provides a wrapper around a element factory
* which validates the props passed to the element. This is intended to be
* used only in DEV and could be replaced by a static type checker for languages
* that support it.
*/
'use strict';
var ReactCurrentOwner = _dereq_(8);
var ReactComponentTreeHook = _dereq_(7);
var ReactElement = _dereq_(10);
var checkReactTypeSpec = _dereq_(21);
var canDefineProperty = _dereq_(20);
var getIteratorFn = _dereq_(22);
var warning = _dereq_(30);
function getDeclarationErrorAddendum() {
if (ReactCurrentOwner.current) {
var name = ReactCurrentOwner.current.getName();
if (name) {
return ' Check the render method of `' + name + '`.';
}
}
return '';
}
function getSourceInfoErrorAddendum(elementProps) {
if (elementProps !== null && elementProps !== undefined && elementProps.__source !== undefined) {
var source = elementProps.__source;
var fileName = source.fileName.replace(/^.*[\\\/]/, '');
var lineNumber = source.lineNumber;
return ' Check your code at ' + fileName + ':' + lineNumber + '.';
}
return '';
}
/**
* Warn if there's no key explicitly set on dynamic arrays of children or
* object keys are not valid. This allows us to keep track of children between
* updates.
*/
var ownerHasKeyUseWarning = {};
function getCurrentComponentErrorInfo(parentType) {
var info = getDeclarationErrorAddendum();
if (!info) {
var parentName = typeof parentType === 'string' ? parentType : parentType.displayName || parentType.name;
if (parentName) {
info = ' Check the top-level render call using <' + parentName + '>.';
}
}
return info;
}
/**
* Warn if the element doesn't have an explicit key assigned to it.
* This element is in an array. The array could grow and shrink or be
* reordered. All children that haven't already been validated are required to
* have a "key" property assigned to it. Error statuses are cached so a warning
* will only be shown once.
*
* @internal
* @param {ReactElement} element Element that requires a key.
* @param {*} parentType element's parent's type.
*/
function validateExplicitKey(element, parentType) {
if (!element._store || element._store.validated || element.key != null) {
return;
}
element._store.validated = true;
var memoizer = ownerHasKeyUseWarning.uniqueKey || (ownerHasKeyUseWarning.uniqueKey = {});
var currentComponentErrorInfo = getCurrentComponentErrorInfo(parentType);
if (memoizer[currentComponentErrorInfo]) {
return;
}
memoizer[currentComponentErrorInfo] = true;
// Usually the current owner is the offender, but if it accepts children as a
// property, it may be the creator of the child that's responsible for
// assigning it a key.
var childOwner = '';
if (element && element._owner && element._owner !== ReactCurrentOwner.current) {
// Give the component that originally created this child.
childOwner = ' It was passed a child from ' + element._owner.getName() + '.';
}
"development" !== 'production' ? warning(false, 'Each child in an array or iterator should have a unique "key" prop.' + '%s%s See https://fb.me/react-warning-keys for more information.%s', currentComponentErrorInfo, childOwner, ReactComponentTreeHook.getCurrentStackAddendum(element)) : void 0;
}
/**
* Ensure that every element either is passed in a static location, in an
* array with an explicit keys property defined, or in an object literal
* with valid key property.
*
* @internal
* @param {ReactNode} node Statically passed child of any type.
* @param {*} parentType node's parent's type.
*/
function validateChildKeys(node, parentType) {
if (typeof node !== 'object') {
return;
}
if (Array.isArray(node)) {
for (var i = 0; i < node.length; i++) {
var child = node[i];
if (ReactElement.isValidElement(child)) {
validateExplicitKey(child, parentType);
}
}
} else if (ReactElement.isValidElement(node)) {
// This element was passed in a valid location.
if (node._store) {
node._store.validated = true;
}
} else if (node) {
var iteratorFn = getIteratorFn(node);
// Entry iterators provide implicit keys.
if (iteratorFn) {
if (iteratorFn !== node.entries) {
var iterator = iteratorFn.call(node);
var step;
while (!(step = iterator.next()).done) {
if (ReactElement.isValidElement(step.value)) {
validateExplicitKey(step.value, parentType);
}
}
}
}
}
}
/**
* Given an element, validate that its props follow the propTypes definition,
* provided by the type.
*
* @param {ReactElement} element
*/
function validatePropTypes(element) {
var componentClass = element.type;
if (typeof componentClass !== 'function') {
return;
}
var name = componentClass.displayName || componentClass.name;
if (componentClass.propTypes) {
checkReactTypeSpec(componentClass.propTypes, element.props, 'prop', name, element, null);
}
if (typeof componentClass.getDefaultProps === 'function') {
"development" !== 'production' ? warning(componentClass.getDefaultProps.isReactClassApproved, 'getDefaultProps is only used on classic React.createClass ' + 'definitions. Use a static property named `defaultProps` instead.') : void 0;
}
}
var ReactElementValidator = {
createElement: function (type, props, children) {
var validType = typeof type === 'string' || typeof type === 'function';
// We warn in this case but don't throw. We expect the element creation to
// succeed and there will likely be errors in render.
if (!validType) {
if (typeof type !== 'function' && typeof type !== 'string') {
var info = '';
if (type === undefined || typeof type === 'object' && type !== null && Object.keys(type).length === 0) {
info += ' You likely forgot to export your component from the file ' + 'it\'s defined in.';
}
var sourceInfo = getSourceInfoErrorAddendum(props);
if (sourceInfo) {
info += sourceInfo;
} else {
info += getDeclarationErrorAddendum();
}
info += ReactComponentTreeHook.getCurrentStackAddendum();
"development" !== 'production' ? warning(false, 'React.createElement: type is invalid -- expected a string (for ' + 'built-in components) or a class/function (for composite ' + 'components) but got: %s.%s', type == null ? type : typeof type, info) : void 0;
}
}
var element = ReactElement.createElement.apply(this, arguments);
// The result can be nullish if a mock or a custom function is used.
// TODO: Drop this when these are no longer allowed as the type argument.
if (element == null) {
return element;
}
// Skip key warning if the type isn't valid since our key validation logic
// doesn't expect a non-string/function type and can throw confusing errors.
// We don't want exception behavior to differ between dev and prod.
// (Rendering will throw with a helpful message and as soon as the type is
// fixed, the key warnings will appear.)
if (validType) {
for (var i = 2; i < arguments.length; i++) {
validateChildKeys(arguments[i], type);
}
}
validatePropTypes(element);
return element;
},
createFactory: function (type) {
var validatedFactory = ReactElementValidator.createElement.bind(null, type);
// Legacy hook TODO: Warn if this is accessed
validatedFactory.type = type;
if ("development" !== 'production') {
if (canDefineProperty) {
Object.defineProperty(validatedFactory, 'type', {
enumerable: false,
get: function () {
"development" !== 'production' ? warning(false, 'Factory.type is deprecated. Access the class directly ' + 'before passing it to createFactory.') : void 0;
Object.defineProperty(this, 'type', {
value: type
});
return type;
}
});
}
}
return validatedFactory;
},
cloneElement: function (element, props, children) {
var newElement = ReactElement.cloneElement.apply(this, arguments);
for (var i = 2; i < arguments.length; i++) {
validateChildKeys(arguments[i], newElement.type);
}
validatePropTypes(newElement);
return newElement;
}
};
module.exports = ReactElementValidator;
},{"10":10,"20":20,"21":21,"22":22,"30":30,"7":7,"8":8}],13:[function(_dereq_,module,exports){
/**
* Copyright 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
'use strict';
var warning = _dereq_(30);
function warnNoop(publicInstance, callerName) {
if ("development" !== 'production') {
var constructor = publicInstance.constructor;
"development" !== 'production' ? warning(false, '%s(...): Can only update a mounted or mounting component. ' + 'This usually means you called %s() on an unmounted component. ' + 'This is a no-op. Please check the code for the %s component.', callerName, callerName, constructor && (constructor.displayName || constructor.name) || 'ReactClass') : void 0;
}
}
/**
* This is the abstract API for an update queue.
*/
var ReactNoopUpdateQueue = {
/**
* Checks whether or not this composite component is mounted.
* @param {ReactClass} publicInstance The instance we want to test.
* @return {boolean} True if mounted, false otherwise.
* @protected
* @final
*/
isMounted: function (publicInstance) {
return false;
},
/**
* Enqueue a callback that will be executed after all the pending updates
* have processed.
*
* @param {ReactClass} publicInstance The instance to use as `this` context.
* @param {?function} callback Called after state is updated.
* @internal
*/
enqueueCallback: function (publicInstance, callback) {},
/**
* Forces an update. This should only be invoked when it is known with
* certainty that we are **not** in a DOM transaction.
*
* You may want to call this when you know that some deeper aspect of the
* component's state has changed but `setState` was not called.
*
* This will not invoke `shouldComponentUpdate`, but it will invoke
* `componentWillUpdate` and `componentDidUpdate`.
*
* @param {ReactClass} publicInstance The instance that should rerender.
* @internal
*/
enqueueForceUpdate: function (publicInstance) {
warnNoop(publicInstance, 'forceUpdate');
},
/**
* Replaces all of the state. Always use this or `setState` to mutate state.
* You should treat `this.state` as immutable.
*
* There is no guarantee that `this.state` will be immediately updated, so
* accessing `this.state` after calling this method may return the old value.
*
* @param {ReactClass} publicInstance The instance that should rerender.
* @param {object} completeState Next state.
* @internal
*/
enqueueReplaceState: function (publicInstance, completeState) {
warnNoop(publicInstance, 'replaceState');
},
/**
* Sets a subset of the state. This only exists because _pendingState is
* internal. This provides a merging strategy that is not available to deep
* properties which is confusing. TODO: Expose pendingState or don't use it
* during the merge.
*
* @param {ReactClass} publicInstance The instance that should rerender.
* @param {object} partialState Next partial state to be merged with state.
* @internal
*/
enqueueSetState: function (publicInstance, partialState) {
warnNoop(publicInstance, 'setState');
}
};
module.exports = ReactNoopUpdateQueue;
},{"30":30}],14:[function(_dereq_,module,exports){
/**
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*
*/
'use strict';
var ReactPropTypeLocationNames = {};
if ("development" !== 'production') {
ReactPropTypeLocationNames = {
prop: 'prop',
context: 'context',
childContext: 'child context'
};
}
module.exports = ReactPropTypeLocationNames;
},{}],15:[function(_dereq_,module,exports){
/**
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
'use strict';
var _require = _dereq_(10),
isValidElement = _require.isValidElement;
var factory = _dereq_(33);
module.exports = factory(isValidElement);
},{"10":10,"33":33}],16:[function(_dereq_,module,exports){
/**
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*
*/
'use strict';
var ReactPropTypesSecret = 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED';
module.exports = ReactPropTypesSecret;
},{}],17:[function(_dereq_,module,exports){
/**
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
'use strict';
var _assign = _dereq_(31);
var ReactComponent = _dereq_(6);
var ReactNoopUpdateQueue = _dereq_(13);
var emptyObject = _dereq_(28);
/**
* Base class helpers for the updating state of a component.
*/
function ReactPureComponent(props, context, updater) {
// Duplicated from ReactComponent.
this.props = props;
this.context = context;
this.refs = emptyObject;
// We initialize the default updater but the real one gets injected by the
// renderer.
this.updater = updater || ReactNoopUpdateQueue;
}
function ComponentDummy() {}
ComponentDummy.prototype = ReactComponent.prototype;
ReactPureComponent.prototype = new ComponentDummy();
ReactPureComponent.prototype.constructor = ReactPureComponent;
// Avoid an extra prototype jump for these methods.
_assign(ReactPureComponent.prototype, ReactComponent.prototype);
ReactPureComponent.prototype.isPureReactComponent = true;
module.exports = ReactPureComponent;
},{"13":13,"28":28,"31":31,"6":6}],18:[function(_dereq_,module,exports){
/**
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
'use strict';
var _assign = _dereq_(31);
var React = _dereq_(3);
// `version` will be added here by the React module.
var ReactUMDEntry = _assign(React, {
__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: {
ReactCurrentOwner: _dereq_(8)
}
});
if ("development" !== 'production') {
_assign(ReactUMDEntry.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED, {
// ReactComponentTreeHook should not be included in production.
ReactComponentTreeHook: _dereq_(7),
getNextDebugID: _dereq_(23)
});
}
module.exports = ReactUMDEntry;
},{"23":23,"3":3,"31":31,"7":7,"8":8}],19:[function(_dereq_,module,exports){
/**
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
'use strict';
module.exports = '15.5.4';
},{}],20:[function(_dereq_,module,exports){
/**
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*
*/
'use strict';
var canDefineProperty = false;
if ("development" !== 'production') {
try {
// $FlowFixMe https://github.com/facebook/flow/issues/285
Object.defineProperty({}, 'x', { get: function () {} });
canDefineProperty = true;
} catch (x) {
// IE will fail on defineProperty
}
}
module.exports = canDefineProperty;
},{}],21:[function(_dereq_,module,exports){
(function (process){
/**
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
'use strict';
var _prodInvariant = _dereq_(25);
var ReactPropTypeLocationNames = _dereq_(14);
var ReactPropTypesSecret = _dereq_(16);
var invariant = _dereq_(29);
var warning = _dereq_(30);
var ReactComponentTreeHook;
if (typeof process !== 'undefined' && process.env && "development" === 'test') {
// Temporary hack.
// Inline requires don't work well with Jest:
// https://github.com/facebook/react/issues/7240
// Remove the inline requires when we don't need them anymore:
// https://github.com/facebook/react/pull/7178
ReactComponentTreeHook = _dereq_(7);
}
var loggedTypeFailures = {};
/**
* Assert that the values match with the type specs.
* Error messages are memorized and will only be shown once.
*
* @param {object} typeSpecs Map of name to a ReactPropType
* @param {object} values Runtime values that need to be type-checked
* @param {string} location e.g. "prop", "context", "child context"
* @param {string} componentName Name of the component for error messages.
* @param {?object} element The React element that is being type-checked
* @param {?number} debugID The React component instance that is being type-checked
* @private
*/
function checkReactTypeSpec(typeSpecs, values, location, componentName, element, debugID) {
for (var typeSpecName in typeSpecs) {
if (typeSpecs.hasOwnProperty(typeSpecName)) {
var error;
// Prop type validation may throw. In case they do, we don't want to
// fail the render phase where it didn't fail before. So we log it.
// After these have been cleaned up, we'll let them throw.
try {
// This is intentionally an invariant that gets caught. It's the same
// behavior as without this statement except with a better message.
!(typeof typeSpecs[typeSpecName] === 'function') ? "development" !== 'production' ? invariant(false, '%s: %s type `%s` is invalid; it must be a function, usually from React.PropTypes.', componentName || 'React class', ReactPropTypeLocationNames[location], typeSpecName) : _prodInvariant('84', componentName || 'React class', ReactPropTypeLocationNames[location], typeSpecName) : void 0;
error = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, ReactPropTypesSecret);
} catch (ex) {
error = ex;
}
"development" !== 'production' ? warning(!error || error instanceof Error, '%s: type specification of %s `%s` is invalid; the type checker ' + 'function must return `null` or an `Error` but returned a %s. ' + 'You may have forgotten to pass an argument to the type checker ' + 'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' + 'shape all require an argument).', componentName || 'React class', ReactPropTypeLocationNames[location], typeSpecName, typeof error) : void 0;
if (error instanceof Error && !(error.message in loggedTypeFailures)) {
// Only monitor this failure once because there tends to be a lot of the
// same error.
loggedTypeFailures[error.message] = true;
var componentStackInfo = '';
if ("development" !== 'production') {
if (!ReactComponentTreeHook) {
ReactComponentTreeHook = _dereq_(7);
}
if (debugID !== null) {
componentStackInfo = ReactComponentTreeHook.getStackAddendumByID(debugID);
} else if (element !== null) {
componentStackInfo = ReactComponentTreeHook.getCurrentStackAddendum(element);
}
}
"development" !== 'production' ? warning(false, 'Failed %s type: %s%s', location, error.message, componentStackInfo) : void 0;
}
}
}
}
module.exports = checkReactTypeSpec;
}).call(this,undefined)
},{"14":14,"16":16,"25":25,"29":29,"30":30,"7":7}],22:[function(_dereq_,module,exports){
/**
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*
*/
'use strict';
/* global Symbol */
var ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
var FAUX_ITERATOR_SYMBOL = '@@iterator'; // Before Symbol spec.
/**
* Returns the iterator method function contained on the iterable object.
*
* Be sure to invoke the function with the iterable as context:
*
* var iteratorFn = getIteratorFn(myIterable);
* if (iteratorFn) {
* var iterator = iteratorFn.call(myIterable);
* ...
* }
*
* @param {?object} maybeIterable
* @return {?function}
*/
function getIteratorFn(maybeIterable) {
var iteratorFn = maybeIterable && (ITERATOR_SYMBOL && maybeIterable[ITERATOR_SYMBOL] || maybeIterable[FAUX_ITERATOR_SYMBOL]);
if (typeof iteratorFn === 'function') {
return iteratorFn;
}
}
module.exports = getIteratorFn;
},{}],23:[function(_dereq_,module,exports){
/**
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*
*/
'use strict';
var nextDebugID = 1;
function getNextDebugID() {
return nextDebugID++;
}
module.exports = getNextDebugID;
},{}],24:[function(_dereq_,module,exports){
/**
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
'use strict';
var _prodInvariant = _dereq_(25);
var ReactElement = _dereq_(10);
var invariant = _dereq_(29);
/**
* Returns the first child in a collection of children and verifies that there
* is only one child in the collection.
*
* See https://facebook.github.io/react/docs/top-level-api.html#react.children.only
*
* The current implementation of this function assumes that a single child gets
* passed without a wrapper, but the purpose of this helper function is to
* abstract away the particular structure of children.
*
* @param {?object} children Child collection structure.
* @return {ReactElement} The first and only `ReactElement` contained in the
* structure.
*/
function onlyChild(children) {
!ReactElement.isValidElement(children) ? "development" !== 'production' ? invariant(false, 'React.Children.only expected to receive a single React element child.') : _prodInvariant('143') : void 0;
return children;
}
module.exports = onlyChild;
},{"10":10,"25":25,"29":29}],25:[function(_dereq_,module,exports){
/**
* Copyright (c) 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*
*/
'use strict';
/**
* WARNING: DO NOT manually require this module.
* This is a replacement for `invariant(...)` used by the error code system
* and will _only_ be required by the corresponding babel pass.
* It always throws.
*/
function reactProdInvariant(code) {
var argCount = arguments.length - 1;
var message = 'Minified React error #' + code + '; visit ' + 'http://facebook.github.io/react/docs/error-decoder.html?invariant=' + code;
for (var argIdx = 0; argIdx < argCount; argIdx++) {
message += '&args[]=' + encodeURIComponent(arguments[argIdx + 1]);
}
message += ' for the full message or use the non-minified dev environment' + ' for full errors and additional helpful warnings.';
var error = new Error(message);
error.name = 'Invariant Violation';
error.framesToPop = 1; // we don't care about reactProdInvariant's own frame
throw error;
}
module.exports = reactProdInvariant;
},{}],26:[function(_dereq_,module,exports){
/**
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
'use strict';
var _prodInvariant = _dereq_(25);
var ReactCurrentOwner = _dereq_(8);
var REACT_ELEMENT_TYPE = _dereq_(11);
var getIteratorFn = _dereq_(22);
var invariant = _dereq_(29);
var KeyEscapeUtils = _dereq_(1);
var warning = _dereq_(30);
var SEPARATOR = '.';
var SUBSEPARATOR = ':';
/**
* This is inlined from ReactElement since this file is shared between
* isomorphic and renderers. We could extract this to a
*
*/
/**
* TODO: Test that a single child and an array with one item have the same key
* pattern.
*/
var didWarnAboutMaps = false;
/**
* Generate a key string that identifies a component within a set.
*
* @param {*} component A component that could contain a manual key.
* @param {number} index Index that is used if a manual key is not provided.
* @return {string}
*/
function getComponentKey(component, index) {
// Do some typechecking here since we call this blindly. We want to ensure
// that we don't block potential future ES APIs.
if (component && typeof component === 'object' && component.key != null) {
// Explicit key
return KeyEscapeUtils.escape(component.key);
}
// Implicit key determined by the index in the set
return index.toString(36);
}
/**
* @param {?*} children Children tree container.
* @param {!string} nameSoFar Name of the key path so far.
* @param {!function} callback Callback to invoke with each child found.
* @param {?*} traverseContext Used to pass information throughout the traversal
* process.
* @return {!number} The number of children in this subtree.
*/
function traverseAllChildrenImpl(children, nameSoFar, callback, traverseContext) {
var type = typeof children;
if (type === 'undefined' || type === 'boolean') {
// All of the above are perceived as null.
children = null;
}
if (children === null || type === 'string' || type === 'number' ||
// The following is inlined from ReactElement. This means we can optimize
// some checks. React Fiber also inlines this logic for similar purposes.
type === 'object' && children.$$typeof === REACT_ELEMENT_TYPE) {
callback(traverseContext, children,
// If it's the only child, treat the name as if it was wrapped in an array
// so that it's consistent if the number of children grows.
nameSoFar === '' ? SEPARATOR + getComponentKey(children, 0) : nameSoFar);
return 1;
}
var child;
var nextName;
var subtreeCount = 0; // Count of children found in the current subtree.
var nextNamePrefix = nameSoFar === '' ? SEPARATOR : nameSoFar + SUBSEPARATOR;
if (Array.isArray(children)) {
for (var i = 0; i < children.length; i++) {
child = children[i];
nextName = nextNamePrefix + getComponentKey(child, i);
subtreeCount += traverseAllChildrenImpl(child, nextName, callback, traverseContext);
}
} else {
var iteratorFn = getIteratorFn(children);
if (iteratorFn) {
var iterator = iteratorFn.call(children);
var step;
if (iteratorFn !== children.entries) {
var ii = 0;
while (!(step = iterator.next()).done) {
child = step.value;
nextName = nextNamePrefix + getComponentKey(child, ii++);
subtreeCount += traverseAllChildrenImpl(child, nextName, callback, traverseContext);
}
} else {
if ("development" !== 'production') {
var mapsAsChildrenAddendum = '';
if (ReactCurrentOwner.current) {
var mapsAsChildrenOwnerName = ReactCurrentOwner.current.getName();
if (mapsAsChildrenOwnerName) {
mapsAsChildrenAddendum = ' Check the render method of `' + mapsAsChildrenOwnerName + '`.';
}
}
"development" !== 'production' ? warning(didWarnAboutMaps, 'Using Maps as children is not yet fully supported. It is an ' + 'experimental feature that might be removed. Convert it to a ' + 'sequence / iterable of keyed ReactElements instead.%s', mapsAsChildrenAddendum) : void 0;
didWarnAboutMaps = true;
}
// Iterator will provide entry [k,v] tuples rather than values.
while (!(step = iterator.next()).done) {
var entry = step.value;
if (entry) {
child = entry[1];
nextName = nextNamePrefix + KeyEscapeUtils.escape(entry[0]) + SUBSEPARATOR + getComponentKey(child, 0);
subtreeCount += traverseAllChildrenImpl(child, nextName, callback, traverseContext);
}
}
}
} else if (type === 'object') {
var addendum = '';
if ("development" !== 'production') {
addendum = ' If you meant to render a collection of children, use an array ' + 'instead or wrap the object using createFragment(object) from the ' + 'React add-ons.';
if (children._isReactElement) {
addendum = ' It looks like you\'re using an element created by a different ' + 'version of React. Make sure to use only one copy of React.';
}
if (ReactCurrentOwner.current) {
var name = ReactCurrentOwner.current.getName();
if (name) {
addendum += ' Check the render method of `' + name + '`.';
}
}
}
var childrenString = String(children);
!false ? "development" !== 'production' ? invariant(false, 'Objects are not valid as a React child (found: %s).%s', childrenString === '[object Object]' ? 'object with keys {' + Object.keys(children).join(', ') + '}' : childrenString, addendum) : _prodInvariant('31', childrenString === '[object Object]' ? 'object with keys {' + Object.keys(children).join(', ') + '}' : childrenString, addendum) : void 0;
}
}
return subtreeCount;
}
/**
* Traverses children that are typically specified as `props.children`, but
* might also be specified through attributes:
*
* - `traverseAllChildren(this.props.children, ...)`
* - `traverseAllChildren(this.props.leftPanelChildren, ...)`
*
* The `traverseContext` is an optional argument that is passed through the
* entire traversal. It can be used to store accumulations or anything else that
* the callback might find relevant.
*
* @param {?*} children Children tree object.
* @param {!function} callback To invoke upon traversing each child.
* @param {?*} traverseContext Context for traversal.
* @return {!number} The number of children in this subtree.
*/
function traverseAllChildren(children, callback, traverseContext) {
if (children == null) {
return 0;
}
return traverseAllChildrenImpl(children, '', callback, traverseContext);
}
module.exports = traverseAllChildren;
},{"1":1,"11":11,"22":22,"25":25,"29":29,"30":30,"8":8}],27:[function(_dereq_,module,exports){
"use strict";
/**
* Copyright (c) 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*
*/
function makeEmptyFunction(arg) {
return function () {
return arg;
};
}
/**
* This function accepts and discards inputs; it has no side effects. This is
* primarily useful idiomatically for overridable function endpoints which
* always need to be callable, since JS lacks a null-call idiom ala Cocoa.
*/
var emptyFunction = function emptyFunction() {};
emptyFunction.thatReturns = makeEmptyFunction;
emptyFunction.thatReturnsFalse = makeEmptyFunction(false);
emptyFunction.thatReturnsTrue = makeEmptyFunction(true);
emptyFunction.thatReturnsNull = makeEmptyFunction(null);
emptyFunction.thatReturnsThis = function () {
return this;
};
emptyFunction.thatReturnsArgument = function (arg) {
return arg;
};
module.exports = emptyFunction;
},{}],28:[function(_dereq_,module,exports){
/**
* Copyright (c) 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
'use strict';
var emptyObject = {};
if ("development" !== 'production') {
Object.freeze(emptyObject);
}
module.exports = emptyObject;
},{}],29:[function(_dereq_,module,exports){
/**
* Copyright (c) 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
'use strict';
/**
* Use invariant() to assert state which your program assumes to be true.
*
* Provide sprintf-style format (only %s is supported) and arguments
* to provide information about what broke and what you were
* expecting.
*
* The invariant message will be stripped in production, but the invariant
* will remain to ensure logic does not differ in production.
*/
var validateFormat = function validateFormat(format) {};
if ("development" !== 'production') {
validateFormat = function validateFormat(format) {
if (format === undefined) {
throw new Error('invariant requires an error message argument');
}
};
}
function invariant(condition, format, a, b, c, d, e, f) {
validateFormat(format);
if (!condition) {
var error;
if (format === undefined) {
error = new Error('Minified exception occurred; use the non-minified dev environment ' + 'for the full error message and additional helpful warnings.');
} else {
var args = [a, b, c, d, e, f];
var argIndex = 0;
error = new Error(format.replace(/%s/g, function () {
return args[argIndex++];
}));
error.name = 'Invariant Violation';
}
error.framesToPop = 1; // we don't care about invariant's own frame
throw error;
}
}
module.exports = invariant;
},{}],30:[function(_dereq_,module,exports){
/**
* Copyright 2014-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
'use strict';
var emptyFunction = _dereq_(27);
/**
* Similar to invariant but only logs a warning if the condition is not met.
* This can be used to log issues in development environments in critical
* paths. Removing the logging code for production environments will keep the
* same logic and follow the same code paths.
*/
var warning = emptyFunction;
if ("development" !== 'production') {
(function () {
var printWarning = function printWarning(format) {
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
var argIndex = 0;
var message = 'Warning: ' + format.replace(/%s/g, function () {
return args[argIndex++];
});
if (typeof console !== 'undefined') {
console.error(message);
}
try {
// --- Welcome to debugging React ---
// This error was thrown as a convenience so that you can use this stack
// to find the callsite that caused this warning to fire.
throw new Error(message);
} catch (x) {}
};
warning = function warning(condition, format) {
if (format === undefined) {
throw new Error('`warning(condition, format, ...args)` requires a warning ' + 'message argument');
}
if (format.indexOf('Failed Composite propType: ') === 0) {
return; // Ignore CompositeComponent proptype check.
}
if (!condition) {
for (var _len2 = arguments.length, args = Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
args[_key2 - 2] = arguments[_key2];
}
printWarning.apply(undefined, [format].concat(args));
}
};
})();
}
module.exports = warning;
},{"27":27}],31:[function(_dereq_,module,exports){
/*
object-assign
(c) Sindre Sorhus
@license MIT
*/
'use strict';
/* eslint-disable no-unused-vars */
var getOwnPropertySymbols = Object.getOwnPropertySymbols;
var hasOwnProperty = Object.prototype.hasOwnProperty;
var propIsEnumerable = Object.prototype.propertyIsEnumerable;
function toObject(val) {
if (val === null || val === undefined) {
throw new TypeError('Object.assign cannot be called with null or undefined');
}
return Object(val);
}
function shouldUseNative() {
try {
if (!Object.assign) {
return false;
}
// Detect buggy property enumeration order in older V8 versions.
// https://bugs.chromium.org/p/v8/issues/detail?id=4118
var test1 = new String('abc'); // eslint-disable-line no-new-wrappers
test1[5] = 'de';
if (Object.getOwnPropertyNames(test1)[0] === '5') {
return false;
}
// https://bugs.chromium.org/p/v8/issues/detail?id=3056
var test2 = {};
for (var i = 0; i < 10; i++) {
test2['_' + String.fromCharCode(i)] = i;
}
var order2 = Object.getOwnPropertyNames(test2).map(function (n) {
return test2[n];
});
if (order2.join('') !== '0123456789') {
return false;
}
// https://bugs.chromium.org/p/v8/issues/detail?id=3056
var test3 = {};
'abcdefghijklmnopqrst'.split('').forEach(function (letter) {
test3[letter] = letter;
});
if (Object.keys(Object.assign({}, test3)).join('') !==
'abcdefghijklmnopqrst') {
return false;
}
return true;
} catch (err) {
// We don't expect any of the above to throw, but better to be safe.
return false;
}
}
module.exports = shouldUseNative() ? Object.assign : function (target, source) {
var from;
var to = toObject(target);
var symbols;
for (var s = 1; s < arguments.length; s++) {
from = Object(arguments[s]);
for (var key in from) {
if (hasOwnProperty.call(from, key)) {
to[key] = from[key];
}
}
if (getOwnPropertySymbols) {
symbols = getOwnPropertySymbols(from);
for (var i = 0; i < symbols.length; i++) {
if (propIsEnumerable.call(from, symbols[i])) {
to[symbols[i]] = from[symbols[i]];
}
}
}
}
return to;
};
},{}],32:[function(_dereq_,module,exports){
/**
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
'use strict';
if ("development" !== 'production') {
var invariant = _dereq_(29);
var warning = _dereq_(30);
var ReactPropTypesSecret = _dereq_(35);
var loggedTypeFailures = {};
}
/**
* Assert that the values match with the type specs.
* Error messages are memorized and will only be shown once.
*
* @param {object} typeSpecs Map of name to a ReactPropType
* @param {object} values Runtime values that need to be type-checked
* @param {string} location e.g. "prop", "context", "child context"
* @param {string} componentName Name of the component for error messages.
* @param {?Function} getStack Returns the component stack.
* @private
*/
function checkPropTypes(typeSpecs, values, location, componentName, getStack) {
if ("development" !== 'production') {
for (var typeSpecName in typeSpecs) {
if (typeSpecs.hasOwnProperty(typeSpecName)) {
var error;
// Prop type validation may throw. In case they do, we don't want to
// fail the render phase where it didn't fail before. So we log it.
// After these have been cleaned up, we'll let them throw.
try {
// This is intentionally an invariant that gets caught. It's the same
// behavior as without this statement except with a better message.
invariant(typeof typeSpecs[typeSpecName] === 'function', '%s: %s type `%s` is invalid; it must be a function, usually from ' + 'React.PropTypes.', componentName || 'React class', location, typeSpecName);
error = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, ReactPropTypesSecret);
} catch (ex) {
error = ex;
}
warning(!error || error instanceof Error, '%s: type specification of %s `%s` is invalid; the type checker ' + 'function must return `null` or an `Error` but returned a %s. ' + 'You may have forgotten to pass an argument to the type checker ' + 'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' + 'shape all require an argument).', componentName || 'React class', location, typeSpecName, typeof error);
if (error instanceof Error && !(error.message in loggedTypeFailures)) {
// Only monitor this failure once because there tends to be a lot of the
// same error.
loggedTypeFailures[error.message] = true;
var stack = getStack ? getStack() : '';
warning(false, 'Failed %s type: %s%s', location, error.message, stack != null ? stack : '');
}
}
}
}
}
module.exports = checkPropTypes;
},{"29":29,"30":30,"35":35}],33:[function(_dereq_,module,exports){
/**
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
'use strict';
// React 15.5 references this module, and assumes PropTypes are still callable in production.
// Therefore we re-export development-only version with all the PropTypes checks here.
// However if one is migrating to the `prop-types` npm library, they will go through the
// `index.js` entry point, and it will branch depending on the environment.
var factory = _dereq_(34);
module.exports = function(isValidElement) {
// It is still allowed in 15.5.
var throwOnDirectAccess = false;
return factory(isValidElement, throwOnDirectAccess);
};
},{"34":34}],34:[function(_dereq_,module,exports){
/**
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
'use strict';
var emptyFunction = _dereq_(27);
var invariant = _dereq_(29);
var warning = _dereq_(30);
var ReactPropTypesSecret = _dereq_(35);
var checkPropTypes = _dereq_(32);
module.exports = function(isValidElement, throwOnDirectAccess) {
/* global Symbol */
var ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
var FAUX_ITERATOR_SYMBOL = '@@iterator'; // Before Symbol spec.
/**
* Returns the iterator method function contained on the iterable object.
*
* Be sure to invoke the function with the iterable as context:
*
* var iteratorFn = getIteratorFn(myIterable);
* if (iteratorFn) {
* var iterator = iteratorFn.call(myIterable);
* ...
* }
*
* @param {?object} maybeIterable
* @return {?function}
*/
function getIteratorFn(maybeIterable) {
var iteratorFn = maybeIterable && (ITERATOR_SYMBOL && maybeIterable[ITERATOR_SYMBOL] || maybeIterable[FAUX_ITERATOR_SYMBOL]);
if (typeof iteratorFn === 'function') {
return iteratorFn;
}
}
/**
* Collection of methods that allow declaration and validation of props that are
* supplied to React components. Example usage:
*
* var Props = require('ReactPropTypes');
* var MyArticle = React.createClass({
* propTypes: {
* // An optional string prop named "description".
* description: Props.string,
*
* // A required enum prop named "category".
* category: Props.oneOf(['News','Photos']).isRequired,
*
* // A prop named "dialog" that requires an instance of Dialog.
* dialog: Props.instanceOf(Dialog).isRequired
* },
* render: function() { ... }
* });
*
* A more formal specification of how these methods are used:
*
* type := array|bool|func|object|number|string|oneOf([...])|instanceOf(...)
* decl := ReactPropTypes.{type}(.isRequired)?
*
* Each and every declaration produces a function with the same signature. This
* allows the creation of custom validation functions. For example:
*
* var MyLink = React.createClass({
* propTypes: {
* // An optional string or URI prop named "href".
* href: function(props, propName, componentName) {
* var propValue = props[propName];
* if (propValue != null && typeof propValue !== 'string' &&
* !(propValue instanceof URI)) {
* return new Error(
* 'Expected a string or an URI for ' + propName + ' in ' +
* componentName
* );
* }
* }
* },
* render: function() {...}
* });
*
* @internal
*/
var ANONYMOUS = '<>';
// Important!
// Keep this list in sync with production version in `./factoryWithThrowingShims.js`.
var ReactPropTypes = {
array: createPrimitiveTypeChecker('array'),
bool: createPrimitiveTypeChecker('boolean'),
func: createPrimitiveTypeChecker('function'),
number: createPrimitiveTypeChecker('number'),
object: createPrimitiveTypeChecker('object'),
string: createPrimitiveTypeChecker('string'),
symbol: createPrimitiveTypeChecker('symbol'),
any: createAnyTypeChecker(),
arrayOf: createArrayOfTypeChecker,
element: createElementTypeChecker(),
instanceOf: createInstanceTypeChecker,
node: createNodeChecker(),
objectOf: createObjectOfTypeChecker,
oneOf: createEnumTypeChecker,
oneOfType: createUnionTypeChecker,
shape: createShapeTypeChecker
};
/**
* inlined Object.is polyfill to avoid requiring consumers ship their own
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
*/
/*eslint-disable no-self-compare*/
function is(x, y) {
// SameValue algorithm
if (x === y) {
// Steps 1-5, 7-10
// Steps 6.b-6.e: +0 != -0
return x !== 0 || 1 / x === 1 / y;
} else {
// Step 6.a: NaN == NaN
return x !== x && y !== y;
}
}
/*eslint-enable no-self-compare*/
/**
* We use an Error-like object for backward compatibility as people may call
* PropTypes directly and inspect their output. However, we don't use real
* Errors anymore. We don't inspect their stack anyway, and creating them
* is prohibitively expensive if they are created too often, such as what
* happens in oneOfType() for any type before the one that matched.
*/
function PropTypeError(message) {
this.message = message;
this.stack = '';
}
// Make `instanceof Error` still work for returned errors.
PropTypeError.prototype = Error.prototype;
function createChainableTypeChecker(validate) {
if ("development" !== 'production') {
var manualPropTypeCallCache = {};
}
function checkType(isRequired, props, propName, componentName, location, propFullName, secret) {
componentName = componentName || ANONYMOUS;
propFullName = propFullName || propName;
if (secret !== ReactPropTypesSecret) {
if (throwOnDirectAccess) {
// New behavior only for users of `prop-types` package
invariant(
false,
'Calling PropTypes validators directly is not supported by the `prop-types` package. ' +
'Use `PropTypes.checkPropTypes()` to call them. ' +
'Read more at http://fb.me/use-check-prop-types'
);
} else if ("development" !== 'production' && typeof console !== 'undefined') {
// Old behavior for people using React.PropTypes
var cacheKey = componentName + ':' + propName;
if (!manualPropTypeCallCache[cacheKey]) {
warning(
false,
'You are manually calling a React.PropTypes validation ' +
'function for the `%s` prop on `%s`. This is deprecated ' +
'and will throw in the standalone `prop-types` package. ' +
'You may be seeing this warning due to a third-party PropTypes ' +
'library. See https://fb.me/react-warning-dont-call-proptypes ' + 'for details.',
propFullName,
componentName
);
manualPropTypeCallCache[cacheKey] = true;
}
}
}
if (props[propName] == null) {
if (isRequired) {
if (props[propName] === null) {
return new PropTypeError('The ' + location + ' `' + propFullName + '` is marked as required ' + ('in `' + componentName + '`, but its value is `null`.'));
}
return new PropTypeError('The ' + location + ' `' + propFullName + '` is marked as required in ' + ('`' + componentName + '`, but its value is `undefined`.'));
}
return null;
} else {
return validate(props, propName, componentName, location, propFullName);
}
}
var chainedCheckType = checkType.bind(null, false);
chainedCheckType.isRequired = checkType.bind(null, true);
return chainedCheckType;
}
function createPrimitiveTypeChecker(expectedType) {
function validate(props, propName, componentName, location, propFullName, secret) {
var propValue = props[propName];
var propType = getPropType(propValue);
if (propType !== expectedType) {
// `propValue` being instance of, say, date/regexp, pass the 'object'
// check, but we can offer a more precise error message here rather than
// 'of type `object`'.
var preciseType = getPreciseType(propValue);
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + preciseType + '` supplied to `' + componentName + '`, expected ') + ('`' + expectedType + '`.'));
}
return null;
}
return createChainableTypeChecker(validate);
}
function createAnyTypeChecker() {
return createChainableTypeChecker(emptyFunction.thatReturnsNull);
}
function createArrayOfTypeChecker(typeChecker) {
function validate(props, propName, componentName, location, propFullName) {
if (typeof typeChecker !== 'function') {
return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside arrayOf.');
}
var propValue = props[propName];
if (!Array.isArray(propValue)) {
var propType = getPropType(propValue);
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an array.'));
}
for (var i = 0; i < propValue.length; i++) {
var error = typeChecker(propValue, i, componentName, location, propFullName + '[' + i + ']', ReactPropTypesSecret);
if (error instanceof Error) {
return error;
}
}
return null;
}
return createChainableTypeChecker(validate);
}
function createElementTypeChecker() {
function validate(props, propName, componentName, location, propFullName) {
var propValue = props[propName];
if (!isValidElement(propValue)) {
var propType = getPropType(propValue);
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected a single ReactElement.'));
}
return null;
}
return createChainableTypeChecker(validate);
}
function createInstanceTypeChecker(expectedClass) {
function validate(props, propName, componentName, location, propFullName) {
if (!(props[propName] instanceof expectedClass)) {
var expectedClassName = expectedClass.name || ANONYMOUS;
var actualClassName = getClassName(props[propName]);
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + actualClassName + '` supplied to `' + componentName + '`, expected ') + ('instance of `' + expectedClassName + '`.'));
}
return null;
}
return createChainableTypeChecker(validate);
}
function createEnumTypeChecker(expectedValues) {
if (!Array.isArray(expectedValues)) {
"development" !== 'production' ? warning(false, 'Invalid argument supplied to oneOf, expected an instance of array.') : void 0;
return emptyFunction.thatReturnsNull;
}
function validate(props, propName, componentName, location, propFullName) {
var propValue = props[propName];
for (var i = 0; i < expectedValues.length; i++) {
if (is(propValue, expectedValues[i])) {
return null;
}
}
var valuesString = JSON.stringify(expectedValues);
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of value `' + propValue + '` ' + ('supplied to `' + componentName + '`, expected one of ' + valuesString + '.'));
}
return createChainableTypeChecker(validate);
}
function createObjectOfTypeChecker(typeChecker) {
function validate(props, propName, componentName, location, propFullName) {
if (typeof typeChecker !== 'function') {
return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside objectOf.');
}
var propValue = props[propName];
var propType = getPropType(propValue);
if (propType !== 'object') {
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an object.'));
}
for (var key in propValue) {
if (propValue.hasOwnProperty(key)) {
var error = typeChecker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret);
if (error instanceof Error) {
return error;
}
}
}
return null;
}
return createChainableTypeChecker(validate);
}
function createUnionTypeChecker(arrayOfTypeCheckers) {
if (!Array.isArray(arrayOfTypeCheckers)) {
"development" !== 'production' ? warning(false, 'Invalid argument supplied to oneOfType, expected an instance of array.') : void 0;
return emptyFunction.thatReturnsNull;
}
function validate(props, propName, componentName, location, propFullName) {
for (var i = 0; i < arrayOfTypeCheckers.length; i++) {
var checker = arrayOfTypeCheckers[i];
if (checker(props, propName, componentName, location, propFullName, ReactPropTypesSecret) == null) {
return null;
}
}
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`.'));
}
return createChainableTypeChecker(validate);
}
function createNodeChecker() {
function validate(props, propName, componentName, location, propFullName) {
if (!isNode(props[propName])) {
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`, expected a ReactNode.'));
}
return null;
}
return createChainableTypeChecker(validate);
}
function createShapeTypeChecker(shapeTypes) {
function validate(props, propName, componentName, location, propFullName) {
var propValue = props[propName];
var propType = getPropType(propValue);
if (propType !== 'object') {
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type `' + propType + '` ' + ('supplied to `' + componentName + '`, expected `object`.'));
}
for (var key in shapeTypes) {
var checker = shapeTypes[key];
if (!checker) {
continue;
}
var error = checker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret);
if (error) {
return error;
}
}
return null;
}
return createChainableTypeChecker(validate);
}
function isNode(propValue) {
switch (typeof propValue) {
case 'number':
case 'string':
case 'undefined':
return true;
case 'boolean':
return !propValue;
case 'object':
if (Array.isArray(propValue)) {
return propValue.every(isNode);
}
if (propValue === null || isValidElement(propValue)) {
return true;
}
var iteratorFn = getIteratorFn(propValue);
if (iteratorFn) {
var iterator = iteratorFn.call(propValue);
var step;
if (iteratorFn !== propValue.entries) {
while (!(step = iterator.next()).done) {
if (!isNode(step.value)) {
return false;
}
}
} else {
// Iterator will provide entry [k,v] tuples rather than values.
while (!(step = iterator.next()).done) {
var entry = step.value;
if (entry) {
if (!isNode(entry[1])) {
return false;
}
}
}
}
} else {
return false;
}
return true;
default:
return false;
}
}
function isSymbol(propType, propValue) {
// Native Symbol.
if (propType === 'symbol') {
return true;
}
// 19.4.3.5 Symbol.prototype[@@toStringTag] === 'Symbol'
if (propValue['@@toStringTag'] === 'Symbol') {
return true;
}
// Fallback for non-spec compliant Symbols which are polyfilled.
if (typeof Symbol === 'function' && propValue instanceof Symbol) {
return true;
}
return false;
}
// Equivalent of `typeof` but with special handling for array and regexp.
function getPropType(propValue) {
var propType = typeof propValue;
if (Array.isArray(propValue)) {
return 'array';
}
if (propValue instanceof RegExp) {
// Old webkits (at least until Android 4.0) return 'function' rather than
// 'object' for typeof a RegExp. We'll normalize this here so that /bla/
// passes PropTypes.object.
return 'object';
}
if (isSymbol(propType, propValue)) {
return 'symbol';
}
return propType;
}
// This handles more types than `getPropType`. Only used for error messages.
// See `createPrimitiveTypeChecker`.
function getPreciseType(propValue) {
var propType = getPropType(propValue);
if (propType === 'object') {
if (propValue instanceof Date) {
return 'date';
} else if (propValue instanceof RegExp) {
return 'regexp';
}
}
return propType;
}
// Returns class name of the object, if any.
function getClassName(propValue) {
if (!propValue.constructor || !propValue.constructor.name) {
return ANONYMOUS;
}
return propValue.constructor.name;
}
ReactPropTypes.checkPropTypes = checkPropTypes;
ReactPropTypes.PropTypes = ReactPropTypes;
return ReactPropTypes;
};
},{"27":27,"29":29,"30":30,"32":32,"35":35}],35:[function(_dereq_,module,exports){
/**
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
'use strict';
var ReactPropTypesSecret = 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED';
module.exports = ReactPropTypesSecret;
},{}]},{},[18])(18)
});
;;
;(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory(require("react"), require("redux"));
else if(typeof define === 'function' && define.amd)
define(["react", "redux"], factory);
else if(typeof exports === 'object')
exports["ReactRedux"] = factory(require("react"), require("redux"));
else
root["ReactRedux"] = factory(root["React"], root["Redux"]);
})(this, function(__WEBPACK_EXTERNAL_MODULE_12__, __WEBPACK_EXTERNAL_MODULE_35__) {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/ // Flag the module as loaded
/******/ module.loaded = true;
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
exports.__esModule = true;
exports.connect = exports.connectAdvanced = exports.Provider = undefined;
var _Provider = __webpack_require__(13);
var _Provider2 = _interopRequireDefault(_Provider);
var _connectAdvanced = __webpack_require__(2);
var _connectAdvanced2 = _interopRequireDefault(_connectAdvanced);
var _connect = __webpack_require__(14);
var _connect2 = _interopRequireDefault(_connect);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
exports.Provider = _Provider2.default;
exports.connectAdvanced = _connectAdvanced2.default;
exports.connect = _connect2.default;
/***/ },
/* 1 */
/***/ function(module, exports) {
'use strict';
exports.__esModule = true;
exports.default = warning;
/**
* Prints a warning in the console if it exists.
*
* @param {String} message The warning message.
* @returns {void}
*/
function warning(message) {
/* eslint-disable no-console */
if (typeof console !== 'undefined' && typeof console.error === 'function') {
console.error(message);
}
/* eslint-enable no-console */
try {
// This error was thrown as a convenience so that if you enable
// "break on all exceptions" in your console,
// it would pause the execution at this line.
throw new Error(message);
/* eslint-disable no-empty */
} catch (e) {}
/* eslint-enable no-empty */
}
/***/ },
/* 2 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
exports.__esModule = true;
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
exports.default = connectAdvanced;
var _hoistNonReactStatics = __webpack_require__(22);
var _hoistNonReactStatics2 = _interopRequireDefault(_hoistNonReactStatics);
var _invariant = __webpack_require__(23);
var _invariant2 = _interopRequireDefault(_invariant);
var _react = __webpack_require__(12);
var _Subscription = __webpack_require__(20);
var _Subscription2 = _interopRequireDefault(_Subscription);
var _PropTypes = __webpack_require__(4);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
var hotReloadingVersion = 0;
var dummyState = {};
function noop() {}
function makeSelectorStateful(sourceSelector, store) {
// wrap the selector in an object that tracks its results between runs.
var selector = {
run: function runComponentSelector(props) {
try {
var nextProps = sourceSelector(store.getState(), props);
if (nextProps !== selector.props || selector.error) {
selector.shouldComponentUpdate = true;
selector.props = nextProps;
selector.error = null;
}
} catch (error) {
selector.shouldComponentUpdate = true;
selector.error = error;
}
}
};
return selector;
}
function connectAdvanced(
/*
selectorFactory is a func that is responsible for returning the selector function used to
compute new props from state, props, and dispatch. For example:
export default connectAdvanced((dispatch, options) => (state, props) => ({
thing: state.things[props.thingId],
saveThing: fields => dispatch(actionCreators.saveThing(props.thingId, fields)),
}))(YourComponent)
Access to dispatch is provided to the factory so selectorFactories can bind actionCreators
outside of their selector as an optimization. Options passed to connectAdvanced are passed to
the selectorFactory, along with displayName and WrappedComponent, as the second argument.
Note that selectorFactory is responsible for all caching/memoization of inbound and outbound
props. Do not use connectAdvanced directly without memoizing results between calls to your
selector, otherwise the Connect component will re-render on every state or props change.
*/
selectorFactory) {
var _contextTypes, _childContextTypes;
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
_ref$getDisplayName = _ref.getDisplayName,
getDisplayName = _ref$getDisplayName === undefined ? function (name) {
return 'ConnectAdvanced(' + name + ')';
} : _ref$getDisplayName,
_ref$methodName = _ref.methodName,
methodName = _ref$methodName === undefined ? 'connectAdvanced' : _ref$methodName,
_ref$renderCountProp = _ref.renderCountProp,
renderCountProp = _ref$renderCountProp === undefined ? undefined : _ref$renderCountProp,
_ref$shouldHandleStat = _ref.shouldHandleStateChanges,
shouldHandleStateChanges = _ref$shouldHandleStat === undefined ? true : _ref$shouldHandleStat,
_ref$storeKey = _ref.storeKey,
storeKey = _ref$storeKey === undefined ? 'store' : _ref$storeKey,
_ref$withRef = _ref.withRef,
withRef = _ref$withRef === undefined ? false : _ref$withRef,
connectOptions = _objectWithoutProperties(_ref, ['getDisplayName', 'methodName', 'renderCountProp', 'shouldHandleStateChanges', 'storeKey', 'withRef']);
var subscriptionKey = storeKey + 'Subscription';
var version = hotReloadingVersion++;
var contextTypes = (_contextTypes = {}, _contextTypes[storeKey] = _PropTypes.storeShape, _contextTypes[subscriptionKey] = _PropTypes.subscriptionShape, _contextTypes);
var childContextTypes = (_childContextTypes = {}, _childContextTypes[subscriptionKey] = _PropTypes.subscriptionShape, _childContextTypes);
return function wrapWithConnect(WrappedComponent) {
(0, _invariant2.default)(typeof WrappedComponent == 'function', 'You must pass a component to the function returned by ' + ('connect. Instead received ' + JSON.stringify(WrappedComponent)));
var wrappedComponentName = WrappedComponent.displayName || WrappedComponent.name || 'Component';
var displayName = getDisplayName(wrappedComponentName);
var selectorFactoryOptions = _extends({}, connectOptions, {
getDisplayName: getDisplayName,
methodName: methodName,
renderCountProp: renderCountProp,
shouldHandleStateChanges: shouldHandleStateChanges,
storeKey: storeKey,
withRef: withRef,
displayName: displayName,
wrappedComponentName: wrappedComponentName,
WrappedComponent: WrappedComponent
});
var Connect = function (_Component) {
_inherits(Connect, _Component);
function Connect(props, context) {
_classCallCheck(this, Connect);
var _this = _possibleConstructorReturn(this, _Component.call(this, props, context));
_this.version = version;
_this.state = {};
_this.renderCount = 0;
_this.store = props[storeKey] || context[storeKey];
_this.propsMode = Boolean(props[storeKey]);
_this.setWrappedInstance = _this.setWrappedInstance.bind(_this);
(0, _invariant2.default)(_this.store, 'Could not find "' + storeKey + '" in either the context or props of ' + ('"' + displayName + '". Either wrap the root component in a , ') + ('or explicitly pass "' + storeKey + '" as a prop to "' + displayName + '".'));
_this.initSelector();
_this.initSubscription();
return _this;
}
Connect.prototype.getChildContext = function getChildContext() {
var _ref2;
// If this component received store from props, its subscription should be transparent
// to any descendants receiving store+subscription from context; it passes along
// subscription passed to it. Otherwise, it shadows the parent subscription, which allows
// Connect to control ordering of notifications to flow top-down.
var subscription = this.propsMode ? null : this.subscription;
return _ref2 = {}, _ref2[subscriptionKey] = subscription || this.context[subscriptionKey], _ref2;
};
Connect.prototype.componentDidMount = function componentDidMount() {
if (!shouldHandleStateChanges) return;
// componentWillMount fires during server side rendering, but componentDidMount and
// componentWillUnmount do not. Because of this, trySubscribe happens during ...didMount.
// Otherwise, unsubscription would never take place during SSR, causing a memory leak.
// To handle the case where a child component may have triggered a state change by
// dispatching an action in its componentWillMount, we have to re-run the select and maybe
// re-render.
this.subscription.trySubscribe();
this.selector.run(this.props);
if (this.selector.shouldComponentUpdate) this.forceUpdate();
};
Connect.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) {
this.selector.run(nextProps);
};
Connect.prototype.shouldComponentUpdate = function shouldComponentUpdate() {
return this.selector.shouldComponentUpdate;
};
Connect.prototype.componentWillUnmount = function componentWillUnmount() {
if (this.subscription) this.subscription.tryUnsubscribe();
this.subscription = null;
this.notifyNestedSubs = noop;
this.store = null;
this.selector.run = noop;
this.selector.shouldComponentUpdate = false;
};
Connect.prototype.getWrappedInstance = function getWrappedInstance() {
(0, _invariant2.default)(withRef, 'To access the wrapped instance, you need to specify ' + ('{ withRef: true } in the options argument of the ' + methodName + '() call.'));
return this.wrappedInstance;
};
Connect.prototype.setWrappedInstance = function setWrappedInstance(ref) {
this.wrappedInstance = ref;
};
Connect.prototype.initSelector = function initSelector() {
var sourceSelector = selectorFactory(this.store.dispatch, selectorFactoryOptions);
this.selector = makeSelectorStateful(sourceSelector, this.store);
this.selector.run(this.props);
};
Connect.prototype.initSubscription = function initSubscription() {
if (!shouldHandleStateChanges) return;
// parentSub's source should match where store came from: props vs. context. A component
// connected to the store via props shouldn't use subscription from context, or vice versa.
var parentSub = (this.propsMode ? this.props : this.context)[subscriptionKey];
this.subscription = new _Subscription2.default(this.store, parentSub, this.onStateChange.bind(this));
// `notifyNestedSubs` is duplicated to handle the case where the component is unmounted in
// the middle of the notification loop, where `this.subscription` will then be null. An
// extra null check every change can be avoided by copying the method onto `this` and then
// replacing it with a no-op on unmount. This can probably be avoided if Subscription's
// listeners logic is changed to not call listeners that have been unsubscribed in the
// middle of the notification loop.
this.notifyNestedSubs = this.subscription.notifyNestedSubs.bind(this.subscription);
};
Connect.prototype.onStateChange = function onStateChange() {
this.selector.run(this.props);
if (!this.selector.shouldComponentUpdate) {
this.notifyNestedSubs();
} else {
this.componentDidUpdate = this.notifyNestedSubsOnComponentDidUpdate;
this.setState(dummyState);
}
};
Connect.prototype.notifyNestedSubsOnComponentDidUpdate = function notifyNestedSubsOnComponentDidUpdate() {
// `componentDidUpdate` is conditionally implemented when `onStateChange` determines it
// needs to notify nested subs. Once called, it unimplements itself until further state
// changes occur. Doing it this way vs having a permanent `componentDidMount` that does
// a boolean check every time avoids an extra method call most of the time, resulting
// in some perf boost.
this.componentDidUpdate = undefined;
this.notifyNestedSubs();
};
Connect.prototype.isSubscribed = function isSubscribed() {
return Boolean(this.subscription) && this.subscription.isSubscribed();
};
Connect.prototype.addExtraProps = function addExtraProps(props) {
if (!withRef && !renderCountProp && !(this.propsMode && this.subscription)) return props;
// make a shallow copy so that fields added don't leak to the original selector.
// this is especially important for 'ref' since that's a reference back to the component
// instance. a singleton memoized selector would then be holding a reference to the
// instance, preventing the instance from being garbage collected, and that would be bad
var withExtras = _extends({}, props);
if (withRef) withExtras.ref = this.setWrappedInstance;
if (renderCountProp) withExtras[renderCountProp] = this.renderCount++;
if (this.propsMode && this.subscription) withExtras[subscriptionKey] = this.subscription;
return withExtras;
};
Connect.prototype.render = function render() {
var selector = this.selector;
selector.shouldComponentUpdate = false;
if (selector.error) {
throw selector.error;
} else {
return (0, _react.createElement)(WrappedComponent, this.addExtraProps(selector.props));
}
};
return Connect;
}(_react.Component);
Connect.WrappedComponent = WrappedComponent;
Connect.displayName = displayName;
Connect.childContextTypes = childContextTypes;
Connect.contextTypes = contextTypes;
Connect.propTypes = contextTypes;
if (true) {
Connect.prototype.componentWillUpdate = function componentWillUpdate() {
// We are hot reloading!
if (this.version !== version) {
this.version = version;
this.initSelector();
if (this.subscription) this.subscription.tryUnsubscribe();
this.initSubscription();
if (shouldHandleStateChanges) this.subscription.trySubscribe();
}
};
}
return (0, _hoistNonReactStatics2.default)(Connect, WrappedComponent);
};
}
/***/ },
/* 3 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
exports.__esModule = true;
exports.wrapMapToPropsConstant = wrapMapToPropsConstant;
exports.getDependsOnOwnProps = getDependsOnOwnProps;
exports.wrapMapToPropsFunc = wrapMapToPropsFunc;
var _verifyPlainObject = __webpack_require__(5);
var _verifyPlainObject2 = _interopRequireDefault(_verifyPlainObject);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function wrapMapToPropsConstant(getConstant) {
return function initConstantSelector(dispatch, options) {
var constant = getConstant(dispatch, options);
function constantSelector() {
return constant;
}
constantSelector.dependsOnOwnProps = false;
return constantSelector;
};
}
// dependsOnOwnProps is used by createMapToPropsProxy to determine whether to pass props as args
// to the mapToProps function being wrapped. It is also used by makePurePropsSelector to determine
// whether mapToProps needs to be invoked when props have changed.
//
// A length of one signals that mapToProps does not depend on props from the parent component.
// A length of zero is assumed to mean mapToProps is getting args via arguments or ...args and
// therefore not reporting its length accurately..
function getDependsOnOwnProps(mapToProps) {
return mapToProps.dependsOnOwnProps !== null && mapToProps.dependsOnOwnProps !== undefined ? Boolean(mapToProps.dependsOnOwnProps) : mapToProps.length !== 1;
}
// Used by whenMapStateToPropsIsFunction and whenMapDispatchToPropsIsFunction,
// this function wraps mapToProps in a proxy function which does several things:
//
// * Detects whether the mapToProps function being called depends on props, which
// is used by selectorFactory to decide if it should reinvoke on props changes.
//
// * On first call, handles mapToProps if returns another function, and treats that
// new function as the true mapToProps for subsequent calls.
//
// * On first call, verifies the first result is a plain object, in order to warn
// the developer that their mapToProps function is not returning a valid result.
//
function wrapMapToPropsFunc(mapToProps, methodName) {
return function initProxySelector(dispatch, _ref) {
var displayName = _ref.displayName;
var proxy = function mapToPropsProxy(stateOrDispatch, ownProps) {
return proxy.dependsOnOwnProps ? proxy.mapToProps(stateOrDispatch, ownProps) : proxy.mapToProps(stateOrDispatch);
};
// allow detectFactoryAndVerify to get ownProps
proxy.dependsOnOwnProps = true;
proxy.mapToProps = function detectFactoryAndVerify(stateOrDispatch, ownProps) {
proxy.mapToProps = mapToProps;
proxy.dependsOnOwnProps = getDependsOnOwnProps(mapToProps);
var props = proxy(stateOrDispatch, ownProps);
if (typeof props === 'function') {
proxy.mapToProps = props;
proxy.dependsOnOwnProps = getDependsOnOwnProps(props);
props = proxy(stateOrDispatch, ownProps);
}
if (true) (0, _verifyPlainObject2.default)(props, displayName, methodName);
return props;
};
return proxy;
};
}
/***/ },
/* 4 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
exports.__esModule = true;
exports.storeShape = exports.subscriptionShape = undefined;
var _propTypes = __webpack_require__(10);
var _propTypes2 = _interopRequireDefault(_propTypes);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var subscriptionShape = exports.subscriptionShape = _propTypes2.default.shape({
trySubscribe: _propTypes2.default.func.isRequired,
tryUnsubscribe: _propTypes2.default.func.isRequired,
notifyNestedSubs: _propTypes2.default.func.isRequired,
isSubscribed: _propTypes2.default.func.isRequired
});
var storeShape = exports.storeShape = _propTypes2.default.shape({
subscribe: _propTypes2.default.func.isRequired,
dispatch: _propTypes2.default.func.isRequired,
getState: _propTypes2.default.func.isRequired
});
/***/ },
/* 5 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
exports.__esModule = true;
exports.default = verifyPlainObject;
var _isPlainObject = __webpack_require__(32);
var _isPlainObject2 = _interopRequireDefault(_isPlainObject);
var _warning = __webpack_require__(1);
var _warning2 = _interopRequireDefault(_warning);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function verifyPlainObject(value, displayName, methodName) {
if (!(0, _isPlainObject2.default)(value)) {
(0, _warning2.default)(methodName + '() in ' + displayName + ' must return a plain object. Instead received ' + value + '.');
}
}
/***/ },
/* 6 */
/***/ function(module, exports) {
"use strict";
/**
* Copyright (c) 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*
*/
function makeEmptyFunction(arg) {
return function () {
return arg;
};
}
/**
* This function accepts and discards inputs; it has no side effects. This is
* primarily useful idiomatically for overridable function endpoints which
* always need to be callable, since JS lacks a null-call idiom ala Cocoa.
*/
var emptyFunction = function emptyFunction() {};
emptyFunction.thatReturns = makeEmptyFunction;
emptyFunction.thatReturnsFalse = makeEmptyFunction(false);
emptyFunction.thatReturnsTrue = makeEmptyFunction(true);
emptyFunction.thatReturnsNull = makeEmptyFunction(null);
emptyFunction.thatReturnsThis = function () {
return this;
};
emptyFunction.thatReturnsArgument = function (arg) {
return arg;
};
module.exports = emptyFunction;
/***/ },
/* 7 */
/***/ function(module, exports, __webpack_require__) {
/**
* Copyright (c) 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
'use strict';
/**
* Use invariant() to assert state which your program assumes to be true.
*
* Provide sprintf-style format (only %s is supported) and arguments
* to provide information about what broke and what you were
* expecting.
*
* The invariant message will be stripped in production, but the invariant
* will remain to ensure logic does not differ in production.
*/
var validateFormat = function validateFormat(format) {};
if (true) {
validateFormat = function validateFormat(format) {
if (format === undefined) {
throw new Error('invariant requires an error message argument');
}
};
}
function invariant(condition, format, a, b, c, d, e, f) {
validateFormat(format);
if (!condition) {
var error;
if (format === undefined) {
error = new Error('Minified exception occurred; use the non-minified dev environment ' + 'for the full error message and additional helpful warnings.');
} else {
var args = [a, b, c, d, e, f];
var argIndex = 0;
error = new Error(format.replace(/%s/g, function () {
return args[argIndex++];
}));
error.name = 'Invariant Violation';
}
error.framesToPop = 1; // we don't care about invariant's own frame
throw error;
}
}
module.exports = invariant;
/***/ },
/* 8 */
/***/ function(module, exports, __webpack_require__) {
/**
* Copyright 2014-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
'use strict';
var emptyFunction = __webpack_require__(6);
/**
* Similar to invariant but only logs a warning if the condition is not met.
* This can be used to log issues in development environments in critical
* paths. Removing the logging code for production environments will keep the
* same logic and follow the same code paths.
*/
var warning = emptyFunction;
if (true) {
(function () {
var printWarning = function printWarning(format) {
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
var argIndex = 0;
var message = 'Warning: ' + format.replace(/%s/g, function () {
return args[argIndex++];
});
if (typeof console !== 'undefined') {
console.error(message);
}
try {
// --- Welcome to debugging React ---
// This error was thrown as a convenience so that you can use this stack
// to find the callsite that caused this warning to fire.
throw new Error(message);
} catch (x) {}
};
warning = function warning(condition, format) {
if (format === undefined) {
throw new Error('`warning(condition, format, ...args)` requires a warning ' + 'message argument');
}
if (format.indexOf('Failed Composite propType: ') === 0) {
return; // Ignore CompositeComponent proptype check.
}
if (!condition) {
for (var _len2 = arguments.length, args = Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
args[_key2 - 2] = arguments[_key2];
}
printWarning.apply(undefined, [format].concat(args));
}
};
})();
}
module.exports = warning;
/***/ },
/* 9 */
/***/ function(module, exports, __webpack_require__) {
var root = __webpack_require__(30);
/** Built-in value references. */
var Symbol = root.Symbol;
module.exports = Symbol;
/***/ },
/* 10 */
/***/ function(module, exports, __webpack_require__) {
/**
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
var factory = __webpack_require__(34);
var REACT_ELEMENT_TYPE = (typeof Symbol === 'function' &&
Symbol.for &&
Symbol.for('react.element')) ||
0xeac7;
function isValidElement(object) {
return typeof object === 'object' &&
object !== null &&
object.$$typeof === REACT_ELEMENT_TYPE;
}
module.exports = factory(isValidElement);
/***/ },
/* 11 */
/***/ function(module, exports) {
/**
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
'use strict';
var ReactPropTypesSecret = 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED';
module.exports = ReactPropTypesSecret;
/***/ },
/* 12 */
/***/ function(module, exports) {
module.exports = __WEBPACK_EXTERNAL_MODULE_12__;
/***/ },
/* 13 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
exports.__esModule = true;
exports.default = undefined;
var _react = __webpack_require__(12);
var _propTypes = __webpack_require__(10);
var _propTypes2 = _interopRequireDefault(_propTypes);
var _PropTypes = __webpack_require__(4);
var _warning = __webpack_require__(1);
var _warning2 = _interopRequireDefault(_warning);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var didWarnAboutReceivingStore = false;
function warnAboutReceivingStore() {
if (didWarnAboutReceivingStore) {
return;
}
didWarnAboutReceivingStore = true;
(0, _warning2.default)(' does not support changing `store` on the fly. ' + 'It is most likely that you see this error because you updated to ' + 'Redux 2.x and React Redux 2.x which no longer hot reload reducers ' + 'automatically. See https://github.com/reactjs/react-redux/releases/' + 'tag/v2.0.0 for the migration instructions.');
}
var Provider = function (_Component) {
_inherits(Provider, _Component);
Provider.prototype.getChildContext = function getChildContext() {
return { store: this.store, storeSubscription: null };
};
function Provider(props, context) {
_classCallCheck(this, Provider);
var _this = _possibleConstructorReturn(this, _Component.call(this, props, context));
_this.store = props.store;
return _this;
}
Provider.prototype.render = function render() {
return _react.Children.only(this.props.children);
};
return Provider;
}(_react.Component);
exports.default = Provider;
if (true) {
Provider.prototype.componentWillReceiveProps = function (nextProps) {
var store = this.store;
var nextStore = nextProps.store;
if (store !== nextStore) {
warnAboutReceivingStore();
}
};
}
Provider.propTypes = {
store: _PropTypes.storeShape.isRequired,
children: _propTypes2.default.element.isRequired
};
Provider.childContextTypes = {
store: _PropTypes.storeShape.isRequired,
storeSubscription: _PropTypes.subscriptionShape
};
Provider.displayName = 'Provider';
/***/ },
/* 14 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
exports.__esModule = true;
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
exports.createConnect = createConnect;
var _connectAdvanced = __webpack_require__(2);
var _connectAdvanced2 = _interopRequireDefault(_connectAdvanced);
var _shallowEqual = __webpack_require__(21);
var _shallowEqual2 = _interopRequireDefault(_shallowEqual);
var _mapDispatchToProps = __webpack_require__(15);
var _mapDispatchToProps2 = _interopRequireDefault(_mapDispatchToProps);
var _mapStateToProps = __webpack_require__(16);
var _mapStateToProps2 = _interopRequireDefault(_mapStateToProps);
var _mergeProps = __webpack_require__(17);
var _mergeProps2 = _interopRequireDefault(_mergeProps);
var _selectorFactory = __webpack_require__(18);
var _selectorFactory2 = _interopRequireDefault(_selectorFactory);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
/*
connect is a facade over connectAdvanced. It turns its args into a compatible
selectorFactory, which has the signature:
(dispatch, options) => (nextState, nextOwnProps) => nextFinalProps
connect passes its args to connectAdvanced as options, which will in turn pass them to
selectorFactory each time a Connect component instance is instantiated or hot reloaded.
selectorFactory returns a final props selector from its mapStateToProps,
mapStateToPropsFactories, mapDispatchToProps, mapDispatchToPropsFactories, mergeProps,
mergePropsFactories, and pure args.
The resulting final props selector is called by the Connect component instance whenever
it receives new props or store state.
*/
function match(arg, factories, name) {
for (var i = factories.length - 1; i >= 0; i--) {
var result = factories[i](arg);
if (result) return result;
}
return function (dispatch, options) {
throw new Error('Invalid value of type ' + typeof arg + ' for ' + name + ' argument when connecting component ' + options.wrappedComponentName + '.');
};
}
function strictEqual(a, b) {
return a === b;
}
// createConnect with default args builds the 'official' connect behavior. Calling it with
// different options opens up some testing and extensibility scenarios
function createConnect() {
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
_ref$connectHOC = _ref.connectHOC,
connectHOC = _ref$connectHOC === undefined ? _connectAdvanced2.default : _ref$connectHOC,
_ref$mapStateToPropsF = _ref.mapStateToPropsFactories,
mapStateToPropsFactories = _ref$mapStateToPropsF === undefined ? _mapStateToProps2.default : _ref$mapStateToPropsF,
_ref$mapDispatchToPro = _ref.mapDispatchToPropsFactories,
mapDispatchToPropsFactories = _ref$mapDispatchToPro === undefined ? _mapDispatchToProps2.default : _ref$mapDispatchToPro,
_ref$mergePropsFactor = _ref.mergePropsFactories,
mergePropsFactories = _ref$mergePropsFactor === undefined ? _mergeProps2.default : _ref$mergePropsFactor,
_ref$selectorFactory = _ref.selectorFactory,
selectorFactory = _ref$selectorFactory === undefined ? _selectorFactory2.default : _ref$selectorFactory;
return function connect(mapStateToProps, mapDispatchToProps, mergeProps) {
var _ref2 = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {},
_ref2$pure = _ref2.pure,
pure = _ref2$pure === undefined ? true : _ref2$pure,
_ref2$areStatesEqual = _ref2.areStatesEqual,
areStatesEqual = _ref2$areStatesEqual === undefined ? strictEqual : _ref2$areStatesEqual,
_ref2$areOwnPropsEqua = _ref2.areOwnPropsEqual,
areOwnPropsEqual = _ref2$areOwnPropsEqua === undefined ? _shallowEqual2.default : _ref2$areOwnPropsEqua,
_ref2$areStatePropsEq = _ref2.areStatePropsEqual,
areStatePropsEqual = _ref2$areStatePropsEq === undefined ? _shallowEqual2.default : _ref2$areStatePropsEq,
_ref2$areMergedPropsE = _ref2.areMergedPropsEqual,
areMergedPropsEqual = _ref2$areMergedPropsE === undefined ? _shallowEqual2.default : _ref2$areMergedPropsE,
extraOptions = _objectWithoutProperties(_ref2, ['pure', 'areStatesEqual', 'areOwnPropsEqual', 'areStatePropsEqual', 'areMergedPropsEqual']);
var initMapStateToProps = match(mapStateToProps, mapStateToPropsFactories, 'mapStateToProps');
var initMapDispatchToProps = match(mapDispatchToProps, mapDispatchToPropsFactories, 'mapDispatchToProps');
var initMergeProps = match(mergeProps, mergePropsFactories, 'mergeProps');
return connectHOC(selectorFactory, _extends({
// used in error messages
methodName: 'connect',
// used to compute Connect's displayName from the wrapped component's displayName.
getDisplayName: function getDisplayName(name) {
return 'Connect(' + name + ')';
},
// if mapStateToProps is falsy, the Connect component doesn't subscribe to store state changes
shouldHandleStateChanges: Boolean(mapStateToProps),
// passed through to selectorFactory
initMapStateToProps: initMapStateToProps,
initMapDispatchToProps: initMapDispatchToProps,
initMergeProps: initMergeProps,
pure: pure,
areStatesEqual: areStatesEqual,
areOwnPropsEqual: areOwnPropsEqual,
areStatePropsEqual: areStatePropsEqual,
areMergedPropsEqual: areMergedPropsEqual
}, extraOptions));
};
}
exports.default = createConnect();
/***/ },
/* 15 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
exports.__esModule = true;
exports.whenMapDispatchToPropsIsFunction = whenMapDispatchToPropsIsFunction;
exports.whenMapDispatchToPropsIsMissing = whenMapDispatchToPropsIsMissing;
exports.whenMapDispatchToPropsIsObject = whenMapDispatchToPropsIsObject;
var _redux = __webpack_require__(35);
var _wrapMapToProps = __webpack_require__(3);
function whenMapDispatchToPropsIsFunction(mapDispatchToProps) {
return typeof mapDispatchToProps === 'function' ? (0, _wrapMapToProps.wrapMapToPropsFunc)(mapDispatchToProps, 'mapDispatchToProps') : undefined;
}
function whenMapDispatchToPropsIsMissing(mapDispatchToProps) {
return !mapDispatchToProps ? (0, _wrapMapToProps.wrapMapToPropsConstant)(function (dispatch) {
return { dispatch: dispatch };
}) : undefined;
}
function whenMapDispatchToPropsIsObject(mapDispatchToProps) {
return mapDispatchToProps && typeof mapDispatchToProps === 'object' ? (0, _wrapMapToProps.wrapMapToPropsConstant)(function (dispatch) {
return (0, _redux.bindActionCreators)(mapDispatchToProps, dispatch);
}) : undefined;
}
exports.default = [whenMapDispatchToPropsIsFunction, whenMapDispatchToPropsIsMissing, whenMapDispatchToPropsIsObject];
/***/ },
/* 16 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
exports.__esModule = true;
exports.whenMapStateToPropsIsFunction = whenMapStateToPropsIsFunction;
exports.whenMapStateToPropsIsMissing = whenMapStateToPropsIsMissing;
var _wrapMapToProps = __webpack_require__(3);
function whenMapStateToPropsIsFunction(mapStateToProps) {
return typeof mapStateToProps === 'function' ? (0, _wrapMapToProps.wrapMapToPropsFunc)(mapStateToProps, 'mapStateToProps') : undefined;
}
function whenMapStateToPropsIsMissing(mapStateToProps) {
return !mapStateToProps ? (0, _wrapMapToProps.wrapMapToPropsConstant)(function () {
return {};
}) : undefined;
}
exports.default = [whenMapStateToPropsIsFunction, whenMapStateToPropsIsMissing];
/***/ },
/* 17 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
exports.__esModule = true;
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
exports.defaultMergeProps = defaultMergeProps;
exports.wrapMergePropsFunc = wrapMergePropsFunc;
exports.whenMergePropsIsFunction = whenMergePropsIsFunction;
exports.whenMergePropsIsOmitted = whenMergePropsIsOmitted;
var _verifyPlainObject = __webpack_require__(5);
var _verifyPlainObject2 = _interopRequireDefault(_verifyPlainObject);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function defaultMergeProps(stateProps, dispatchProps, ownProps) {
return _extends({}, ownProps, stateProps, dispatchProps);
}
function wrapMergePropsFunc(mergeProps) {
return function initMergePropsProxy(dispatch, _ref) {
var displayName = _ref.displayName,
pure = _ref.pure,
areMergedPropsEqual = _ref.areMergedPropsEqual;
var hasRunOnce = false;
var mergedProps = void 0;
return function mergePropsProxy(stateProps, dispatchProps, ownProps) {
var nextMergedProps = mergeProps(stateProps, dispatchProps, ownProps);
if (hasRunOnce) {
if (!pure || !areMergedPropsEqual(nextMergedProps, mergedProps)) mergedProps = nextMergedProps;
} else {
hasRunOnce = true;
mergedProps = nextMergedProps;
if (true) (0, _verifyPlainObject2.default)(mergedProps, displayName, 'mergeProps');
}
return mergedProps;
};
};
}
function whenMergePropsIsFunction(mergeProps) {
return typeof mergeProps === 'function' ? wrapMergePropsFunc(mergeProps) : undefined;
}
function whenMergePropsIsOmitted(mergeProps) {
return !mergeProps ? function () {
return defaultMergeProps;
} : undefined;
}
exports.default = [whenMergePropsIsFunction, whenMergePropsIsOmitted];
/***/ },
/* 18 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
exports.__esModule = true;
exports.impureFinalPropsSelectorFactory = impureFinalPropsSelectorFactory;
exports.pureFinalPropsSelectorFactory = pureFinalPropsSelectorFactory;
exports.default = finalPropsSelectorFactory;
var _verifySubselectors = __webpack_require__(19);
var _verifySubselectors2 = _interopRequireDefault(_verifySubselectors);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
function impureFinalPropsSelectorFactory(mapStateToProps, mapDispatchToProps, mergeProps, dispatch) {
return function impureFinalPropsSelector(state, ownProps) {
return mergeProps(mapStateToProps(state, ownProps), mapDispatchToProps(dispatch, ownProps), ownProps);
};
}
function pureFinalPropsSelectorFactory(mapStateToProps, mapDispatchToProps, mergeProps, dispatch, _ref) {
var areStatesEqual = _ref.areStatesEqual,
areOwnPropsEqual = _ref.areOwnPropsEqual,
areStatePropsEqual = _ref.areStatePropsEqual;
var hasRunAtLeastOnce = false;
var state = void 0;
var ownProps = void 0;
var stateProps = void 0;
var dispatchProps = void 0;
var mergedProps = void 0;
function handleFirstCall(firstState, firstOwnProps) {
state = firstState;
ownProps = firstOwnProps;
stateProps = mapStateToProps(state, ownProps);
dispatchProps = mapDispatchToProps(dispatch, ownProps);
mergedProps = mergeProps(stateProps, dispatchProps, ownProps);
hasRunAtLeastOnce = true;
return mergedProps;
}
function handleNewPropsAndNewState() {
stateProps = mapStateToProps(state, ownProps);
if (mapDispatchToProps.dependsOnOwnProps) dispatchProps = mapDispatchToProps(dispatch, ownProps);
mergedProps = mergeProps(stateProps, dispatchProps, ownProps);
return mergedProps;
}
function handleNewProps() {
if (mapStateToProps.dependsOnOwnProps) stateProps = mapStateToProps(state, ownProps);
if (mapDispatchToProps.dependsOnOwnProps) dispatchProps = mapDispatchToProps(dispatch, ownProps);
mergedProps = mergeProps(stateProps, dispatchProps, ownProps);
return mergedProps;
}
function handleNewState() {
var nextStateProps = mapStateToProps(state, ownProps);
var statePropsChanged = !areStatePropsEqual(nextStateProps, stateProps);
stateProps = nextStateProps;
if (statePropsChanged) mergedProps = mergeProps(stateProps, dispatchProps, ownProps);
return mergedProps;
}
function handleSubsequentCalls(nextState, nextOwnProps) {
var propsChanged = !areOwnPropsEqual(nextOwnProps, ownProps);
var stateChanged = !areStatesEqual(nextState, state);
state = nextState;
ownProps = nextOwnProps;
if (propsChanged && stateChanged) return handleNewPropsAndNewState();
if (propsChanged) return handleNewProps();
if (stateChanged) return handleNewState();
return mergedProps;
}
return function pureFinalPropsSelector(nextState, nextOwnProps) {
return hasRunAtLeastOnce ? handleSubsequentCalls(nextState, nextOwnProps) : handleFirstCall(nextState, nextOwnProps);
};
}
// TODO: Add more comments
// If pure is true, the selector returned by selectorFactory will memoize its results,
// allowing connectAdvanced's shouldComponentUpdate to return false if final
// props have not changed. If false, the selector will always return a new
// object and shouldComponentUpdate will always return true.
function finalPropsSelectorFactory(dispatch, _ref2) {
var initMapStateToProps = _ref2.initMapStateToProps,
initMapDispatchToProps = _ref2.initMapDispatchToProps,
initMergeProps = _ref2.initMergeProps,
options = _objectWithoutProperties(_ref2, ['initMapStateToProps', 'initMapDispatchToProps', 'initMergeProps']);
var mapStateToProps = initMapStateToProps(dispatch, options);
var mapDispatchToProps = initMapDispatchToProps(dispatch, options);
var mergeProps = initMergeProps(dispatch, options);
if (true) {
(0, _verifySubselectors2.default)(mapStateToProps, mapDispatchToProps, mergeProps, options.displayName);
}
var selectorFactory = options.pure ? pureFinalPropsSelectorFactory : impureFinalPropsSelectorFactory;
return selectorFactory(mapStateToProps, mapDispatchToProps, mergeProps, dispatch, options);
}
/***/ },
/* 19 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
exports.__esModule = true;
exports.default = verifySubselectors;
var _warning = __webpack_require__(1);
var _warning2 = _interopRequireDefault(_warning);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function verify(selector, methodName, displayName) {
if (!selector) {
throw new Error('Unexpected value for ' + methodName + ' in ' + displayName + '.');
} else if (methodName === 'mapStateToProps' || methodName === 'mapDispatchToProps') {
if (!selector.hasOwnProperty('dependsOnOwnProps')) {
(0, _warning2.default)('The selector for ' + methodName + ' of ' + displayName + ' did not specify a value for dependsOnOwnProps.');
}
}
}
function verifySubselectors(mapStateToProps, mapDispatchToProps, mergeProps, displayName) {
verify(mapStateToProps, 'mapStateToProps', displayName);
verify(mapDispatchToProps, 'mapDispatchToProps', displayName);
verify(mergeProps, 'mergeProps', displayName);
}
/***/ },
/* 20 */
/***/ function(module, exports) {
"use strict";
exports.__esModule = true;
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
// encapsulates the subscription logic for connecting a component to the redux store, as
// well as nesting subscriptions of descendant components, so that we can ensure the
// ancestor components re-render before descendants
var CLEARED = null;
var nullListeners = {
notify: function notify() {}
};
function createListenerCollection() {
// the current/next pattern is copied from redux's createStore code.
// TODO: refactor+expose that code to be reusable here?
var current = [];
var next = [];
return {
clear: function clear() {
next = CLEARED;
current = CLEARED;
},
notify: function notify() {
var listeners = current = next;
for (var i = 0; i < listeners.length; i++) {
listeners[i]();
}
},
subscribe: function subscribe(listener) {
var isSubscribed = true;
if (next === current) next = current.slice();
next.push(listener);
return function unsubscribe() {
if (!isSubscribed || current === CLEARED) return;
isSubscribed = false;
if (next === current) next = current.slice();
next.splice(next.indexOf(listener), 1);
};
}
};
}
var Subscription = function () {
function Subscription(store, parentSub, onStateChange) {
_classCallCheck(this, Subscription);
this.store = store;
this.parentSub = parentSub;
this.onStateChange = onStateChange;
this.unsubscribe = null;
this.listeners = nullListeners;
}
Subscription.prototype.addNestedSub = function addNestedSub(listener) {
this.trySubscribe();
return this.listeners.subscribe(listener);
};
Subscription.prototype.notifyNestedSubs = function notifyNestedSubs() {
this.listeners.notify();
};
Subscription.prototype.isSubscribed = function isSubscribed() {
return Boolean(this.unsubscribe);
};
Subscription.prototype.trySubscribe = function trySubscribe() {
if (!this.unsubscribe) {
this.unsubscribe = this.parentSub ? this.parentSub.addNestedSub(this.onStateChange) : this.store.subscribe(this.onStateChange);
this.listeners = createListenerCollection();
}
};
Subscription.prototype.tryUnsubscribe = function tryUnsubscribe() {
if (this.unsubscribe) {
this.unsubscribe();
this.unsubscribe = null;
this.listeners.clear();
this.listeners = nullListeners;
}
};
return Subscription;
}();
exports.default = Subscription;
/***/ },
/* 21 */
/***/ function(module, exports) {
'use strict';
exports.__esModule = true;
exports.default = shallowEqual;
var hasOwn = Object.prototype.hasOwnProperty;
function is(x, y) {
if (x === y) {
return x !== 0 || y !== 0 || 1 / x === 1 / y;
} else {
return x !== x && y !== y;
}
}
function shallowEqual(objA, objB) {
if (is(objA, objB)) return true;
if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) {
return false;
}
var keysA = Object.keys(objA);
var keysB = Object.keys(objB);
if (keysA.length !== keysB.length) return false;
for (var i = 0; i < keysA.length; i++) {
if (!hasOwn.call(objB, keysA[i]) || !is(objA[keysA[i]], objB[keysA[i]])) {
return false;
}
}
return true;
}
/***/ },
/* 22 */
/***/ function(module, exports) {
/**
* Copyright 2015, Yahoo! Inc.
* Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms.
*/
'use strict';
var REACT_STATICS = {
childContextTypes: true,
contextTypes: true,
defaultProps: true,
displayName: true,
getDefaultProps: true,
mixins: true,
propTypes: true,
type: true
};
var KNOWN_STATICS = {
name: true,
length: true,
prototype: true,
caller: true,
arguments: true,
arity: true
};
var isGetOwnPropertySymbolsAvailable = typeof Object.getOwnPropertySymbols === 'function';
module.exports = function hoistNonReactStatics(targetComponent, sourceComponent, customStatics) {
if (typeof sourceComponent !== 'string') { // don't hoist over string (html) components
var keys = Object.getOwnPropertyNames(sourceComponent);
/* istanbul ignore else */
if (isGetOwnPropertySymbolsAvailable) {
keys = keys.concat(Object.getOwnPropertySymbols(sourceComponent));
}
for (var i = 0; i < keys.length; ++i) {
if (!REACT_STATICS[keys[i]] && !KNOWN_STATICS[keys[i]] && (!customStatics || !customStatics[keys[i]])) {
try {
targetComponent[keys[i]] = sourceComponent[keys[i]];
} catch (error) {
}
}
}
}
return targetComponent;
};
/***/ },
/* 23 */
/***/ function(module, exports, __webpack_require__) {
/**
* Copyright 2013-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
'use strict';
/**
* Use invariant() to assert state which your program assumes to be true.
*
* Provide sprintf-style format (only %s is supported) and arguments
* to provide information about what broke and what you were
* expecting.
*
* The invariant message will be stripped in production, but the invariant
* will remain to ensure logic does not differ in production.
*/
var invariant = function(condition, format, a, b, c, d, e, f) {
if (true) {
if (format === undefined) {
throw new Error('invariant requires an error message argument');
}
}
if (!condition) {
var error;
if (format === undefined) {
error = new Error(
'Minified exception occurred; use the non-minified dev environment ' +
'for the full error message and additional helpful warnings.'
);
} else {
var args = [a, b, c, d, e, f];
var argIndex = 0;
error = new Error(
format.replace(/%s/g, function() { return args[argIndex++]; })
);
error.name = 'Invariant Violation';
}
error.framesToPop = 1; // we don't care about invariant's own frame
throw error;
}
};
module.exports = invariant;
/***/ },
/* 24 */
/***/ function(module, exports, __webpack_require__) {
var Symbol = __webpack_require__(9),
getRawTag = __webpack_require__(27),
objectToString = __webpack_require__(28);
/** `Object#toString` result references. */
var nullTag = '[object Null]',
undefinedTag = '[object Undefined]';
/** Built-in value references. */
var symToStringTag = Symbol ? Symbol.toStringTag : undefined;
/**
* The base implementation of `getTag` without fallbacks for buggy environments.
*
* @private
* @param {*} value The value to query.
* @returns {string} Returns the `toStringTag`.
*/
function baseGetTag(value) {
if (value == null) {
return value === undefined ? undefinedTag : nullTag;
}
return (symToStringTag && symToStringTag in Object(value))
? getRawTag(value)
: objectToString(value);
}
module.exports = baseGetTag;
/***/ },
/* 25 */
/***/ function(module, exports) {
/* WEBPACK VAR INJECTION */(function(global) {/** Detect free variable `global` from Node.js. */
var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
module.exports = freeGlobal;
/* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }()) || Function('return this')()))
/***/ },
/* 26 */
/***/ function(module, exports, __webpack_require__) {
var overArg = __webpack_require__(29);
/** Built-in value references. */
var getPrototype = overArg(Object.getPrototypeOf, Object);
module.exports = getPrototype;
/***/ },
/* 27 */
/***/ function(module, exports, __webpack_require__) {
var Symbol = __webpack_require__(9);
/** Used for built-in method references. */
var objectProto = Object.prototype;
/** Used to check objects for own properties. */
var hasOwnProperty = objectProto.hasOwnProperty;
/**
* Used to resolve the
* [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
* of values.
*/
var nativeObjectToString = objectProto.toString;
/** Built-in value references. */
var symToStringTag = Symbol ? Symbol.toStringTag : undefined;
/**
* A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values.
*
* @private
* @param {*} value The value to query.
* @returns {string} Returns the raw `toStringTag`.
*/
function getRawTag(value) {
var isOwn = hasOwnProperty.call(value, symToStringTag),
tag = value[symToStringTag];
try {
value[symToStringTag] = undefined;
var unmasked = true;
} catch (e) {}
var result = nativeObjectToString.call(value);
if (unmasked) {
if (isOwn) {
value[symToStringTag] = tag;
} else {
delete value[symToStringTag];
}
}
return result;
}
module.exports = getRawTag;
/***/ },
/* 28 */
/***/ function(module, exports) {
/** Used for built-in method references. */
var objectProto = Object.prototype;
/**
* Used to resolve the
* [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
* of values.
*/
var nativeObjectToString = objectProto.toString;
/**
* Converts `value` to a string using `Object.prototype.toString`.
*
* @private
* @param {*} value The value to convert.
* @returns {string} Returns the converted string.
*/
function objectToString(value) {
return nativeObjectToString.call(value);
}
module.exports = objectToString;
/***/ },
/* 29 */
/***/ function(module, exports) {
/**
* Creates a unary function that invokes `func` with its argument transformed.
*
* @private
* @param {Function} func The function to wrap.
* @param {Function} transform The argument transform.
* @returns {Function} Returns the new function.
*/
function overArg(func, transform) {
return function(arg) {
return func(transform(arg));
};
}
module.exports = overArg;
/***/ },
/* 30 */
/***/ function(module, exports, __webpack_require__) {
var freeGlobal = __webpack_require__(25);
/** Detect free variable `self`. */
var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
/** Used as a reference to the global object. */
var root = freeGlobal || freeSelf || Function('return this')();
module.exports = root;
/***/ },
/* 31 */
/***/ function(module, exports) {
/**
* Checks if `value` is object-like. A value is object-like if it's not `null`
* and has a `typeof` result of "object".
*
* @static
* @memberOf _
* @since 4.0.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is object-like, else `false`.
* @example
*
* _.isObjectLike({});
* // => true
*
* _.isObjectLike([1, 2, 3]);
* // => true
*
* _.isObjectLike(_.noop);
* // => false
*
* _.isObjectLike(null);
* // => false
*/
function isObjectLike(value) {
return value != null && typeof value == 'object';
}
module.exports = isObjectLike;
/***/ },
/* 32 */
/***/ function(module, exports, __webpack_require__) {
var baseGetTag = __webpack_require__(24),
getPrototype = __webpack_require__(26),
isObjectLike = __webpack_require__(31);
/** `Object#toString` result references. */
var objectTag = '[object Object]';
/** Used for built-in method references. */
var funcProto = Function.prototype,
objectProto = Object.prototype;
/** Used to resolve the decompiled source of functions. */
var funcToString = funcProto.toString;
/** Used to check objects for own properties. */
var hasOwnProperty = objectProto.hasOwnProperty;
/** Used to infer the `Object` constructor. */
var objectCtorString = funcToString.call(Object);
/**
* Checks if `value` is a plain object, that is, an object created by the
* `Object` constructor or one with a `[[Prototype]]` of `null`.
*
* @static
* @memberOf _
* @since 0.8.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
* @example
*
* function Foo() {
* this.a = 1;
* }
*
* _.isPlainObject(new Foo);
* // => false
*
* _.isPlainObject([1, 2, 3]);
* // => false
*
* _.isPlainObject({ 'x': 0, 'y': 0 });
* // => true
*
* _.isPlainObject(Object.create(null));
* // => true
*/
function isPlainObject(value) {
if (!isObjectLike(value) || baseGetTag(value) != objectTag) {
return false;
}
var proto = getPrototype(value);
if (proto === null) {
return true;
}
var Ctor = hasOwnProperty.call(proto, 'constructor') && proto.constructor;
return typeof Ctor == 'function' && Ctor instanceof Ctor &&
funcToString.call(Ctor) == objectCtorString;
}
module.exports = isPlainObject;
/***/ },
/* 33 */
/***/ function(module, exports, __webpack_require__) {
/**
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
'use strict';
var invariant = __webpack_require__(7);
var warning = __webpack_require__(8);
var ReactPropTypesSecret = __webpack_require__(11);
var loggedTypeFailures = {};
/**
* Assert that the values match with the type specs.
* Error messages are memorized and will only be shown once.
*
* @param {object} typeSpecs Map of name to a ReactPropType
* @param {object} values Runtime values that need to be type-checked
* @param {string} location e.g. "prop", "context", "child context"
* @param {string} componentName Name of the component for error messages.
* @param {?Function} getStack Returns the component stack.
* @private
*/
function checkPropTypes(typeSpecs, values, location, componentName, getStack) {
if (true) {
for (var typeSpecName in typeSpecs) {
if (typeSpecs.hasOwnProperty(typeSpecName)) {
var error;
// Prop type validation may throw. In case they do, we don't want to
// fail the render phase where it didn't fail before. So we log it.
// After these have been cleaned up, we'll let them throw.
try {
// This is intentionally an invariant that gets caught. It's the same
// behavior as without this statement except with a better message.
invariant(typeof typeSpecs[typeSpecName] === 'function', '%s: %s type `%s` is invalid; it must be a function, usually from ' + 'React.PropTypes.', componentName || 'React class', location, typeSpecName);
error = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, ReactPropTypesSecret);
} catch (ex) {
error = ex;
}
true ? warning(!error || error instanceof Error, '%s: type specification of %s `%s` is invalid; the type checker ' + 'function must return `null` or an `Error` but returned a %s. ' + 'You may have forgotten to pass an argument to the type checker ' + 'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' + 'shape all require an argument).', componentName || 'React class', location, typeSpecName, typeof error) : void 0;
if (error instanceof Error && !(error.message in loggedTypeFailures)) {
// Only monitor this failure once because there tends to be a lot of the
// same error.
loggedTypeFailures[error.message] = true;
var stack = getStack ? getStack() : '';
true ? warning(false, 'Failed %s type: %s%s', location, error.message, stack != null ? stack : '') : void 0;
}
}
}
}
}
module.exports = checkPropTypes;
/***/ },
/* 34 */
/***/ function(module, exports, __webpack_require__) {
/**
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
'use strict';
var emptyFunction = __webpack_require__(6);
var invariant = __webpack_require__(7);
var warning = __webpack_require__(8);
var ReactPropTypesSecret = __webpack_require__(11);
var checkPropTypes = __webpack_require__(33);
module.exports = function (isValidElement) {
/* global Symbol */
var ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
var FAUX_ITERATOR_SYMBOL = '@@iterator'; // Before Symbol spec.
/**
* Returns the iterator method function contained on the iterable object.
*
* Be sure to invoke the function with the iterable as context:
*
* var iteratorFn = getIteratorFn(myIterable);
* if (iteratorFn) {
* var iterator = iteratorFn.call(myIterable);
* ...
* }
*
* @param {?object} maybeIterable
* @return {?function}
*/
function getIteratorFn(maybeIterable) {
var iteratorFn = maybeIterable && (ITERATOR_SYMBOL && maybeIterable[ITERATOR_SYMBOL] || maybeIterable[FAUX_ITERATOR_SYMBOL]);
if (typeof iteratorFn === 'function') {
return iteratorFn;
}
}
/**
* Collection of methods that allow declaration and validation of props that are
* supplied to React components. Example usage:
*
* var Props = require('ReactPropTypes');
* var MyArticle = React.createClass({
* propTypes: {
* // An optional string prop named "description".
* description: Props.string,
*
* // A required enum prop named "category".
* category: Props.oneOf(['News','Photos']).isRequired,
*
* // A prop named "dialog" that requires an instance of Dialog.
* dialog: Props.instanceOf(Dialog).isRequired
* },
* render: function() { ... }
* });
*
* A more formal specification of how these methods are used:
*
* type := array|bool|func|object|number|string|oneOf([...])|instanceOf(...)
* decl := ReactPropTypes.{type}(.isRequired)?
*
* Each and every declaration produces a function with the same signature. This
* allows the creation of custom validation functions. For example:
*
* var MyLink = React.createClass({
* propTypes: {
* // An optional string or URI prop named "href".
* href: function(props, propName, componentName) {
* var propValue = props[propName];
* if (propValue != null && typeof propValue !== 'string' &&
* !(propValue instanceof URI)) {
* return new Error(
* 'Expected a string or an URI for ' + propName + ' in ' +
* componentName
* );
* }
* }
* },
* render: function() {...}
* });
*
* @internal
*/
var ANONYMOUS = '<>';
var ReactPropTypes;
if (true) {
// Keep in sync with production version below
ReactPropTypes = {
array: createPrimitiveTypeChecker('array'),
bool: createPrimitiveTypeChecker('boolean'),
func: createPrimitiveTypeChecker('function'),
number: createPrimitiveTypeChecker('number'),
object: createPrimitiveTypeChecker('object'),
string: createPrimitiveTypeChecker('string'),
symbol: createPrimitiveTypeChecker('symbol'),
any: createAnyTypeChecker(),
arrayOf: createArrayOfTypeChecker,
element: createElementTypeChecker(),
instanceOf: createInstanceTypeChecker,
node: createNodeChecker(),
objectOf: createObjectOfTypeChecker,
oneOf: createEnumTypeChecker,
oneOfType: createUnionTypeChecker,
shape: createShapeTypeChecker
};
} else {
var productionTypeChecker = function () {
invariant(false, 'React.PropTypes type checking code is stripped in production.');
};
productionTypeChecker.isRequired = productionTypeChecker;
var getProductionTypeChecker = function () {
return productionTypeChecker;
};
// Keep in sync with development version above
ReactPropTypes = {
array: productionTypeChecker,
bool: productionTypeChecker,
func: productionTypeChecker,
number: productionTypeChecker,
object: productionTypeChecker,
string: productionTypeChecker,
symbol: productionTypeChecker,
any: productionTypeChecker,
arrayOf: getProductionTypeChecker,
element: productionTypeChecker,
instanceOf: getProductionTypeChecker,
node: productionTypeChecker,
objectOf: getProductionTypeChecker,
oneOf: getProductionTypeChecker,
oneOfType: getProductionTypeChecker,
shape: getProductionTypeChecker
};
}
/**
* inlined Object.is polyfill to avoid requiring consumers ship their own
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
*/
/*eslint-disable no-self-compare*/
function is(x, y) {
// SameValue algorithm
if (x === y) {
// Steps 1-5, 7-10
// Steps 6.b-6.e: +0 != -0
return x !== 0 || 1 / x === 1 / y;
} else {
// Step 6.a: NaN == NaN
return x !== x && y !== y;
}
}
/*eslint-enable no-self-compare*/
/**
* We use an Error-like object for backward compatibility as people may call
* PropTypes directly and inspect their output. However, we don't use real
* Errors anymore. We don't inspect their stack anyway, and creating them
* is prohibitively expensive if they are created too often, such as what
* happens in oneOfType() for any type before the one that matched.
*/
function PropTypeError(message) {
this.message = message;
this.stack = '';
}
// Make `instanceof Error` still work for returned errors.
PropTypeError.prototype = Error.prototype;
function createChainableTypeChecker(validate) {
if (true) {
var manualPropTypeCallCache = {};
}
function checkType(isRequired, props, propName, componentName, location, propFullName, secret) {
componentName = componentName || ANONYMOUS;
propFullName = propFullName || propName;
if (true) {
if (secret !== ReactPropTypesSecret && typeof console !== 'undefined') {
var cacheKey = componentName + ':' + propName;
if (!manualPropTypeCallCache[cacheKey]) {
true ? warning(false, 'You are manually calling a React.PropTypes validation ' + 'function for the `%s` prop on `%s`. This is deprecated ' + 'and will not work in production with the next major version. ' + 'You may be seeing this warning due to a third-party PropTypes ' + 'library. See https://fb.me/react-warning-dont-call-proptypes ' + 'for details.', propFullName, componentName) : void 0;
manualPropTypeCallCache[cacheKey] = true;
}
}
}
if (props[propName] == null) {
if (isRequired) {
if (props[propName] === null) {
return new PropTypeError('The ' + location + ' `' + propFullName + '` is marked as required ' + ('in `' + componentName + '`, but its value is `null`.'));
}
return new PropTypeError('The ' + location + ' `' + propFullName + '` is marked as required in ' + ('`' + componentName + '`, but its value is `undefined`.'));
}
return null;
} else {
return validate(props, propName, componentName, location, propFullName);
}
}
var chainedCheckType = checkType.bind(null, false);
chainedCheckType.isRequired = checkType.bind(null, true);
return chainedCheckType;
}
function createPrimitiveTypeChecker(expectedType) {
function validate(props, propName, componentName, location, propFullName, secret) {
var propValue = props[propName];
var propType = getPropType(propValue);
if (propType !== expectedType) {
// `propValue` being instance of, say, date/regexp, pass the 'object'
// check, but we can offer a more precise error message here rather than
// 'of type `object`'.
var preciseType = getPreciseType(propValue);
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + preciseType + '` supplied to `' + componentName + '`, expected ') + ('`' + expectedType + '`.'));
}
return null;
}
return createChainableTypeChecker(validate);
}
function createAnyTypeChecker() {
return createChainableTypeChecker(emptyFunction.thatReturnsNull);
}
function createArrayOfTypeChecker(typeChecker) {
function validate(props, propName, componentName, location, propFullName) {
if (typeof typeChecker !== 'function') {
return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside arrayOf.');
}
var propValue = props[propName];
if (!Array.isArray(propValue)) {
var propType = getPropType(propValue);
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an array.'));
}
for (var i = 0; i < propValue.length; i++) {
var error = typeChecker(propValue, i, componentName, location, propFullName + '[' + i + ']', ReactPropTypesSecret);
if (error instanceof Error) {
return error;
}
}
return null;
}
return createChainableTypeChecker(validate);
}
function createElementTypeChecker() {
function validate(props, propName, componentName, location, propFullName) {
var propValue = props[propName];
if (!isValidElement(propValue)) {
var propType = getPropType(propValue);
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected a single ReactElement.'));
}
return null;
}
return createChainableTypeChecker(validate);
}
function createInstanceTypeChecker(expectedClass) {
function validate(props, propName, componentName, location, propFullName) {
if (!(props[propName] instanceof expectedClass)) {
var expectedClassName = expectedClass.name || ANONYMOUS;
var actualClassName = getClassName(props[propName]);
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + actualClassName + '` supplied to `' + componentName + '`, expected ') + ('instance of `' + expectedClassName + '`.'));
}
return null;
}
return createChainableTypeChecker(validate);
}
function createEnumTypeChecker(expectedValues) {
if (!Array.isArray(expectedValues)) {
true ? warning(false, 'Invalid argument supplied to oneOf, expected an instance of array.') : void 0;
return emptyFunction.thatReturnsNull;
}
function validate(props, propName, componentName, location, propFullName) {
var propValue = props[propName];
for (var i = 0; i < expectedValues.length; i++) {
if (is(propValue, expectedValues[i])) {
return null;
}
}
var valuesString = JSON.stringify(expectedValues);
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of value `' + propValue + '` ' + ('supplied to `' + componentName + '`, expected one of ' + valuesString + '.'));
}
return createChainableTypeChecker(validate);
}
function createObjectOfTypeChecker(typeChecker) {
function validate(props, propName, componentName, location, propFullName) {
if (typeof typeChecker !== 'function') {
return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside objectOf.');
}
var propValue = props[propName];
var propType = getPropType(propValue);
if (propType !== 'object') {
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an object.'));
}
for (var key in propValue) {
if (propValue.hasOwnProperty(key)) {
var error = typeChecker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret);
if (error instanceof Error) {
return error;
}
}
}
return null;
}
return createChainableTypeChecker(validate);
}
function createUnionTypeChecker(arrayOfTypeCheckers) {
if (!Array.isArray(arrayOfTypeCheckers)) {
true ? warning(false, 'Invalid argument supplied to oneOfType, expected an instance of array.') : void 0;
return emptyFunction.thatReturnsNull;
}
function validate(props, propName, componentName, location, propFullName) {
for (var i = 0; i < arrayOfTypeCheckers.length; i++) {
var checker = arrayOfTypeCheckers[i];
if (checker(props, propName, componentName, location, propFullName, ReactPropTypesSecret) == null) {
return null;
}
}
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`.'));
}
return createChainableTypeChecker(validate);
}
function createNodeChecker() {
function validate(props, propName, componentName, location, propFullName) {
if (!isNode(props[propName])) {
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`, expected a ReactNode.'));
}
return null;
}
return createChainableTypeChecker(validate);
}
function createShapeTypeChecker(shapeTypes) {
function validate(props, propName, componentName, location, propFullName) {
var propValue = props[propName];
var propType = getPropType(propValue);
if (propType !== 'object') {
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type `' + propType + '` ' + ('supplied to `' + componentName + '`, expected `object`.'));
}
for (var key in shapeTypes) {
var checker = shapeTypes[key];
if (!checker) {
continue;
}
var error = checker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret);
if (error) {
return error;
}
}
return null;
}
return createChainableTypeChecker(validate);
}
function isNode(propValue) {
switch (typeof propValue) {
case 'number':
case 'string':
case 'undefined':
return true;
case 'boolean':
return !propValue;
case 'object':
if (Array.isArray(propValue)) {
return propValue.every(isNode);
}
if (propValue === null || isValidElement(propValue)) {
return true;
}
var iteratorFn = getIteratorFn(propValue);
if (iteratorFn) {
var iterator = iteratorFn.call(propValue);
var step;
if (iteratorFn !== propValue.entries) {
while (!(step = iterator.next()).done) {
if (!isNode(step.value)) {
return false;
}
}
} else {
// Iterator will provide entry [k,v] tuples rather than values.
while (!(step = iterator.next()).done) {
var entry = step.value;
if (entry) {
if (!isNode(entry[1])) {
return false;
}
}
}
}
} else {
return false;
}
return true;
default:
return false;
}
}
function isSymbol(propType, propValue) {
// Native Symbol.
if (propType === 'symbol') {
return true;
}
// 19.4.3.5 Symbol.prototype[@@toStringTag] === 'Symbol'
if (propValue['@@toStringTag'] === 'Symbol') {
return true;
}
// Fallback for non-spec compliant Symbols which are polyfilled.
if (typeof Symbol === 'function' && propValue instanceof Symbol) {
return true;
}
return false;
}
// Equivalent of `typeof` but with special handling for array and regexp.
function getPropType(propValue) {
var propType = typeof propValue;
if (Array.isArray(propValue)) {
return 'array';
}
if (propValue instanceof RegExp) {
// Old webkits (at least until Android 4.0) return 'function' rather than
// 'object' for typeof a RegExp. We'll normalize this here so that /bla/
// passes PropTypes.object.
return 'object';
}
if (isSymbol(propType, propValue)) {
return 'symbol';
}
return propType;
}
// This handles more types than `getPropType`. Only used for error messages.
// See `createPrimitiveTypeChecker`.
function getPreciseType(propValue) {
var propType = getPropType(propValue);
if (propType === 'object') {
if (propValue instanceof Date) {
return 'date';
} else if (propValue instanceof RegExp) {
return 'regexp';
}
}
return propType;
}
// Returns class name of the object, if any.
function getClassName(propValue) {
if (!propValue.constructor || !propValue.constructor.name) {
return ANONYMOUS;
}
return propValue.constructor.name;
}
ReactPropTypes.checkPropTypes = checkPropTypes;
ReactPropTypes.PropTypes = ReactPropTypes;
return ReactPropTypes;
};
/***/ },
/* 35 */
/***/ function(module, exports) {
module.exports = __WEBPACK_EXTERNAL_MODULE_35__;
/***/ }
/******/ ])
});
;
;;
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.r = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;oHello World
;
* }
* });
*
* The class specification supports a specific protocol of methods that have
* special meaning (e.g. `render`). See `ReactClassInterface` for
* more the comprehensive protocol. Any other properties and methods in the
* class specification will be available on the prototype.
*
* @interface ReactClassInterface
* @internal
*/
var ReactClassInterface = {
/**
* An array of Mixin objects to include when defining your component.
*
* @type {array}
* @optional
*/
mixins: 'DEFINE_MANY',
/**
* An object containing properties and methods that should be defined on
* the component's constructor instead of its prototype (static methods).
*
* @type {object}
* @optional
*/
statics: 'DEFINE_MANY',
/**
* Definition of prop types for this component.
*
* @type {object}
* @optional
*/
propTypes: 'DEFINE_MANY',
/**
* Definition of context types for this component.
*
* @type {object}
* @optional
*/
contextTypes: 'DEFINE_MANY',
/**
* Definition of context types this component sets for its children.
*
* @type {object}
* @optional
*/
childContextTypes: 'DEFINE_MANY',
// ==== Definition methods ====
/**
* Invoked when the component is mounted. Values in the mapping will be set on
* `this.props` if that prop is not specified (i.e. using an `in` check).
*
* This method is invoked before `getInitialState` and therefore cannot rely
* on `this.state` or use `this.setState`.
*
* @return {object}
* @optional
*/
getDefaultProps: 'DEFINE_MANY_MERGED',
/**
* Invoked once before the component is mounted. The return value will be used
* as the initial value of `this.state`.
*
* getInitialState: function() {
* return {
* isOn: false,
* fooBaz: new BazFoo()
* }
* }
*
* @return {object}
* @optional
*/
getInitialState: 'DEFINE_MANY_MERGED',
/**
* @return {object}
* @optional
*/
getChildContext: 'DEFINE_MANY_MERGED',
/**
* Uses props from `this.props` and state from `this.state` to render the
* structure of the component.
*
* No guarantees are made about when or how often this method is invoked, so
* it must not have side effects.
*
* render: function() {
* var name = this.props.name;
* return
Hello, {name}!
;
* }
*
* @return {ReactComponent}
* @nosideeffects
* @required
*/
render: 'DEFINE_ONCE',
// ==== Delegate methods ====
/**
* Invoked when the component is initially created and about to be mounted.
* This may have side effects, but any external subscriptions or data created
* by this method must be cleaned up in `componentWillUnmount`.
*
* @optional
*/
componentWillMount: 'DEFINE_MANY',
/**
* Invoked when the component has been mounted and has a DOM representation.
* However, there is no guarantee that the DOM node is in the document.
*
* Use this as an opportunity to operate on the DOM when the component has
* been mounted (initialized and rendered) for the first time.
*
* @param {DOMElement} rootNode DOM element representing the component.
* @optional
*/
componentDidMount: 'DEFINE_MANY',
/**
* Invoked before the component receives new props.
*
* Use this as an opportunity to react to a prop transition by updating the
* state using `this.setState`. Current props are accessed via `this.props`.
*
* componentWillReceiveProps: function(nextProps, nextContext) {
* this.setState({
* likesIncreasing: nextProps.likeCount > this.props.likeCount
* });
* }
*
* NOTE: There is no equivalent `componentWillReceiveState`. An incoming prop
* transition may cause a state change, but the opposite is not true. If you
* need it, you are probably looking for `componentWillUpdate`.
*
* @param {object} nextProps
* @optional
*/
componentWillReceiveProps: 'DEFINE_MANY',
/**
* Invoked while deciding if the component should be updated as a result of
* receiving new props, state and/or context.
*
* Use this as an opportunity to `return false` when you're certain that the
* transition to the new props/state/context will not require a component
* update.
*
* shouldComponentUpdate: function(nextProps, nextState, nextContext) {
* return !equal(nextProps, this.props) ||
* !equal(nextState, this.state) ||
* !equal(nextContext, this.context);
* }
*
* @param {object} nextProps
* @param {?object} nextState
* @param {?object} nextContext
* @return {boolean} True if the component should update.
* @optional
*/
shouldComponentUpdate: 'DEFINE_ONCE',
/**
* Invoked when the component is about to update due to a transition from
* `this.props`, `this.state` and `this.context` to `nextProps`, `nextState`
* and `nextContext`.
*
* Use this as an opportunity to perform preparation before an update occurs.
*
* NOTE: You **cannot** use `this.setState()` in this method.
*
* @param {object} nextProps
* @param {?object} nextState
* @param {?object} nextContext
* @param {ReactReconcileTransaction} transaction
* @optional
*/
componentWillUpdate: 'DEFINE_MANY',
/**
* Invoked when the component's DOM representation has been updated.
*
* Use this as an opportunity to operate on the DOM when the component has
* been updated.
*
* @param {object} prevProps
* @param {?object} prevState
* @param {?object} prevContext
* @param {DOMElement} rootNode DOM element representing the component.
* @optional
*/
componentDidUpdate: 'DEFINE_MANY',
/**
* Invoked when the component is about to be removed from its parent and have
* its DOM representation destroyed.
*
* Use this as an opportunity to deallocate any external resources.
*
* NOTE: There is no `componentDidUnmount` since your component will have been
* destroyed by that point.
*
* @optional
*/
componentWillUnmount: 'DEFINE_MANY',
// ==== Advanced methods ====
/**
* Updates the component's currently mounted DOM representation.
*
* By default, this implements React's rendering and reconciliation algorithm.
* Sophisticated clients may wish to override this.
*
* @param {ReactReconcileTransaction} transaction
* @internal
* @overridable
*/
updateComponent: 'OVERRIDE_BASE'
};
/**
* Mapping from class specification keys to special processing functions.
*
* Although these are declared like instance properties in the specification
* when defining classes using `React.createClass`, they are actually static
* and are accessible on the constructor instead of the prototype. Despite
* being static, they must be defined outside of the "statics" key under
* which all other static methods are defined.
*/
var RESERVED_SPEC_KEYS = {
displayName: function (Constructor, displayName) {
Constructor.displayName = displayName;
},
mixins: function (Constructor, mixins) {
if (mixins) {
for (var i = 0; i < mixins.length; i++) {
mixSpecIntoComponent(Constructor, mixins[i]);
}
}
},
childContextTypes: function (Constructor, childContextTypes) {
if (process.env.NODE_ENV !== 'production') {
validateTypeDef(Constructor, childContextTypes, 'childContext');
}
Constructor.childContextTypes = _assign({}, Constructor.childContextTypes, childContextTypes);
},
contextTypes: function (Constructor, contextTypes) {
if (process.env.NODE_ENV !== 'production') {
validateTypeDef(Constructor, contextTypes, 'context');
}
Constructor.contextTypes = _assign({}, Constructor.contextTypes, contextTypes);
},
/**
* Special case getDefaultProps which should move into statics but requires
* automatic merging.
*/
getDefaultProps: function (Constructor, getDefaultProps) {
if (Constructor.getDefaultProps) {
Constructor.getDefaultProps = createMergedResultFunction(Constructor.getDefaultProps, getDefaultProps);
} else {
Constructor.getDefaultProps = getDefaultProps;
}
},
propTypes: function (Constructor, propTypes) {
if (process.env.NODE_ENV !== 'production') {
validateTypeDef(Constructor, propTypes, 'prop');
}
Constructor.propTypes = _assign({}, Constructor.propTypes, propTypes);
},
statics: function (Constructor, statics) {
mixStaticSpecIntoComponent(Constructor, statics);
},
autobind: function () {} };
function validateTypeDef(Constructor, typeDef, location) {
for (var propName in typeDef) {
if (typeDef.hasOwnProperty(propName)) {
// use a warning instead of an _invariant so components
// don't show up in prod but only in __DEV__
process.env.NODE_ENV !== 'production' ? warning(typeof typeDef[propName] === 'function', '%s: %s type `%s` is invalid; it must be a function, usually from ' + 'React.PropTypes.', Constructor.displayName || 'ReactClass', ReactPropTypeLocationNames[location], propName) : void 0;
}
}
}
function validateMethodOverride(isAlreadyDefined, name) {
var specPolicy = ReactClassInterface.hasOwnProperty(name) ? ReactClassInterface[name] : null;
// Disallow overriding of base class methods unless explicitly allowed.
if (ReactClassMixin.hasOwnProperty(name)) {
_invariant(specPolicy === 'OVERRIDE_BASE', 'ReactClassInterface: You are attempting to override ' + '`%s` from your class specification. Ensure that your method names ' + 'do not overlap with React methods.', name);
}
// Disallow defining methods more than once unless explicitly allowed.
if (isAlreadyDefined) {
_invariant(specPolicy === 'DEFINE_MANY' || specPolicy === 'DEFINE_MANY_MERGED', 'ReactClassInterface: You are attempting to define ' + '`%s` on your component more than once. This conflict may be due ' + 'to a mixin.', name);
}
}
/**
* Mixin helper which handles policy validation and reserved
* specification keys when building React classes.
*/
function mixSpecIntoComponent(Constructor, spec) {
if (!spec) {
if (process.env.NODE_ENV !== 'production') {
var typeofSpec = typeof spec;
var isMixinValid = typeofSpec === 'object' && spec !== null;
process.env.NODE_ENV !== 'production' ? warning(isMixinValid, '%s: You\'re attempting to include a mixin that is either null ' + 'or not an object. Check the mixins included by the component, ' + 'as well as any mixins they include themselves. ' + 'Expected object but got %s.', Constructor.displayName || 'ReactClass', spec === null ? null : typeofSpec) : void 0;
}
return;
}
_invariant(typeof spec !== 'function', 'ReactClass: You\'re attempting to ' + 'use a component class or function as a mixin. Instead, just use a ' + 'regular object.');
_invariant(!isValidElement(spec), 'ReactClass: You\'re attempting to ' + 'use a component as a mixin. Instead, just use a regular object.');
var proto = Constructor.prototype;
var autoBindPairs = proto.__reactAutoBindPairs;
// By handling mixins before any other properties, we ensure the same
// chaining order is applied to methods with DEFINE_MANY policy, whether
// mixins are listed before or after these methods in the spec.
if (spec.hasOwnProperty(MIXINS_KEY)) {
RESERVED_SPEC_KEYS.mixins(Constructor, spec.mixins);
}
for (var name in spec) {
if (!spec.hasOwnProperty(name)) {
continue;
}
if (name === MIXINS_KEY) {
// We have already handled mixins in a special case above.
continue;
}
var property = spec[name];
var isAlreadyDefined = proto.hasOwnProperty(name);
validateMethodOverride(isAlreadyDefined, name);
if (RESERVED_SPEC_KEYS.hasOwnProperty(name)) {
RESERVED_SPEC_KEYS[name](Constructor, property);
} else {
// Setup methods on prototype:
// The following member methods should not be automatically bound:
// 1. Expected ReactClass methods (in the "interface").
// 2. Overridden methods (that were mixed in).
var isReactClassMethod = ReactClassInterface.hasOwnProperty(name);
var isFunction = typeof property === 'function';
var shouldAutoBind = isFunction && !isReactClassMethod && !isAlreadyDefined && spec.autobind !== false;
if (shouldAutoBind) {
autoBindPairs.push(name, property);
proto[name] = property;
} else {
if (isAlreadyDefined) {
var specPolicy = ReactClassInterface[name];
// These cases should already be caught by validateMethodOverride.
_invariant(isReactClassMethod && (specPolicy === 'DEFINE_MANY_MERGED' || specPolicy === 'DEFINE_MANY'), 'ReactClass: Unexpected spec policy %s for key %s ' + 'when mixing in component specs.', specPolicy, name);
// For methods which are defined more than once, call the existing
// methods before calling the new property, merging if appropriate.
if (specPolicy === 'DEFINE_MANY_MERGED') {
proto[name] = createMergedResultFunction(proto[name], property);
} else if (specPolicy === 'DEFINE_MANY') {
proto[name] = createChainedFunction(proto[name], property);
}
} else {
proto[name] = property;
if (process.env.NODE_ENV !== 'production') {
// Add verbose displayName to the function, which helps when looking
// at profiling tools.
if (typeof property === 'function' && spec.displayName) {
proto[name].displayName = spec.displayName + '_' + name;
}
}
}
}
}
}
}
function mixStaticSpecIntoComponent(Constructor, statics) {
if (!statics) {
return;
}
for (var name in statics) {
var property = statics[name];
if (!statics.hasOwnProperty(name)) {
continue;
}
var isReserved = name in RESERVED_SPEC_KEYS;
_invariant(!isReserved, 'ReactClass: You are attempting to define a reserved ' + 'property, `%s`, that shouldn\'t be on the "statics" key. Define it ' + 'as an instance property instead; it will still be accessible on the ' + 'constructor.', name);
var isInherited = name in Constructor;
_invariant(!isInherited, 'ReactClass: You are attempting to define ' + '`%s` on your component more than once. This conflict may be ' + 'due to a mixin.', name);
Constructor[name] = property;
}
}
/**
* Merge two objects, but throw if both contain the same key.
*
* @param {object} one The first object, which is mutated.
* @param {object} two The second object
* @return {object} one after it has been mutated to contain everything in two.
*/
function mergeIntoWithNoDuplicateKeys(one, two) {
_invariant(one && two && typeof one === 'object' && typeof two === 'object', 'mergeIntoWithNoDuplicateKeys(): Cannot merge non-objects.');
for (var key in two) {
if (two.hasOwnProperty(key)) {
_invariant(one[key] === undefined, 'mergeIntoWithNoDuplicateKeys(): ' + 'Tried to merge two objects with the same key: `%s`. This conflict ' + 'may be due to a mixin; in particular, this may be caused by two ' + 'getInitialState() or getDefaultProps() methods returning objects ' + 'with clashing keys.', key);
one[key] = two[key];
}
}
return one;
}
/**
* Creates a function that invokes two functions and merges their return values.
*
* @param {function} one Function to invoke first.
* @param {function} two Function to invoke second.
* @return {function} Function that invokes the two argument functions.
* @private
*/
function createMergedResultFunction(one, two) {
return function mergedResult() {
var a = one.apply(this, arguments);
var b = two.apply(this, arguments);
if (a == null) {
return b;
} else if (b == null) {
return a;
}
var c = {};
mergeIntoWithNoDuplicateKeys(c, a);
mergeIntoWithNoDuplicateKeys(c, b);
return c;
};
}
/**
* Creates a function that invokes two functions and ignores their return vales.
*
* @param {function} one Function to invoke first.
* @param {function} two Function to invoke second.
* @return {function} Function that invokes the two argument functions.
* @private
*/
function createChainedFunction(one, two) {
return function chainedFunction() {
one.apply(this, arguments);
two.apply(this, arguments);
};
}
/**
* Binds a method to the component.
*
* @param {object} component Component whose method is going to be bound.
* @param {function} method Method to be bound.
* @return {function} The bound method.
*/
function bindAutoBindMethod(component, method) {
var boundMethod = method.bind(component);
if (process.env.NODE_ENV !== 'production') {
boundMethod.__reactBoundContext = component;
boundMethod.__reactBoundMethod = method;
boundMethod.__reactBoundArguments = null;
var componentName = component.constructor.displayName;
var _bind = boundMethod.bind;
boundMethod.bind = function (newThis) {
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
// User is trying to bind() an autobound method; we effectively will
// ignore the value of "this" that the user is trying to use, so
// let's warn.
if (newThis !== component && newThis !== null) {
process.env.NODE_ENV !== 'production' ? warning(false, 'bind(): React component methods may only be bound to the ' + 'component instance. See %s', componentName) : void 0;
} else if (!args.length) {
process.env.NODE_ENV !== 'production' ? warning(false, 'bind(): You are binding a component method to the component. ' + 'React does this for you automatically in a high-performance ' + 'way, so you can safely remove this call. See %s', componentName) : void 0;
return boundMethod;
}
var reboundMethod = _bind.apply(boundMethod, arguments);
reboundMethod.__reactBoundContext = component;
reboundMethod.__reactBoundMethod = method;
reboundMethod.__reactBoundArguments = args;
return reboundMethod;
};
}
return boundMethod;
}
/**
* Binds all auto-bound methods in a component.
*
* @param {object} component Component whose method is going to be bound.
*/
function bindAutoBindMethods(component) {
var pairs = component.__reactAutoBindPairs;
for (var i = 0; i < pairs.length; i += 2) {
var autoBindKey = pairs[i];
var method = pairs[i + 1];
component[autoBindKey] = bindAutoBindMethod(component, method);
}
}
var IsMountedMixin = {
componentDidMount: function () {
this.__isMounted = true;
},
componentWillUnmount: function () {
this.__isMounted = false;
}
};
/**
* Add more to the ReactClass base class. These are all legacy features and
* therefore not already part of the modern ReactComponent.
*/
var ReactClassMixin = {
/**
* TODO: This will be deprecated because state should always keep a consistent
* type signature and the only use case for this, is to avoid that.
*/
replaceState: function (newState, callback) {
this.updater.enqueueReplaceState(this, newState, callback);
},
/**
* Checks whether or not this composite component is mounted.
* @return {boolean} True if mounted, false otherwise.
* @protected
* @final
*/
isMounted: function () {
if (process.env.NODE_ENV !== 'production') {
process.env.NODE_ENV !== 'production' ? warning(this.__didWarnIsMounted, '%s: isMounted is deprecated. Instead, make sure to clean up ' + 'subscriptions and pending requests in componentWillUnmount to ' + 'prevent memory leaks.', this.constructor && this.constructor.displayName || this.name || 'Component') : void 0;
this.__didWarnIsMounted = true;
}
return !!this.__isMounted;
}
};
var ReactClassComponent = function () {};
_assign(ReactClassComponent.prototype, ReactComponent.prototype, ReactClassMixin);
/**
* Creates a composite component class given a class specification.
* See https://facebook.github.io/react/docs/top-level-api.html#react.createclass
*
* @param {object} spec Class specification (which must define `render`).
* @return {function} Component constructor function.
* @public
*/
function createClass(spec) {
// To keep our warnings more understandable, we'll use a little hack here to
// ensure that Constructor.name !== 'Constructor'. This makes sure we don't
// unnecessarily identify a class without displayName as 'Constructor'.
var Constructor = identity(function (props, context, updater) {
// This constructor gets overridden by mocks. The argument is used
// by mocks to assert on what gets mounted.
if (process.env.NODE_ENV !== 'production') {
process.env.NODE_ENV !== 'production' ? warning(this instanceof Constructor, 'Something is calling a React component directly. Use a factory or ' + 'JSX instead. See: https://fb.me/react-legacyfactory') : void 0;
}
// Wire up auto-binding
if (this.__reactAutoBindPairs.length) {
bindAutoBindMethods(this);
}
this.props = props;
this.context = context;
this.refs = emptyObject;
this.updater = updater || ReactNoopUpdateQueue;
this.state = null;
// ReactClasses doesn't have constructors. Instead, they use the
// getInitialState and componentWillMount methods for initialization.
var initialState = this.getInitialState ? this.getInitialState() : null;
if (process.env.NODE_ENV !== 'production') {
// We allow auto-mocks to proceed as if they're returning null.
if (initialState === undefined && this.getInitialState._isMockFunction) {
// This is probably bad practice. Consider warning here and
// deprecating this convenience.
initialState = null;
}
}
_invariant(typeof initialState === 'object' && !Array.isArray(initialState), '%s.getInitialState(): must return an object or null', Constructor.displayName || 'ReactCompositeComponent');
this.state = initialState;
});
Constructor.prototype = new ReactClassComponent();
Constructor.prototype.constructor = Constructor;
Constructor.prototype.__reactAutoBindPairs = [];
injectedMixins.forEach(mixSpecIntoComponent.bind(null, Constructor));
mixSpecIntoComponent(Constructor, IsMountedMixin);
mixSpecIntoComponent(Constructor, spec);
// Initialize the defaultProps property after all mixins have been merged.
if (Constructor.getDefaultProps) {
Constructor.defaultProps = Constructor.getDefaultProps();
}
if (process.env.NODE_ENV !== 'production') {
// This is a tag to indicate that the use of these method names is ok,
// since it's used with createClass. If it's not, then it's likely a
// mistake so we'll warn you to use the static property, property
// initializer or constructor respectively.
if (Constructor.getDefaultProps) {
Constructor.getDefaultProps.isReactClassApproved = {};
}
if (Constructor.prototype.getInitialState) {
Constructor.prototype.getInitialState.isReactClassApproved = {};
}
}
_invariant(Constructor.prototype.render, 'createClass(...): Class specification must implement a `render` method.');
if (process.env.NODE_ENV !== 'production') {
process.env.NODE_ENV !== 'production' ? warning(!Constructor.prototype.componentShouldUpdate, '%s has a method called ' + 'componentShouldUpdate(). Did you mean shouldComponentUpdate()? ' + 'The name is phrased as a question because the function is ' + 'expected to return a value.', spec.displayName || 'A component') : void 0;
process.env.NODE_ENV !== 'production' ? warning(!Constructor.prototype.componentWillRecieveProps, '%s has a method called ' + 'componentWillRecieveProps(). Did you mean componentWillReceiveProps()?', spec.displayName || 'A component') : void 0;
}
// Reduce time spent doing lookups by setting these on the prototype.
for (var methodName in ReactClassInterface) {
if (!Constructor.prototype[methodName]) {
Constructor.prototype[methodName] = null;
}
}
return Constructor;
}
return createClass;
}
module.exports = factory;
}).call(this,require('_process'))
},{"_process":8,"fbjs/lib/emptyObject":4,"fbjs/lib/invariant":5,"fbjs/lib/warning":6,"object-assign":7}],2:[function(require,module,exports){
(function (global){
/**
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
'use strict';
var React = (typeof window !== "undefined" ? window['React'] : typeof global !== "undefined" ? global['React'] : null);
var factory = require('./factory');
// Hack to grab NoopUpdateQueue from isomorphic React
var ReactNoopUpdateQueue = new React.Component().updater;
module.exports = factory(
React.Component,
React.isValidElement,
ReactNoopUpdateQueue
);
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{"./factory":1}],3:[function(require,module,exports){
"use strict";
/**
* Copyright (c) 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*
*/
function makeEmptyFunction(arg) {
return function () {
return arg;
};
}
/**
* This function accepts and discards inputs; it has no side effects. This is
* primarily useful idiomatically for overridable function endpoints which
* always need to be callable, since JS lacks a null-call idiom ala Cocoa.
*/
var emptyFunction = function emptyFunction() {};
emptyFunction.thatReturns = makeEmptyFunction;
emptyFunction.thatReturnsFalse = makeEmptyFunction(false);
emptyFunction.thatReturnsTrue = makeEmptyFunction(true);
emptyFunction.thatReturnsNull = makeEmptyFunction(null);
emptyFunction.thatReturnsThis = function () {
return this;
};
emptyFunction.thatReturnsArgument = function (arg) {
return arg;
};
module.exports = emptyFunction;
},{}],4:[function(require,module,exports){
(function (process){
/**
* Copyright (c) 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
'use strict';
var emptyObject = {};
if (process.env.NODE_ENV !== 'production') {
Object.freeze(emptyObject);
}
module.exports = emptyObject;
}).call(this,require('_process'))
},{"_process":8}],5:[function(require,module,exports){
(function (process){
/**
* Copyright (c) 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
'use strict';
/**
* Use invariant() to assert state which your program assumes to be true.
*
* Provide sprintf-style format (only %s is supported) and arguments
* to provide information about what broke and what you were
* expecting.
*
* The invariant message will be stripped in production, but the invariant
* will remain to ensure logic does not differ in production.
*/
var validateFormat = function validateFormat(format) {};
if (process.env.NODE_ENV !== 'production') {
validateFormat = function validateFormat(format) {
if (format === undefined) {
throw new Error('invariant requires an error message argument');
}
};
}
function invariant(condition, format, a, b, c, d, e, f) {
validateFormat(format);
if (!condition) {
var error;
if (format === undefined) {
error = new Error('Minified exception occurred; use the non-minified dev environment ' + 'for the full error message and additional helpful warnings.');
} else {
var args = [a, b, c, d, e, f];
var argIndex = 0;
error = new Error(format.replace(/%s/g, function () {
return args[argIndex++];
}));
error.name = 'Invariant Violation';
}
error.framesToPop = 1; // we don't care about invariant's own frame
throw error;
}
}
module.exports = invariant;
}).call(this,require('_process'))
},{"_process":8}],6:[function(require,module,exports){
(function (process){
/**
* Copyright 2014-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
'use strict';
var emptyFunction = require('./emptyFunction');
/**
* Similar to invariant but only logs a warning if the condition is not met.
* This can be used to log issues in development environments in critical
* paths. Removing the logging code for production environments will keep the
* same logic and follow the same code paths.
*/
var warning = emptyFunction;
if (process.env.NODE_ENV !== 'production') {
(function () {
var printWarning = function printWarning(format) {
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
var argIndex = 0;
var message = 'Warning: ' + format.replace(/%s/g, function () {
return args[argIndex++];
});
if (typeof console !== 'undefined') {
console.error(message);
}
try {
// --- Welcome to debugging React ---
// This error was thrown as a convenience so that you can use this stack
// to find the callsite that caused this warning to fire.
throw new Error(message);
} catch (x) {}
};
warning = function warning(condition, format) {
if (format === undefined) {
throw new Error('`warning(condition, format, ...args)` requires a warning ' + 'message argument');
}
if (format.indexOf('Failed Composite propType: ') === 0) {
return; // Ignore CompositeComponent proptype check.
}
if (!condition) {
for (var _len2 = arguments.length, args = Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
args[_key2 - 2] = arguments[_key2];
}
printWarning.apply(undefined, [format].concat(args));
}
};
})();
}
module.exports = warning;
}).call(this,require('_process'))
},{"./emptyFunction":3,"_process":8}],7:[function(require,module,exports){
/*
object-assign
(c) Sindre Sorhus
@license MIT
*/
'use strict';
/* eslint-disable no-unused-vars */
var getOwnPropertySymbols = Object.getOwnPropertySymbols;
var hasOwnProperty = Object.prototype.hasOwnProperty;
var propIsEnumerable = Object.prototype.propertyIsEnumerable;
function toObject(val) {
if (val === null || val === undefined) {
throw new TypeError('Object.assign cannot be called with null or undefined');
}
return Object(val);
}
function shouldUseNative() {
try {
if (!Object.assign) {
return false;
}
// Detect buggy property enumeration order in older V8 versions.
// https://bugs.chromium.org/p/v8/issues/detail?id=4118
var test1 = new String('abc'); // eslint-disable-line no-new-wrappers
test1[5] = 'de';
if (Object.getOwnPropertyNames(test1)[0] === '5') {
return false;
}
// https://bugs.chromium.org/p/v8/issues/detail?id=3056
var test2 = {};
for (var i = 0; i < 10; i++) {
test2['_' + String.fromCharCode(i)] = i;
}
var order2 = Object.getOwnPropertyNames(test2).map(function (n) {
return test2[n];
});
if (order2.join('') !== '0123456789') {
return false;
}
// https://bugs.chromium.org/p/v8/issues/detail?id=3056
var test3 = {};
'abcdefghijklmnopqrst'.split('').forEach(function (letter) {
test3[letter] = letter;
});
if (Object.keys(Object.assign({}, test3)).join('') !==
'abcdefghijklmnopqrst') {
return false;
}
return true;
} catch (err) {
// We don't expect any of the above to throw, but better to be safe.
return false;
}
}
module.exports = shouldUseNative() ? Object.assign : function (target, source) {
var from;
var to = toObject(target);
var symbols;
for (var s = 1; s < arguments.length; s++) {
from = Object(arguments[s]);
for (var key in from) {
if (hasOwnProperty.call(from, key)) {
to[key] = from[key];
}
}
if (getOwnPropertySymbols) {
symbols = getOwnPropertySymbols(from);
for (var i = 0; i < symbols.length; i++) {
if (propIsEnumerable.call(from, symbols[i])) {
to[symbols[i]] = from[symbols[i]];
}
}
}
}
return to;
};
},{}],8:[function(require,module,exports){
// shim for using process in browser
var process = module.exports = {};
// cached from whatever global is present so that test runners that stub it
// don't break things. But we need to wrap it in a try catch in case it is
// wrapped in strict mode code which doesn't define any globals. It's inside a
// function because try/catches deoptimize in certain engines.
var cachedSetTimeout;
var cachedClearTimeout;
function defaultSetTimout() {
throw new Error('setTimeout has not been defined');
}
function defaultClearTimeout () {
throw new Error('clearTimeout has not been defined');
}
(function () {
try {
if (typeof setTimeout === 'function') {
cachedSetTimeout = setTimeout;
} else {
cachedSetTimeout = defaultSetTimout;
}
} catch (e) {
cachedSetTimeout = defaultSetTimout;
}
try {
if (typeof clearTimeout === 'function') {
cachedClearTimeout = clearTimeout;
} else {
cachedClearTimeout = defaultClearTimeout;
}
} catch (e) {
cachedClearTimeout = defaultClearTimeout;
}
} ())
function runTimeout(fun) {
if (cachedSetTimeout === setTimeout) {
//normal enviroments in sane situations
return setTimeout(fun, 0);
}
// if setTimeout wasn't available but was latter defined
if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
cachedSetTimeout = setTimeout;
return setTimeout(fun, 0);
}
try {
// when when somebody has screwed with setTimeout but no I.E. maddness
return cachedSetTimeout(fun, 0);
} catch(e){
try {
// When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
return cachedSetTimeout.call(null, fun, 0);
} catch(e){
// same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
return cachedSetTimeout.call(this, fun, 0);
}
}
}
function runClearTimeout(marker) {
if (cachedClearTimeout === clearTimeout) {
//normal enviroments in sane situations
return clearTimeout(marker);
}
// if clearTimeout wasn't available but was latter defined
if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
cachedClearTimeout = clearTimeout;
return clearTimeout(marker);
}
try {
// when when somebody has screwed with setTimeout but no I.E. maddness
return cachedClearTimeout(marker);
} catch (e){
try {
// When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
return cachedClearTimeout.call(null, marker);
} catch (e){
// same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
// Some versions of I.E. have different rules for clearTimeout vs setTimeout
return cachedClearTimeout.call(this, marker);
}
}
}
var queue = [];
var draining = false;
var currentQueue;
var queueIndex = -1;
function cleanUpNextTick() {
if (!draining || !currentQueue) {
return;
}
draining = false;
if (currentQueue.length) {
queue = currentQueue.concat(queue);
} else {
queueIndex = -1;
}
if (queue.length) {
drainQueue();
}
}
function drainQueue() {
if (draining) {
return;
}
var timeout = runTimeout(cleanUpNextTick);
draining = true;
var len = queue.length;
while(len) {
currentQueue = queue;
queue = [];
while (++queueIndex < len) {
if (currentQueue) {
currentQueue[queueIndex].run();
}
}
queueIndex = -1;
len = queue.length;
}
currentQueue = null;
draining = false;
runClearTimeout(timeout);
}
process.nextTick = function (fun) {
var args = new Array(arguments.length - 1);
if (arguments.length > 1) {
for (var i = 1; i < arguments.length; i++) {
args[i - 1] = arguments[i];
}
}
queue.push(new Item(fun, args));
if (queue.length === 1 && !draining) {
runTimeout(drainQueue);
}
};
// v8 likes predictible objects
function Item(fun, array) {
this.fun = fun;
this.array = array;
}
Item.prototype.run = function () {
this.fun.apply(null, this.array);
};
process.title = 'browser';
process.browser = true;
process.env = {};
process.argv = [];
process.version = ''; // empty string to avoid regexp issues
process.versions = {};
function noop() {}
process.on = noop;
process.addListener = noop;
process.once = noop;
process.off = noop;
process.removeListener = noop;
process.removeAllListeners = noop;
process.emit = noop;
process.prependListener = noop;
process.prependOnceListener = noop;
process.listeners = function (name) { return [] }
process.binding = function (name) {
throw new Error('process.binding is not supported');
};
process.cwd = function () { return '/' };
process.chdir = function (dir) {
throw new Error('process.chdir is not supported');
};
process.umask = function() { return 0; };
},{}]},{},[2])(2)
});
;;
// @include lib/react.js
// @include lib/rdom.js
// @include lib/create-react-class.js
var ModalTitle = createReactClass({
displayName: 'ModalTitle',
render: function() {
return r.div({ className: this.props.className || 'modal-header text-left' },
this.props.children ? this.props.children : [
r.button({ type: 'button', className: 'close', 'data-dismiss': 'modal' },
r.span('×')
),
r.h2({ className: 'modal-title' }, this.props.title)
]
)
}
})
var ModalBody = createReactClass({
displayName: 'ModalBody',
render: function() {
return r.div({className: 'modal-body clearfix'}, this.props.children)
}
})
var ModalFooter = createReactClass({
displayName: 'ModalFooter',
defaultButtons: [{ text: 'Close' }],
render: function() {
return r.div({ className: this.props.className || 'modal-footer' },
this.props.children ? this.props.children :
(this.props.buttons || this.defaultButtons).map(function(button) {
var dataDismiss = "modal";
if (button.dataDismiss) {
dataDismiss = button.dataDismiss;
}
if (button.loading !== undefined) {
return !button.loading ? null :
r.span({ className: 'fa fa-2x fa-spinner fa-pulse fa-fw vertical-middle' })
}
return r.button({
type: 'button',
disabled: button.disabled,
className: 'btn '+ (button.className || 'btn-default'),
'data-dismiss': dataDismiss,
onClick: !button.disabled ? button.onClick : undefined
}, button.text)
})
)
}
})
var Modal = createReactClass({
componentDidMount: function() {
$(this.modal).modal(this.props.modalOptions)
if (this.props.onHide)
$(this.modal).on('hidden.bs.modal', this.props.onHide)
if (this.props.onShow){
$(this.modal).on('shown.bs.modal',this.props.onShow())
}
},
componentWillUnmount: function() {
$(this.modal).off()
$(this.modal).modal('hide')
},
componentDidUpdate: function() {
if (this.props.modalOptions && this.props.modalOptions.show === true) {
$(this.modal).modal('show')
}else{
$(this.modal).modal('hide')
}
},
render: function() {
var self = this
return r.div({
id : this.props.id,
className: 'modal fade-into ' + (this.props.className || ''),
ref: function(modal) { self.modal = modal }
},
r.div({ className: 'modal-dialog ' + (this.props.modalSmall ? 'modal-sm' : '') },
r.div({ className: 'modal-content' },
this.props.children
)
)
)
}
})
;;
// @include lib/react.js
// @include lib/rdom.js
// @include lib/create-react-class.js
/**
* This creates a popover that uses tether to position it over an element
*
* Example usage:
var popoverContainer = document.createElement('div')
ReactDOM.render(
r(Popover, {
orient: 'bottom',
target: '.presentation-title', attachment: 'top center', targetAttachment: 'bottom center'
}, [
r.div({ className: 'arrow' }),
r.h3({ className: 'popover-title' }, 'Popover bottom'),
r.div({ className: 'popover-content' }, [
r.span('This is some popover content')
])
]), popoverContainer)
document.body.appendChild(popoverContainer)
*/
/* NOTE:
* If you're rendering a component that's a popover using ReactDOM.render, make sure that it's
* container is attached to the DOM. Otherwise ReactDOM.unmountComponentAtNode won't remove the
* contents correctly
*/
var Popover = createReactClass({
displayName: 'Popover',
destroyPopover: function() {
if (this.tether) {
this.tether.destroy();
$(this.tether.element).remove()
}
},
componentDidMount: function() {
this.tether = new Tether({
element: this.refs.popover,
target: this.props.target,
attachment: this.props.attachment,
targetAttachment: this.props.targetAttachment,
offset: this.props.offset || '0 0',
constraints: this.props.constraints
});
if (this.props.tether && this.refs.popover && this.props.target){
this.props.tether(this.tether)
}
},
componentWillUnmount: function() {
this.destroyPopover()
},
render: function() {
var style = $.extend(this.props.noDisplay ? {} : {display: 'block'}, this.props.style);
return r.div({
ref: 'popover',
style: style,
className: 'popover '+ this.props.orient +' '+ (this.props.className || '')
}, this.props.children)
}
});
;;
/*!
* typeahead.js 0.11.1
* https://github.com/twitter/typeahead.js
* Copyright 2013-2015 Twitter, Inc. and other contributors; Licensed MIT
*/
!function(a,b){"function"==typeof define&&define.amd?define("bloodhound",["jquery"],function(c){return a.Bloodhound=b(c)}):"object"==typeof exports?module.exports=b(require("jquery")):a.Bloodhound=b(jQuery)}(this,function(a){var b=function(){"use strict";return{isMsie:function(){return/(msie|trident)/i.test(navigator.userAgent)?navigator.userAgent.match(/(msie |rv:)(\d+(.\d+)?)/i)[2]:!1},isBlankString:function(a){return!a||/^\s*$/.test(a)},escapeRegExChars:function(a){return a.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")},isString:function(a){return"string"==typeof a},isNumber:function(a){return"number"==typeof a},isArray:a.isArray,isFunction:a.isFunction,isObject:a.isPlainObject,isUndefined:function(a){return"undefined"==typeof a},isElement:function(a){return!(!a||1!==a.nodeType)},isJQuery:function(b){return b instanceof a},toStr:function(a){return b.isUndefined(a)||null===a?"":a+""},bind:a.proxy,each:function(b,c){function d(a,b){return c(b,a)}a.each(b,d)},map:a.map,filter:a.grep,every:function(b,c){var d=!0;return b?(a.each(b,function(a,e){return(d=c.call(null,e,a,b))?void 0:!1}),!!d):d},some:function(b,c){var d=!1;return b?(a.each(b,function(a,e){return(d=c.call(null,e,a,b))?!1:void 0}),!!d):d},mixin:a.extend,identity:function(a){return a},clone:function(b){return a.extend(!0,{},b)},getIdGenerator:function(){var a=0;return function(){return a++}},templatify:function(b){function c(){return String(b)}return a.isFunction(b)?b:c},defer:function(a){setTimeout(a,0)},debounce:function(a,b,c){var d,e;return function(){var f,g,h=this,i=arguments;return f=function(){d=null,c||(e=a.apply(h,i))},g=c&&!d,clearTimeout(d),d=setTimeout(f,b),g&&(e=a.apply(h,i)),e}},throttle:function(a,b){var c,d,e,f,g,h;return g=0,h=function(){g=new Date,e=null,f=a.apply(c,d)},function(){var i=new Date,j=b-(i-g);return c=this,d=arguments,0>=j?(clearTimeout(e),e=null,g=i,f=a.apply(c,d)):e||(e=setTimeout(h,j)),f}},stringify:function(a){return b.isString(a)?a:JSON.stringify(a)},noop:function(){}}}(),c="0.11.1",d=function(){"use strict";function a(a){return a=b.toStr(a),a?a.split(/\s+/):[]}function c(a){return a=b.toStr(a),a?a.split(/\W+/):[]}function d(a){return function(c){return c=b.isArray(c)?c:[].slice.call(arguments,0),function(d){var e=[];return b.each(c,function(c){e=e.concat(a(b.toStr(d[c])))}),e}}}return{nonword:c,whitespace:a,obj:{nonword:d(c),whitespace:d(a)}}}(),e=function(){"use strict";function c(c){this.maxSize=b.isNumber(c)?c:100,this.reset(),this.maxSize<=0&&(this.set=this.get=a.noop)}function d(){this.head=this.tail=null}function e(a,b){this.key=a,this.val=b,this.prev=this.next=null}return b.mixin(c.prototype,{set:function(a,b){var c,d=this.list.tail;this.size>=this.maxSize&&(this.list.remove(d),delete this.hash[d.key],this.size--),(c=this.hash[a])?(c.val=b,this.list.moveToFront(c)):(c=new e(a,b),this.list.add(c),this.hash[a]=c,this.size++)},get:function(a){var b=this.hash[a];return b?(this.list.moveToFront(b),b.val):void 0},reset:function(){this.size=0,this.hash={},this.list=new d}}),b.mixin(d.prototype,{add:function(a){this.head&&(a.next=this.head,this.head.prev=a),this.head=a,this.tail=this.tail||a},remove:function(a){a.prev?a.prev.next=a.next:this.head=a.next,a.next?a.next.prev=a.prev:this.tail=a.prev},moveToFront:function(a){this.remove(a),this.add(a)}}),c}(),f=function(){"use strict";function c(a,c){this.prefix=["__",a,"__"].join(""),this.ttlKey="__ttl__",this.keyMatcher=new RegExp("^"+b.escapeRegExChars(this.prefix)),this.ls=c||h,!this.ls&&this._noop()}function d(){return(new Date).getTime()}function e(a){return JSON.stringify(b.isUndefined(a)?null:a)}function f(b){return a.parseJSON(b)}function g(a){var b,c,d=[],e=h.length;for(b=0;e>b;b++)(c=h.key(b)).match(a)&&d.push(c.replace(a,""));return d}var h;try{h=window.localStorage,h.setItem("~~~","!"),h.removeItem("~~~")}catch(i){h=null}return b.mixin(c.prototype,{_prefix:function(a){return this.prefix+a},_ttlKey:function(a){return this._prefix(a)+this.ttlKey},_noop:function(){this.get=this.set=this.remove=this.clear=this.isExpired=b.noop},_safeSet:function(a,b){try{this.ls.setItem(a,b)}catch(c){"QuotaExceededError"===c.name&&(this.clear(),this._noop())}},get:function(a){return this.isExpired(a)&&this.remove(a),f(this.ls.getItem(this._prefix(a)))},set:function(a,c,f){return b.isNumber(f)?this._safeSet(this._ttlKey(a),e(d()+f)):this.ls.removeItem(this._ttlKey(a)),this._safeSet(this._prefix(a),e(c))},remove:function(a){return this.ls.removeItem(this._ttlKey(a)),this.ls.removeItem(this._prefix(a)),this},clear:function(){var a,b=g(this.keyMatcher);for(a=b.length;a--;)this.remove(b[a]);return this},isExpired:function(a){var c=f(this.ls.getItem(this._ttlKey(a)));return b.isNumber(c)&&d()>c?!0:!1}}),c}(),g=function(){"use strict";function c(a){a=a||{},this.cancelled=!1,this.lastReq=null,this._send=a.transport,this._get=a.limiter?a.limiter(this._get):this._get,this._cache=a.cache===!1?new e(0):h}var d=0,f={},g=6,h=new e(10);return c.setMaxPendingRequests=function(a){g=a},c.resetCache=function(){h.reset()},b.mixin(c.prototype,{_fingerprint:function(b){return b=b||{},b.url+b.type+a.param(b.data||{})},_get:function(a,b){function c(a){b(null,a),k._cache.set(i,a)}function e(){b(!0)}function h(){d--,delete f[i],k.onDeckRequestArgs&&(k._get.apply(k,k.onDeckRequestArgs),k.onDeckRequestArgs=null)}var i,j,k=this;i=this._fingerprint(a),this.cancelled||i!==this.lastReq||((j=f[i])?j.done(c).fail(e):g>d?(d++,f[i]=this._send(a).done(c).fail(e).always(h)):this.onDeckRequestArgs=[].slice.call(arguments,0))},get:function(c,d){var e,f;d=d||a.noop,c=b.isString(c)?{url:c}:c||{},f=this._fingerprint(c),this.cancelled=!1,this.lastReq=f,(e=this._cache.get(f))?d(null,e):this._get(c,d)},cancel:function(){this.cancelled=!0}}),c}(),h=window.SearchIndex=function(){"use strict";function c(c){c=c||{},c.datumTokenizer&&c.queryTokenizer||a.error("datumTokenizer and queryTokenizer are both required"),this.identify=c.identify||b.stringify,this.datumTokenizer=c.datumTokenizer,this.queryTokenizer=c.queryTokenizer,this.reset()}function d(a){return a=b.filter(a,function(a){return!!a}),a=b.map(a,function(a){return a.toLowerCase()})}function e(){var a={};return a[i]=[],a[h]={},a}function f(a){for(var b={},c=[],d=0,e=a.length;e>d;d++)b[a[d]]||(b[a[d]]=!0,c.push(a[d]));return c}function g(a,b){var c=0,d=0,e=[];a=a.sort(),b=b.sort();for(var f=a.length,g=b.length;f>c&&g>d;)a[c]b[d]?d++:(e.push(a[c]),c++,d++);return e}var h="c",i="i";return b.mixin(c.prototype,{bootstrap:function(a){this.datums=a.datums,this.trie=a.trie},add:function(a){var c=this;a=b.isArray(a)?a:[a],b.each(a,function(a){var f,g;c.datums[f=c.identify(a)]=a,g=d(c.datumTokenizer(a)),b.each(g,function(a){var b,d,g;for(b=c.trie,d=a.split("");g=d.shift();)b=b[h][g]||(b[h][g]=e()),b[i].push(f)})})},get:function(a){var c=this;return b.map(a,function(a){return c.datums[a]})},search:function(a){var c,e,j=this;return c=d(this.queryTokenizer(a)),b.each(c,function(a){var b,c,d,f;if(e&&0===e.length)return!1;for(b=j.trie,c=a.split("");b&&(d=c.shift());)b=b[h][d];return b&&0===c.length?(f=b[i].slice(0),void(e=e?g(e,f):f)):(e=[],!1)}),e?b.map(f(e),function(a){return j.datums[a]}):[]},all:function(){var a=[];for(var b in this.datums)a.push(this.datums[b]);return a},reset:function(){this.datums={},this.trie=e()},serialize:function(){return{datums:this.datums,trie:this.trie}}}),c}(),i=function(){"use strict";function a(a){this.url=a.url,this.ttl=a.ttl,this.cache=a.cache,this.prepare=a.prepare,this.transform=a.transform,this.transport=a.transport,this.thumbprint=a.thumbprint,this.storage=new f(a.cacheKey)}var c;return c={data:"data",protocol:"protocol",thumbprint:"thumbprint"},b.mixin(a.prototype,{_settings:function(){return{url:this.url,type:"GET",dataType:"json"}},store:function(a){this.cache&&(this.storage.set(c.data,a,this.ttl),this.storage.set(c.protocol,location.protocol,this.ttl),this.storage.set(c.thumbprint,this.thumbprint,this.ttl))},fromCache:function(){var a,b={};return this.cache?(b.data=this.storage.get(c.data),b.protocol=this.storage.get(c.protocol),b.thumbprint=this.storage.get(c.thumbprint),a=b.thumbprint!==this.thumbprint||b.protocol!==location.protocol,b.data&&!a?b.data:null):null},fromNetwork:function(a){function b(){a(!0)}function c(b){a(null,e.transform(b))}var d,e=this;a&&(d=this.prepare(this._settings()),this.transport(d).fail(b).done(c))},clear:function(){return this.storage.clear(),this}}),a}(),j=function(){"use strict";function a(a){this.url=a.url,this.prepare=a.prepare,this.transform=a.transform,this.transport=new g({cache:a.cache,limiter:a.limiter,transport:a.transport})}return b.mixin(a.prototype,{_settings:function(){return{url:this.url,type:"GET",dataType:"json"}},get:function(a,b){function c(a,c){b(a?[]:e.transform(c))}var d,e=this;if(b)return a=a||"",d=this.prepare(a,this._settings()),this.transport.get(d,c)},cancelLastRequest:function(){this.transport.cancel()}}),a}(),k=function(){"use strict";function d(d){var e;return d?(e={url:null,ttl:864e5,cache:!0,cacheKey:null,thumbprint:"",prepare:b.identity,transform:b.identity,transport:null},d=b.isString(d)?{url:d}:d,d=b.mixin(e,d),!d.url&&a.error("prefetch requires url to be set"),d.transform=d.filter||d.transform,d.cacheKey=d.cacheKey||d.url,d.thumbprint=c+d.thumbprint,d.transport=d.transport?h(d.transport):a.ajax,d):null}function e(c){var d;if(c)return d={url:null,cache:!0,prepare:null,replace:null,wildcard:null,limiter:null,rateLimitBy:"debounce",rateLimitWait:300,transform:b.identity,transport:null},c=b.isString(c)?{url:c}:c,c=b.mixin(d,c),!c.url&&a.error("remote requires url to be set"),c.transform=c.filter||c.transform,c.prepare=f(c),c.limiter=g(c),c.transport=c.transport?h(c.transport):a.ajax,delete c.replace,delete c.wildcard,delete c.rateLimitBy,delete c.rateLimitWait,c}function f(a){function b(a,b){return b.url=f(b.url,a),b}function c(a,b){return b.url=b.url.replace(g,encodeURIComponent(a)),b}function d(a,b){return b}var e,f,g;return e=a.prepare,f=a.replace,g=a.wildcard,e?e:e=f?b:a.wildcard?c:d}function g(a){function c(a){return function(c){return b.debounce(c,a)}}function d(a){return function(c){return b.throttle(c,a)}}var e,f,g;return e=a.limiter,f=a.rateLimitBy,g=a.rateLimitWait,e||(e=/^throttle$/i.test(f)?d(g):c(g)),e}function h(c){return function(d){function e(a){b.defer(function(){g.resolve(a)})}function f(a){b.defer(function(){g.reject(a)})}var g=a.Deferred();return c(d,e,f),g}}return function(c){var f,g;return f={initialize:!0,identify:b.stringify,datumTokenizer:null,queryTokenizer:null,sufficient:5,sorter:null,local:[],prefetch:null,remote:null},c=b.mixin(f,c||{}),!c.datumTokenizer&&a.error("datumTokenizer is required"),!c.queryTokenizer&&a.error("queryTokenizer is required"),g=c.sorter,c.sorter=g?function(a){return a.sort(g)}:b.identity,c.local=b.isFunction(c.local)?c.local():c.local,c.prefetch=d(c.prefetch),c.remote=e(c.remote),c}}(),l=function(){"use strict";function c(a){a=k(a),this.sorter=a.sorter,this.identify=a.identify,this.sufficient=a.sufficient,this.local=a.local,this.remote=a.remote?new j(a.remote):null,this.prefetch=a.prefetch?new i(a.prefetch):null,this.index=new h({identify:this.identify,datumTokenizer:a.datumTokenizer,queryTokenizer:a.queryTokenizer}),a.initialize!==!1&&this.initialize()}var e;return e=window&&window.Bloodhound,c.noConflict=function(){return window&&(window.Bloodhound=e),c},c.tokenizers=d,b.mixin(c.prototype,{__ttAdapter:function(){function a(a,b,d){return c.search(a,b,d)}function b(a,b){return c.search(a,b)}var c=this;return this.remote?a:b},_loadPrefetch:function(){function b(a,b){return a?c.reject():(e.add(b),e.prefetch.store(e.index.serialize()),void c.resolve())}var c,d,e=this;return c=a.Deferred(),this.prefetch?(d=this.prefetch.fromCache())?(this.index.bootstrap(d),c.resolve()):this.prefetch.fromNetwork(b):c.resolve(),c.promise()},_initialize:function(){function a(){b.add(b.local)}var b=this;return this.clear(),(this.initPromise=this._loadPrefetch()).done(a),this.initPromise},initialize:function(a){return!this.initPromise||a?this._initialize():this.initPromise},add:function(a){return this.index.add(a),this},get:function(a){return a=b.isArray(a)?a:[].slice.call(arguments),this.index.get(a)},search:function(a,c,d){function e(a){var c=[];b.each(a,function(a){!b.some(f,function(b){return g.identify(a)===g.identify(b)})&&c.push(a)}),d&&d(c)}var f,g=this;return f=this.sorter(this.index.search(a)),c(this.remote?f.slice():f),this.remote&&f.length=j?(clearTimeout(e),e=null,g=i,f=a.apply(c,d)):e||(e=setTimeout(h,j)),f}},stringify:function(a){return b.isString(a)?a:JSON.stringify(a)},noop:function(){}}}(),c=function(){"use strict";function a(a){var g,h;return h=b.mixin({},f,a),g={css:e(),classes:h,html:c(h),selectors:d(h)},{css:g.css,html:g.html,classes:g.classes,selectors:g.selectors,mixin:function(a){b.mixin(a,g)}}}function c(a){return{wrapper:'',menu:''}}function d(a){var c={};return b.each(a,function(a,b){c[b]="."+a}),c}function e(){var a={wrapper:{position:"relative",display:"inline-block"},hint:{position:"absolute",top:"0",left:"0",borderColor:"transparent",boxShadow:"none",opacity:"1"},input:{position:"relative",verticalAlign:"top",backgroundColor:"transparent"},inputWithNoHint:{position:"relative",verticalAlign:"top"},menu:{position:"absolute",top:"100%",left:"0",zIndex:"100",display:"none"},ltr:{left:"0",right:"auto"},rtl:{left:"auto",right:" 0"}};return b.isMsie()&&b.mixin(a.input,{backgroundImage:"url(data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)"}),a}var f={wrapper:"twitter-typeahead",input:"tt-input",hint:"tt-hint",menu:"tt-menu",dataset:"tt-dataset",suggestion:"tt-suggestion",selectable:"tt-selectable",empty:"tt-empty",open:"tt-open",cursor:"tt-cursor",highlight:"tt-highlight"};return a}(),d=function(){"use strict";function c(b){b&&b.el||a.error("EventBus initialized without el"),this.$el=a(b.el)}var d,e;return d="typeahead:",e={render:"rendered",cursorchange:"cursorchanged",select:"selected",autocomplete:"autocompleted"},b.mixin(c.prototype,{_trigger:function(b,c){var e;return e=a.Event(d+b),(c=c||[]).unshift(e),this.$el.trigger.apply(this.$el,c),e},before:function(a){var b,c;return b=[].slice.call(arguments,1),c=this._trigger("before"+a,b),c.isDefaultPrevented()},trigger:function(a){var b;this._trigger(a,[].slice.call(arguments,1)),(b=e[a])&&this._trigger(b,[].slice.call(arguments,1))}}),c}(),e=function(){"use strict";function a(a,b,c,d){var e;if(!c)return this;for(b=b.split(i),c=d?h(c,d):c,this._callbacks=this._callbacks||{};e=b.shift();)this._callbacks[e]=this._callbacks[e]||{sync:[],async:[]},this._callbacks[e][a].push(c);return this}function b(b,c,d){return a.call(this,"async",b,c,d)}function c(b,c,d){return a.call(this,"sync",b,c,d)}function d(a){var b;if(!this._callbacks)return this;for(a=a.split(i);b=a.shift();)delete this._callbacks[b];return this}function e(a){var b,c,d,e,g;if(!this._callbacks)return this;for(a=a.split(i),d=[].slice.call(arguments,1);(b=a.shift())&&(c=this._callbacks[b]);)e=f(c.sync,this,[b].concat(d)),g=f(c.async,this,[b].concat(d)),e()&&j(g);return this}function f(a,b,c){function d(){for(var d,e=0,f=a.length;!d&&f>e;e+=1)d=a[e].apply(b,c)===!1;return!d}return d}function g(){var a;return a=window.setImmediate?function(a){setImmediate(function(){a()})}:function(a){setTimeout(function(){a()},0)}}function h(a,b){return a.bind?a.bind(b):function(){a.apply(b,[].slice.call(arguments,0))}}var i=/\s+/,j=g();return{onSync:c,onAsync:b,off:d,trigger:e}}(),f=function(a){"use strict";function c(a,c,d){for(var e,f=[],g=0,h=a.length;h>g;g++)f.push(b.escapeRegExChars(a[g]));return e=d?"\\b("+f.join("|")+")\\b":"("+f.join("|")+")",c?new RegExp(e):new RegExp(e,"i")}var d={node:null,pattern:null,tagName:"strong",className:null,wordsOnly:!1,caseSensitive:!1};return function(e){function f(b){var c,d,f;return(c=h.exec(b.data))&&(f=a.createElement(e.tagName),e.className&&(f.className=e.className),d=b.splitText(c.index),d.splitText(c[0].length),f.appendChild(d.cloneNode(!0)),b.parentNode.replaceChild(f,d)),!!c}function g(a,b){for(var c,d=3,e=0;e').css({position:"absolute",visibility:"hidden",whiteSpace:"pre",fontFamily:b.css("font-family"),fontSize:b.css("font-size"),fontStyle:b.css("font-style"),fontVariant:b.css("font-variant"),fontWeight:b.css("font-weight"),wordSpacing:b.css("word-spacing"),letterSpacing:b.css("letter-spacing"),textIndent:b.css("text-indent"),textRendering:b.css("text-rendering"),textTransform:b.css("text-transform")}).insertAfter(b)}function f(a,b){return c.normalizeQuery(a)===c.normalizeQuery(b)}function g(a){return a.altKey||a.ctrlKey||a.metaKey||a.shiftKey}var h;return h={9:"tab",27:"esc",37:"left",39:"right",13:"enter",38:"up",40:"down"},c.normalizeQuery=function(a){return b.toStr(a).replace(/^\s*/g,"").replace(/\s{2,}/g," ")},b.mixin(c.prototype,e,{_onBlur:function(){this.resetInputValue(),this.trigger("blurred")},_onFocus:function(){this.queryWhenFocused=this.query,this.trigger("focused")},_onKeydown:function(a){var b=h[a.which||a.keyCode];this._managePreventDefault(b,a),b&&this._shouldTrigger(b,a)&&this.trigger(b+"Keyed",a)},_onInput:function(){this._setQuery(this.getInputValue()),this.clearHintIfInvalid(),this._checkLanguageDirection()},_managePreventDefault:function(a,b){var c;switch(a){case"up":case"down":c=!g(b);break;default:c=!1}c&&b.preventDefault()},_shouldTrigger:function(a,b){var c;switch(a){case"tab":c=!g(b);break;default:c=!0}return c},_checkLanguageDirection:function(){var a=(this.$input.css("direction")||"ltr").toLowerCase();this.dir!==a&&(this.dir=a,this.$hint.attr("dir",a),this.trigger("langDirChanged",a))},_setQuery:function(a,b){var c,d;c=f(a,this.query),d=c?this.query.length!==a.length:!1,this.query=a,b||c?!b&&d&&this.trigger("whitespaceChanged",this.query):this.trigger("queryChanged",this.query)},bind:function(){var a,c,d,e,f=this;return a=b.bind(this._onBlur,this),c=b.bind(this._onFocus,this),d=b.bind(this._onKeydown,this),e=b.bind(this._onInput,this),this.$input.on("blur.tt",a).on("focus.tt",c).on("keydown.tt",d),!b.isMsie()||b.isMsie()>9?this.$input.on("input.tt",e):this.$input.on("keydown.tt keypress.tt cut.tt paste.tt",function(a){h[a.which||a.keyCode]||b.defer(b.bind(f._onInput,f,a))}),this},focus:function(){this.$input.focus()},blur:function(){this.$input.blur()},getLangDir:function(){return this.dir},getQuery:function(){return this.query||""},setQuery:function(a,b){this.setInputValue(a),this._setQuery(a,b)},hasQueryChangedSinceLastFocus:function(){return this.query!==this.queryWhenFocused},getInputValue:function(){return this.$input.val()},setInputValue:function(a){this.$input.val(a),this.clearHintIfInvalid(),this._checkLanguageDirection()},resetInputValue:function(){this.setInputValue(this.query)},getHint:function(){return this.$hint.val()},setHint:function(a){this.$hint.val(a)},clearHint:function(){this.setHint("")},clearHintIfInvalid:function(){var a,b,c,d;a=this.getInputValue(),b=this.getHint(),c=a!==b&&0===b.indexOf(a),d=""!==a&&c&&!this.hasOverflow(),!d&&this.clearHint()},hasFocus:function(){return this.$input.is(":focus")},hasOverflow:function(){var a=this.$input.width()-2;return this.$overflowHelper.text(this.getInputValue()),this.$overflowHelper.width()>=a},isCursorAtEnd:function(){var a,c,d;return a=this.$input.val().length,c=this.$input[0].selectionStart,b.isNumber(c)?c===a:document.selection?(d=document.selection.createRange(),d.moveStart("character",-a),a===d.text.length):!0},destroy:function(){this.$hint.off(".tt"),this.$input.off(".tt"),this.$overflowHelper.remove(),this.$hint=this.$input=this.$overflowHelper=a("
');
result
.append($base.toggleClass('trefis-tooltip-icon'))
.append(
$('
', {
'class':'trefis-tooltip-content',
'style':'display:none',
'data-position-my':'center bottom-10',
'data-position-at':'center top',
'data-position-collision':'fit',
text:text
})
);
return result;
};
// run it to attach click listeners on all elements in the page
$(function(){
tf.tags.toolTip();
});
})();
;;
// lib/jquery.min.js
// @include tags/toolTip.js
// @include lib/underscore.js
// @include lib/jquery.ui.min.js
// @include widgetCommon/styledDialog.js
// @include infrastructure/period.js
// @include infrastructure/unitUtil.js
// @include infrastructure/numberFormatUtil.js
// @include infrastructure/stackedBarChart.js
/**
* Popup containing a chart that cannot be directly modified, but can
* update on model changes.
*
* Popup created using styledDialog contains Highcharts chart
* Can also use StackedBarChart
*
* @constructor
* @param {Object} options contains
* {Object} companyData Encapsulates all the data on the Company model (REQUIRED)
* {ModelManager} modelManager manager containing the various current ForecastModels (REQUIRED)
* {Object} periodToId map from period strings to identifiers of values that should be on the chart (REQUIRED)
* {JQuery Element} chartElement element that will be used for chart
* {JQuery Element} toolbarElement element that will be used for chart toolbar
* {Object} cssClass css classes contains
* {string} container css class for chart container
* {Object} dialogOptions options for popup which is used by styledDialog
* {Object} chartOptions options for chart inside popup which is used by Highcharts
* {Boolean} isEmbedded whether using the chart inside some container (not in the popup) or not
*
* REQUIRED (can also be set after creation but before use)
*
* You can also override creation-time options for the chart and dialog
* box. For example, you can override `dialogOptions.title` to set a title
* on the popup and override `chartOptions.xAxis.labels.formatter` if you
* are not using periods as categories.
*/
(function() {
var ModelChartPopup,
bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
ModelChartPopup = (function() {
var activeModel, baseModel, chartType, decimalPlaces, defaultStackedLabelsTooltip, defaultXAxisLabelFormatter, getAbsoluteValue, legendLabelFormatter, processLegendVisibility, thisChart, thisOptions;
thisChart = null;
chartType = null;
decimalPlaces = 1;
baseModel = void 0;
activeModel = void 0;
thisOptions = null;
function ModelChartPopup(options) {
this.unregister = bind(this.unregister, this);
this.switchModel = bind(this.switchModel, this);
this.drawPlotLine = bind(this.drawPlotLine, this);
this.findNowIndex = bind(this.findNowIndex, this);
this.getChartColor = bind(this.getChartColor, this);
this.updateAllData = bind(this.updateAllData, this);
this.createStackedBar = bind(this.createStackedBar, this);
this.updateData = bind(this.updateData, this);
var publishedModels;
var chartOptions;
if (options.collectionIdentifier && options.companyData.md.yAxisLabels && options.companyData.md.yAxisLabels[options.collectionIdentifier]) {
this.unit = options.companyData.md.yAxisLabels[options.collectionIdentifier];
} else {
this.unit = options.unit;
}
this.options = {
deepLinkingEnabled: false,
companyData: null,
modelManager: null,
periodToId: {},
plots: null,
stackedBarChart: null,
chartElement: $(_.template($('#bootstrap-modal-template').html())({
includeHeader: true, includeCloseX: true, includeFooter: false
})),
chartElementOrig: $('', {
html: [
$('
', { 'class': 'no-margin', text: this.options.dialogOptions.title }))
this.options.chartElement.find('.modal-body').append(this.options.chartElementOrig);
this.options.chartElement.find('.modal-body').append(this.options.chartElementStacked);
this.options.chartElement.modal({ show: false })
if (!this.options.isEmbedded) {
this.options.chartElement.addClass(this.options.cssClass.container);
this.open();
}
baseModel = this.options.modelManager.get('trefis');
activeModel = this.options.modelManager.get('active');
publishedModels = this.options.modelManager.get("publishedModels");
chartOptions = {
chart: {
// renderTo: this.options.chartElementOrig[0]
},
plotOptions: {
line: {
lineWidth: 10
}
}
};
chartOptions = $.extend(true, {}, this.options.chartOptions, chartOptions)
if (publishedModels.length > 0) {
chartOptions.plotOptions.series.type = "line";
}
chartType ="column"
if (this.options.stackedBarChart) {
// this.options.stackedBarCview.answer().constituentBreakdowns[0]
// current fields on the a constituentBreakdown
// {
// name:'default', // not sure what this is used for
// components: [], // the constituents...
// displayType:string // '', stackedcolumn, waterfall
// }
chartType = this.options.stackedBarChart.defaultChartType;
// some charts may not have the display type associated with them, default them to stackedcolumn
if (!chartType){
chartType = 'stackedcolumn'
}
}
if (!this.options.isEmbedded) {
this.createToolbar(chartType);
}
//this.chart = new Highcharts.Chart($.extend(true, {}, this.options.chartOptions, chartOptions));
chartOptions.series = chartOptions.series||{}
/*
this.chart = $(this.options.chartElementOrig[0]).modelChart({
//deepLinkingEnabled: this.options.deepLinkingEnabled,
//shareLinksModel: this.options.shareLinksModel,
//divisionIdentifier: this.options.collectionIdentifier,
//answerIdentifier: this.options.answerIdentifier,
activePeriodType : 1,
modelManager : this.options.modelManager,
maxHistoricalPoints: tf.modelPreferences.historicalYearsNumber,
plots: this.options.plots,
chart: chartOptions,
modelChartPopupOptions : thisOptions,
chartDisplay : thisOptions.chartDisplay,
height: 460,
editableUserSeriesOptions:{
tf:{
series:{
editable:false
}
},
}
})
*/
var options = $.extend({}, thisOptions);
options = $.extend({}, options, {
chart : chartOptions
});
this.chart = $(this.options.chartElementOrig[0]).modelChart(options);
//$("#stretch-area").modelChart(thisOptions);
thisChart = this.chart;
var self = this
this.options.chartElement.on('hide.bs.modal', function() {
self.chart.modelChart('destroy')
self.options.chartElement.remove()
})
tf.tags.toolTip();
//this.register();
}
/**
* Can be called externally to set options after creation
* @param {Object} options
*/
ModelChartPopup.prototype.extendOptions = function(options) {
return this.options = $.extend(true, this.options, options || {});
};
/**
* Create and display non-stacked-bar chart for current model
* Created for called by @updateAllData
* @param {ForecastModel} model current model that will be used for creating the chart
* @param {integer} idx current model index. will be used for clearing the chart if idx is 0.
* @param {Array of String} periods X axis categories that should be used in the chart
*/
ModelChartPopup.prototype.updateData = function(model, idx, periods) {
var axis, countOfData, data, j, len, mantissa, ref, seriesColor, seriesName, sumOfData;
sumOfData = 0;
countOfData = 0;
data = $.map(periods, (function(_this) {
return function(period) {
var ref, value;
value = (ref = model.getValue(_this.options.periodToId[period])) != null ? ref : null;
if (value) {
countOfData++;
sumOfData = sumOfData + value;
return parseFloat(value);
} else {
return 0;
}
};
})(this));
mantissa = sumOfData / countOfData;
decimalPlaces = 1;
if (mantissa > 0) {
while (!(mantissa > 1)) {
decimalPlaces++;
mantissa *= 10;
}
}
ref = this.chart.xAxis;
for (j = 0, len = ref.length; j < len; j++) {
axis = ref[j];
axis.setCategories(periods, false);
}
idx = parseInt(idx);
if (idx === 0) {
while (this.chart.series.length > 0) {
this.chart.series[0].remove(false);
}
}
this.chart.counters.color = 0;
this.chart.counters.symbol = 0;
seriesName = model.getTitle();
seriesColor = "";
if (idx > 0) {
if (model.modelId === baseModel.modelId) {
seriesColor = "#666";
} else {
seriesColor = this.getChartColor(idx);
}
}
this.chart.addSeries({
name: seriesName,
data: data,
color: seriesColor
}, false);
this.chart.redraw();
return this.updateChartSize();
};
/**
* This section will create the stacked bar chart for constituents
* It will limit the json data to 32 elements and 12 labels
* needs to be refactored and not to be rebuilt each time?
* @param {ForecastModel} model curent model that will be used for creating the chart
* @param {PeriodType} periodType is used to filter the data
*/
ModelChartPopup.prototype.createStackedBar = function(model, periodType) {
var chartOptions,
constituent,
difference,
differenceData,
includeDifference,
index,
index2,
j,
k,
keys,
legend,
legendHeight,
legendItemStyleWidth,
legendItemWidth,
maxSize,
maxVal,
modelData,
percentageDifference,
ref,
ref1,
ref2,
ref3,
sbcPeriods,
sbcSeries,
sbcSeriesSize,
series,
seriesValue,
stepSize,
total;
constituent = {
"stat": "Constituents"
};
keys = _.keys(this.options.stackedBarChart.data);
sbcPeriods = [];
maxSize = 32;
if (this.options.isEmbedded) {
maxSize = 20;
}
sbcSeries = $.map(keys, (function(_this) {
return function(key) {
var data, keys2, map, series;
series = {};
series.name = _this.options.stackedBarChart.names[key];
series.unit = _this.options.unit;
map = _this.options.stackedBarChart.data[key];
keys2 = _.keys(_this.options.stackedBarChart.data[key]);
keys2 = $.grep(keys2, function(period) {
return tf.period.typeOf(period) === periodType;
});
keys2.sort(tf.period.compare);
keys2 = keys2.slice(0, maxSize);
if (keys2.length > sbcPeriods.length) {
sbcPeriods = keys2;
}
data = $.map(keys2, function(key2) {
var modelValue, ref, ref1, value;
value = (ref = map[key2]) != null ? ref : null;
modelValue = (ref1 = model.getValue(value)) != null ? ref1 : null;
if (isNaN(modelValue)) {
return 0;
} else {
return modelValue;
}
});
series.data = data;
return series;
};
})(this));
modelData = $.map(sbcPeriods, (function(_this) {
return function(period) {
var ref, value;
value = (ref = model.getValue(_this.options.periodToId[period])) != null ? ref : null;
return value;
};
})(this));
maxVal = sbcPeriods.length - 1;
stepSize = 1;
differenceData = [];
includeDifference = false;
for (index = j = 0, ref = maxVal, ref1 = stepSize; ref1 > 0 ? j <= ref : j >= ref; index = j += ref1) {
sbcSeriesSize = sbcSeries.length - 1;
total = 0;
for (index2 = k = 0, ref2 = sbcSeriesSize, ref3 = stepSize; ref3 > 0 ? k <= ref2 : k >= ref2; index2 = k += ref3) {
seriesValue = sbcSeries[index2].data[index];
total = total + seriesValue;
}
difference = Math.round(modelData[index] - total);
differenceData.push(isNaN(difference) ? 0 : difference);
percentageDifference = Math.abs(difference / modelData[index]);
if (percentageDifference > 0.01) {
includeDifference = true;
}
}
if (includeDifference) {
series = {};
series.name = "Other";
series.unit = "$";
series.data = differenceData;
sbcSeries.push(series);
}
if (sbcSeries.length > 4 && this.options.isEmbedded) {
sbcSeries = processLegendVisibility(sbcSeries);
}
constituent.series = sbcSeries;
constituent.bars = sbcPeriods.slice(0, maxSize);
legend = {
align: 'center',
verticalAlign: 'bottom',
layout: 'horizontal',
labelFormatter: legendLabelFormatter,
y: 1,
itemStyle: {
font: '11pt GothamBook,Helvetica,Arial,sans-serif',
textDecoration: 'none',
color: '#FFF',
cursor: 'default',
color: '#3E576F'
},
itemHoverStyle: {
color: '#3E576F'
}
};
if (sbcSeries.length > 3 && !this.options.isEmbedded) {
legendHeight = 42;
legendItemWidth = 223;
legendItemStyleWidth = 220;
if (sbcSeries.length > 12) {
legendHeight = 108;
} else if (sbcSeries.length > 9) {
legendHeight = 84;
} else if (sbcSeries.length > 6) {
legendHeight = 61;
} v
legend = {
width: 680,
height: legendHeight,
itemWidth: legendItemWidth,
align: 'center',
verticalAlign: 'bottom',
layout: 'horizontal',
labelFormatter: legendLabelFormatter,
y: 1,
itemStyle: {
font: '11pt GothamBook,Helvetica,Arial,sans-serif',
textDecoration: 'none',
color: '#FFF',
cursor: 'default',
width: legendItemStyleWidth,
color: '#3E576F',
textAlign: 'center'
},
itemHoverStyle: {
color: '#3E576F'
}
};
}
chartOptions = {
chart: {
backgroundColor: '#ffffff'
},
xAxis: {
labels: {
formatter: defaultXAxisLabelFormatter,
step: 1,
style: {
color: '#999999',
fontFamily: 'Gotham, Helvetica, Arial, sans-serif',
fontSize: '9pt'
}
}
},
yAxis: {
title: {
text: this.options.unit
},
stackLabels: {
style: {
color: '#333'
},
enabled: false
},
labels: {
formatter: this.createDefaultYAxisFormatter()
},
opposite: this.options.isEmbedded
},
legend: legend,
tooltip: {
backgroundColor: '#ffffff',
useHTML: true,
formatter: defaultStackedLabelsTooltip,
style: {
color: '#333'
}
},
point: {
events: {
legendItemClick: (function(_this) {
return function() {
return false;
};
})(this)
}
}
};
chartOptions = $.extend(true, chartOptions, this.options.stackedBarChartOptions || {});
return this.chartStacked = new StackedBarChart($.extend(constituent, {
width: this.options.chartElement.width(),
height: this.options.chartElement.height(),
renderTo: this.options.chartElementStacked[0],
chartOptions: chartOptions
}));
};
/**
* sort series by absolute value
* hide items #5 and lower
*/
processLegendVisibility = function(series) {
var idx;
for (idx in series) {
series[idx].absoluteValue = getAbsoluteValue(series[idx]);
}
series.sort(function(a, b) {
return parseFloat(b.absoluteValue) - parseFloat(a.absoluteValue);
});
idx = 4;
while (idx < series.length) {
series[idx].showInLegend = false;
idx++;
}
return series;
};
/**
* get serie's absolute value
*/
getAbsoluteValue = function(serie) {
var idx, returnValue;
returnValue = 0;
for (idx in serie.data) {
returnValue += serie.data[idx];
}
return Math.abs(returnValue);
};
/**
* Create and display chart for all model
*/
ModelChartPopup.prototype.updateAllData = function() {
var allModels, publishedModel, idx, model, periodType, periods, ref;
periods = _.keys(this.options.periodToId);
this.options.dataPeriodsMap = tf.period.getCountMap(periods, false);
if (this.options.selectedPeriodChartType) {
periodType = tf.period.getCurrentType(periods, this.options.companyData, false, this.options.selectedPeriodChartType);
} else {
periodType = tf.period.getCurrentType(periods, this.options.companyData, false);
}
this.options.selectedPeriodType = periodType;
periods = $.grep(periods, function(period) {
return tf.period.typeOf(period) === periodType;
});
periods.sort(tf.period.compare);
if (chartType === 'stacked') {
this.createStackedBar(activeModel, periodType);
} else {
allModels = [];
if (this.options.modelManager.get('publishedModels')) {
ref = this.options.modelManager.get('publishedModels');
for (idx in ref) {
publishedModel = ref[idx];
if (publishedModel.modelId !== activeModel.modelId) {
allModels.push(publishedModel);
}
}
}
if (activeModel !== baseModel && activeModel.isModified()) {
allModels.push(activeModel);
}
allModels.push(baseModel);
for (idx in allModels) {
model = allModels[idx];
this.updateData(model, idx, periods);
}
}
return this.drawPlotLine();
};
/**
* Get color that will be used by chart
* @param {integer} idx model index
*/
ModelChartPopup.prototype.getChartColor = function(idx) {
var result;
result = ["936", "639", "396", "993"][idx % 4];
return "#" + result;
};
/**
* Get category index minus one for first projected period
* Created to be called from @drawPlotLine
*/
ModelChartPopup.prototype.findNowIndex = function() {
var categories, category, firstProjectedPeriod, idx, result;
result = -1;
categories = thisChart.xAxis[0].categories;
firstProjectedPeriod = this.options.companyData.md.sankeyPeriods.codes[0];
for (idx in categories) {
category = categories[idx];
if (tf.period.periodEquals(category, firstProjectedPeriod)) {
result = idx === 0 ? 0 : idx - 1;
break;
}
}
return result;
};
/**
* Draw plot line in the chart
*/
ModelChartPopup.prototype.drawPlotLine = function() {
var nowIndex, xAxis;
xAxis = thisChart.xAxis[0];
xAxis.removePlotLine("verticalPlotLine");
if (thisChart.options.chart.type === "line") {
nowIndex = this.findNowIndex();
if (nowIndex >= 0) {
return xAxis.addPlotLine({
color: "#888",
id: "verticalPlotLine",
width: 1,
value: nowIndex,
zIndex: 2
});
}
}
};
/**
* Methods for listening for model changes, reacting to them, and no
* longer listening when the popup is closed.
*
* We want to listen for changes in which model is being used, and
* changes in the output of the current model.
*/
ModelChartPopup.prototype.register = function() {
var ref;
if ((ref = this.options.modelManager) != null) {
ref.on('change:active', this.switchModel);
}
return this.switchModel();
};
/**
* Methods for updating current chart to active model
*/
ModelChartPopup.prototype.switchModel = function() {
if (activeModel != null) {
activeModel.removeChangeListener(this.updateAllData);
}
activeModel = this.options.modelManager.get('active');
activeModel.addChangeListener(this.updateAllData);
return this.updateAllData();
};
/**
* Methods for removing all listener
* Called when popup is closed
*/
ModelChartPopup.prototype.unregister = function() {
this.options.modelManager.off('change:active', this.switchModel);
return activeModel != null ? activeModel.removeChangeListener(this.updateAllData) : void 0;
};
/**
* Methods for opening the popup
*/
ModelChartPopup.prototype.open = function() {
var callbackOptions, options;
callbackOptions = {
close: this.unregister,
resize: (function(_this) {
return function() {
return _this.updateChartSize();
};
})(this)
};
options = $.extend({}, this.options.dialogOptions, callbackOptions);
this.options.chartElement.modal('show')
};
/**
* Methods for closing the popup
*/
ModelChartPopup.prototype.close = function() {
return this.options.chartElement.modal("hide").remove();
};
/**
* Methods for updating the chart size
*/
ModelChartPopup.prototype.updateChartSize = function() {
var height, highChart, width;
width = this.options.chartElement.width();
height = this.options.chartElement.height();
this.chart.setSize(width, height, false);
if (chartType === "stacked") {
highChart = this.chartStacked.chart;
return highChart.setSize(width, height, false);
}
};
/**
* Methods for creating default tooltip formatter
* Called bound to a Highcharts datum descriptor object
*/
ModelChartPopup.prototype.createDefaultTooltipFormatter = function() {
var unit;
unit = this.unit;
return function() {
var x, y;
x = tf.period.format(this.x);
y = UnitUtil.getDisplayString(this.y, unit === '%' ? unit : '');
return x + ': ' + y;
};
};
/**
* Methods for creating default plot formatter
* Called bound to a Highcharts datum descriptor object
*/
ModelChartPopup.prototype.createDefaultPlotFormatter = function() {
var unit;
unit = this.unit;
return function() {
var index, length;
length = this.series.xData.length;
if (length > 12) {
index = $.inArray(this.x, this.series.xAxis.categories);
if (length < 25) {
if ((index % 2) !== 0) {
return "";
}
} else {
if ((index % 4) !== 0) {
return "";
}
}
}
return UnitUtil.getDisplayString(this.y.toFixed(decimalPlaces), unit === '%' ? unit : '');
};
};
/**
* Methods for creating default Y Axis formatter
* Called bound to a Highcharts datum descriptor object
*/
ModelChartPopup.prototype.createDefaultYAxisFormatter = function() {
var unit;
unit = this.unit;
return function() {
return UnitUtil.getDisplayString(this.value, unit === '%' ? unit : '');
};
};
/**
* Method for creating default x axis label formatter
* It will limit to 'lower' labels
* Called bound to a Highcharts datum descriptor object
*/
defaultXAxisLabelFormatter = function() {
var index, lower, upper, xYear;
lower = 12;
upper = 25;
if (thisOptions.isEmbedded) {
lower = 8;
upper = 15;
}
if (this.axis.categories.length > lower) {
index = $.inArray(this.value, this.axis.categories);
if (this.axis.categories.length < upper) {
if ((index % 2) !== 0) {
return "";
}
} else {
if ((index % 4) !== 0) {
return "";
}
}
}
xYear = tf.period.format(this.value);
xYear = xYear.substring(2, xYear.length);
if (parseInt(xYear) === new Date().getFullYear()) {
return "NOW";
} else {
return "'" + xYear.replace(" ", "");
}
};
/**
* Method for creating default stacked bar series tooltip formatter
* This is HTML format
* Called bound to a Highcharts datum descriptor object
*/
defaultStackedLabelsTooltip = function() {
var html, percentage, seriesName, value, year;
year = tf.period.format(this.x);
seriesName = this.series.name;
value = this.series.options.unit + UnitUtil.getDisplayString(this.y, "");
percentage = NumberFormatUtil.formatPercent(this.percentage, 100) + " of " + this.series.options.unit + UnitUtil.getDisplayString(this.total, "");
html = "" + year + " " + seriesName + " " + value + " " + percentage;
return html;
};
/**
* Methods for slicing the legend labels based on number of series in the legend
*/
legendLabelFormatter = function() {
var numberOfItems;
numberOfItems = this.chart.series.length;
if (numberOfItems > 2) {
return this.name.slice(0, 23);
} else if (numberOfItems > 1) {
return this.name.slice(0, 38);
}
return this.name;
};
/**
* Methods for creating chart toolbar
* Toolbar can be used to change period type and chart type
* @param {string} defaultChartType default selected chart type in toolbar
*/
ModelChartPopup.prototype.createToolbar = function(defaultChartType) {
var columnButton,
dataPeriodIdx,
dataPeriodValue,
divButtonElement,
existPeriodsSize,
lineButton,
periodTypeKey,
periodTypeValues,
ref,
selectElement,
selectValue,
selectValueVal,
self,
stackBarChartButton,
arearangeChartButton,
toolbarElement,
val;
self = this;
this.options.toolbarElement.addClass("toolbarElement");
toolbarElement = $(this.options.toolbarElement[0]);
periodTypeValues = [];
for (periodTypeKey in tf.period.type) {
periodTypeValues.push(tf.period.type[periodTypeKey]);
}
existPeriodsSize = $.grep(this.options.dataPeriodsMap, function(dataPeriods, i) {
return $.inArray(i - 1, periodTypeValues) > -1 && dataPeriods > 0;
}).length > 0;
//NOT USING THIS TOOLBAR PERIOD SELECTION ANYMORE, USING THE WIDGET'S CHART BUTTON CONTROL INSTEAD
/*
if (existPeriodsSize) {
selectElement = $("");
selectElement.addClass("selectElement");
selectValue = {};
ref = this.options.dataPeriodsMap;
for (dataPeriodIdx in ref) {
dataPeriodValue = ref[dataPeriodIdx];
if (this.options.dataPeriodsMap[dataPeriodIdx] > 0) {
selectValue[tf.period.typeNames[dataPeriodIdx]] = dataPeriodIdx;
}
}
for (val in selectValue) {
selectValueVal = selectValue[val];
if (this.options.dataPeriodsMap[selectValueVal] > 0) {
$("", {
value: selectValueVal,
text: val
}).appendTo(selectElement);
}
}
selectElement.val(this.options.selectedPeriodType);
selectElement.on("change", function(e) {
return self.changePeriodType(parseInt(this.value));
});
selectElement.appendTo(toolbarElement);
}*/
divButtonElement = $("");
divButtonElement.addClass("divButtonElement");
lineButton = $("");
columnButton = $("");
stackBarChartButton = $("");
arearangeChartButton = $("area");
// wire up a wave
// _this.changeType("arearange")
arearangeChartButton.click((function(_this) {
return function(e) {
e.preventDefault();
divButtonElement.find("a").removeClass("active");
$(e.target).addClass("active");
return _this.changeType("arearange");
};
})(this));
columnButton.click((function(_this) {
return function(e) {
e.preventDefault();
divButtonElement.find("a").removeClass("active");
$(e.target).addClass("active");
return _this.changeType("column");
};
})(this));
lineButton.click((function(_this) {
return function(e) {
e.preventDefault();
divButtonElement.find("a").removeClass("active");
$(e.target).addClass("active");
return _this.changeType("line");
};
})(this));
stackBarChartButton.click((function(_this) {
return function(e) {
e.preventDefault();
divButtonElement.find("a").removeClass("active");
$(e.target).addClass("active");
//return _this.changeType("stacked");
return _this.changeType("stackedcolumn");
};
})(this));
if (this.options.stackedBarChart) {
stackBarChartButton.addClass("active");
} else if (defaultChartType === 'column') {
columnButton.addClass("active");
} else if (this.options.arearangeChart){
arearangeChartButton.addClass("active");
} else {
lineButton.addClass("active");
}
/*
if (this.options.stackedBarChart) {
divButtonElement.append(stackBarChartButton).append(lineButton);
} else {
divButtonElement.append(columnButton).append(lineButton);
}
if (this.options.arearangeChart){
divButtonElement.append(arearangeChartButton);
}*/
divButtonElement.appendTo(toolbarElement);
$("").addClass("toolbarBottom").appendTo(toolbarElement);
return $(this.options.chartElement[0]).before(toolbarElement);
};
/**
* Methods that can be called for changing chart type
* Called from createToolbar
* @param {string} newType chart type
*/
ModelChartPopup.prototype.changeType = function(newType) {
$(this.chart).modelChart("updateSeriesType", newType);
/*if (newType === "stacked") {
$(this.options.chartElementOrig[0]).hide();
$(this.options.chartElementStacked[0]).show();
} else {
$(this.options.chartElementOrig[0]).show();
$(this.options.chartElementStacked[0]).hide();
thisChart.options.chart.type = newType;
}
chartType = newType;
return this.updateAllData();*/
};
/**
* Methods that can be called for changing chart period type
* Called from createToolbar
* @param {string} periodType chart period type
*/
ModelChartPopup.prototype.changePeriodType = function(periodType) {
this.options.selectedPeriodChartType = periodType;
return this.updateAllData();
};
return ModelChartPopup;
})();
window.ModelChartPopup = ModelChartPopup;
}).call(this);
;;
// lib/jquery.min.js
// @include tf/admin.js
(function(){
function findFirstNextChecked(el) {
if(el.is(':checked')) {
return el;
} else {
var next = el.closest("tr").next(); // next() returns a collection
if (next.length === 0) {
return null;
} else {
return findFirstNextChecked($('.driverVisibility', next[0]));
}
}
}
function findFirstPrevChecked(el) {
if(el.is(':checked')) {
return el;
} else {
var prev = el.closest("tr").prev(); // prev() returns a collection
if (prev.length === 0) {
return null;
} else {
return findFirstPrevChecked($('.driverVisibility', prev[0]));
}
}
}
// maintains the color of the label of a checkbox
function colorTheLabel(visible, el) {
el.closest('tr').toggleClass('hideFromSankey', !visible);
}
/*
* @param {jQuery} linkDiv -- the jQuery object of the static part of the drop-down
* @param {Function} changeListener -- optional function to be called when the user changes
* the dropdown state; will be called with 1 argument, the new selectedIndex
* @param {Array of String} options -- elements to show in the dropdown
* @param {int} selectedIndex -- which element should be selected by default; if null, defaults to 0
* @param {String} popupCssClass -- classname to be applied to the popup that appears when the user clicks the
* link. If null, we'll default to right-aligning the popup to the link. If not-null, no horizontal positioning,
* is done by default (the only positioning will be that the top of the popup is vertically aligned with the bottom
* of the link)
*
*/
HeaderDropdown = function(linkDiv, changeListener, options, selectedIndex, popupCssClass) {
var css = {};
if(!popupCssClass) {
css = {
right: linkDiv.length > 0 ? linkDiv.parent().width() - linkDiv.position().left - linkDiv.width() - 16 + parseInt(linkDiv.css('padding-left')) : 0
};
}
var self = this,
table = $("
"),
popupDiv = $("", {
"class": "cwHeaderDropdown",
css: css
})
.addClass(popupCssClass != undefined ? popupCssClass : "")
.append("")
.append(table)
;
var form = $("").appendTo(popupDiv);
linkDiv
.click(function() {
if (popupDiv.is(':visible')) {
popupDiv.hide();
} else {
popupDiv
.show()
.css({top: linkDiv.position().top + linkDiv.height() + parseInt(linkDiv.css('padding-top')) + parseInt(linkDiv.css('padding-bottom')) + 1});
setTimeout(function() {$("body").one("click", hidePopup)}, 100);
}
return false;
})
.parent().append(popupDiv);
selectedIndex = selectedIndex || 0;
setOptions(options || []);
/**
* @param {Array} newOptions the new value for the array of options
* @param {int} newSelectedIndex index of the initial selection
* @param {Array} newOptionsMetaData meta-data objects for each option.
* newOptionsMetaData[i] contains key-value metadata for
* option[i]. It would be nice to do this by mapping options
* meta-data, but the options are display strings for which
* we sometimes have duplicates (though that's undesirable).
*/
function setOptions(newOptions, newSelectedIndex, newOptionsMetaData) {
options = newOptions;
table.empty();
table.toggleClass("admin", !!(window.tf && tf.isAdmin && tf.isAdmin()));
var editMode = !!(//jQuery requires an actual boolean
window &&
window.tf &&
window.tf.editMode &&
newOptionsMetaData &&
window.tf.urls &&
window.tf.urls.periodVisibleEndpoint);
table.toggleClass("editMode", editMode);
if(editMode) {
var header = $("
");
table.append(header);
header.append($("
"));
header.append($("
Show
").attr("title", "'unchecked' == inconsistent breakdown, hide in view"));
header.append($("
Display by Default
").attr("title", "'unchecked' == inconsistent breakdown, hide in view"));
};
$.each(options, function(i, option) {
var tr = $("
");
var a = $("", {
text: option,
href: '#'
});
var td = $("
").append(check));
check.attr("checked", !hidden)
.attr("title", "'unchecked' == inconsistent breakdown, hide in view")
.attr("code", newOptionsMetaData[i].code);
check.click(function(event){
var el = $(this);
var code = el.attr("code");
var visible = el.is(':checked');
var nearbyChecked = findFirstNextChecked(el) || findFirstPrevChecked(el);
if(nearbyChecked) {
if(!visible && $(':radio',tr).is(':checked') ) {
// if the user deselects the default period simulate user action picking up another one
$(':radio', nearbyChecked.closest("tr")).click();
}
} else {
colorTheLabel(!visible, el);
return false; // revert checkbox state -- do not allow the user to deselect all periods
};
colorTheLabel(visible, el);
$.ajax({
type: "POST",
url: window.tf.urls.periodVisibleEndpoint+"&periodCode="+encodeURIComponent(code)+"&isVisible="+visible,
success: function(data){
if(data.success==false){
alert(data.message);
//revert checkbox state on failure
el.prop('checked', !visible);
colorTheLabel(!visible, el);
return false;
}
}
});
$(':radio', tr).attr("disabled", !visible);
event.stopPropagation();
});
var displayByDefault = $("");
tr.append($("
").append(displayByDefault));
displayByDefault.attr("checked", i === newSelectedIndex)
.attr("code", newOptionsMetaData[i].code)
.attr("disabled", !$('.driverVisibility', tr).is(':checked'));
displayByDefault.click(function(event){
var el = $(this)
var code = el.attr("code");
if( $('.driverVisibility', el.closest("tr")).is(':checked') ) {
$.ajax({
type: "POST",
url: window.tf.urls.periodDefaultEndpoint+"&periodCode="+encodeURIComponent(code),
success: function(data){
if(data.success==false){
alert(data.message);
colorTheLabel(!visible, el);
return false; //revert radio button state on failure
}
}
});
} else {
event.stopPropagation();
colorTheLabel(!visible, el);
return false; //revert radio button -- cannot make non-displaying period default
}
event.stopPropagation();
});
}
if(newOptionsMetaData && newOptionsMetaData[i] && newOptionsMetaData[i].code)tr.attr("code", newOptionsMetaData[i].code)
if(newOptionsMetaData && newOptionsMetaData[i] && newOptionsMetaData[i].id)tr.attr("id", newOptionsMetaData[i].id)
});
setSelected(Math.max(0, Math.min(newSelectedIndex === undefined ? selectedIndex : newSelectedIndex, options.length-1)));
}
function setSelected(newSelected, fireEvent) {
selectedIndex = newSelected;
linkDiv.text(options[selectedIndex]);
if(fireEvent)
changeListener(selectedIndex);
}
function getSelected() {
return selectedIndex;
}
function internalClickListener() {
var clickedElement = this;
table.find("td.periodLabel").each(function(i, el) {
if(el == clickedElement) {
setSelected(i, 1)
hidePopup();
}
});
return false;
}
function hidePopup() {
popupDiv.hide();
}
$.extend(self, {
setOptions: setOptions,
setSelected: setSelected,
getSelected: getSelected,
popupDiv: popupDiv
});
}
})();
;;
// @include lib/jquery.ui.min.js
// @include lib/raphael-min.js
// @include widgetCommon/styledDialog.js
// @include common.js
// @include infrastructure/unitUtil.js
// @include infrastructure/seriesUtil.js
// @include tf/ga.js
// @include widgetCommon/chartPopup.js
// @include widgetCommon/modelChartPopup.js
// @include widgetCommon/headerDropdown.js
/*
This file holds classes for client-side sankey rendering using the Raphael library (SVG/VML).
SankeyDiagram is the main class that external files need to interact with. There are also a couple
"private" classes in this file: Node and Column, which are used internally by SankeyDiagram.
*/
// enclose in function for minification
;(function() {
// various states that a node can be in; should match the values in the NodeState.java enum
var NODE_STATE_ROOT = 0;
var NODE_STATE_NORMAL = 1
var NODE_STATE_NORMAL_SUBDIVISION = 2;
var NODE_STATE_SELECTED_SUPERDIVISION = 3;
var NODE_STATE_SELECTED_DIVISION = 4;
var NODE_STATE_REVERSE = 5;
// various states the sankey as a whole can be in; should match the values in the SnakeyState.java enum
var SANKEY_STATE_NORMAL = 0;
var SANKEY_STATE_SUPERDIVISION_SELECTED = 1;
var SANKEY_STATE_DIVISION_SELECTED = 2;
var SANKEY_STATE_SUBDIVISION_SELECTED = 3;
/*
* when rendering two polygons that meet at an edge, if you set the end of
* one equal to the start of the other, you map see a little gap between the polygons
* because of rounding errors and rasterization. To avoid this, have each polygon extend
* a little farther than its nominal dimensions by adding OVERLAP_FUDGE_FACTOR to each dimension
*/
var OVERLAP_FUDGE_FACTOR = 0.5;
var DEFAULT_NODE_RENDER_OPTIONS ={
cash:{}, //cash gets its defaults from positive unless otherwise specified or passed in
positive:{
"stroke-width": 0, //curve outline width
stroke:'transparent', //curve outline color
superFill:"0-#93b793-#61AD61:30", //curve fill for first level arms, like superdivisions
subFill:"#61AD61", //curve fill for 2nd level arms like sub divisions
extenderFill:"0-#61AD61-#61AD61:20-#ededed:21",
minTubeWidth: 1 //minimum tube width
},
negative:{
"stroke-width": 0, //curve outline width
stroke:'transparent', //curve outline color
superFill:"0-#b27575-#A42D2D:30", //curve fill for first level arms, like superdivisions
subFill:"#A42D2D", //curve fill for 2nd level arms like sub division
extenderFill:"0-#A42D2D-#A42D2D:20-#ededed:21",
minTubeWidth: 1 //minimum tube width
},
root:{
"stroke-width": 0, //curve outline width
stroke:'transparent', //curve outline color
positiveFill: "0-#ededed:50-#93b793",
negativeFill: "0-#ededed:50-#b27575",
fill:"#ededed",
arrowThicknessPercent:1 //arrow thickness as percentage of the very left column (root node)
},
reversed: {
"stroke-width": 0, //curve outline width
stroke:'transparent', //curve outline color
superFill:"0-#A42D2D-#ededed", //curve fill for first level arms, like superdivisions
subFill:"#A42D2D", //curve fill for 2nd level arms like sub division
extenderFill:"0-#A42D2D-#A42D2D:20-#ededed:21",
minTubeWidth: 1 //minimum tube width
},
selectedTextBoxMinHeight:35,
animationDuration:200
}
var RENDER_OPTIONS={};
var SANKEY_INITIAL_LOAD_DATA;
// =============================================================
// ======================== SANKEY DIAGRAM =====================
// =============================================================
/**
* Creates a client-side rendered sankey diagram.
*
* @constructor
* @param {String} divId id of the div in which the sankey should be created. The div must already exist in the page.
* @param {Object} params key/value pairs of configuration options for the sankey. can be null to use all defaults. Accepted parameters are:
* {int} rootTubeWidth: thickness in pixels of the arrow at the root end of the sankey
* {int} heightForText: the lineheight in pixels we should expect for division labels
* {int} width: width in pixels of the area available for sankey
* {int} height: height in pixels of the area available for sankey
* {int} widthForRHSColumn: space in pixels to leave for the RHS column of $/% numbers
* {int} minArmSpacing: minimum vertical space in pixels to leave between sankey arms
* {int} maxArmSpacing: maximum vertical space in pixels to leave between sankey arms
* {int} rootVerticalPosition: distance in pixels from the top of the sankey-containing div to the midpoint of the root arrow
* {String} selectedPeriod: period code for the default selected period
* {int} inspectorLeftEdge: the horizontal distance in pixels from the left of the sankey-containing div to the left of the inspector div.
* Used to make sure the selected division of the sankey can extend its arm to be flush with the inspector
* {boolean} renderPartialSums: if true, red/green brackets will be displayed on the RHS to show the sums of various groups of arms
* {boolean} editableDivisionNames: if true, allow the user to edit
* division names
* {function(element, id, options)} nameDecoratorCallback: a
* callback for making names editable, taking
* {jQuery} element: part of the document to make editable
* {String} id: an id that identifies the name on the back-end
* {object} options: we will set options.extraData.type to say
* what type of name we are editing.
* @param {ForecastModel} forecastModel the model that should be visualized by this sankey
* @param {PeriodSelectionManager} periodSelectionManager
*/
_SankeyDiagram = function(elemOrSelector, params, startingForecastModel, periodSelectionManager, initialLoadData, root, containerDimensions) {
var selfSankey = this,
div = $(elemOrSelector),
// Hack: give it the full viewport width/height to get the sankey to render better and then scale it down later
paper = Raphael(div[0], window.innerWidth, window.innerHeight),
nodes = {}, // map from node identifiers to the Node objects themselves
currentDynamicData; // stores the dynamicData object that was last rendered by applyDynamicData
div.hide() // Hide the chart until it's done rendering
window.paper = paper;
SANKEY_INITIAL_LOAD_DATA = initialLoadData;
var svgHeight = div.height();
// this defines the default params, and overrides them with any params passed as an argument to the ctor
params = $.extend({
rootTubeWidth: 55,
heightForText: 16,
// Hack: give it the full viewport width/height to get the sankey to render better and then scale it down later
width: window.innerWidth,
height: window.innerHeight,
widthForRHSColumn: 90,
minArmSpacing: 14,
maxArmSpacing: 35,
rootVerticalPosition: 90,
selectedPeriod: periodSelectionManager ? periodSelectionManager.getSelectedPeriod() : null,
inspectorLeftEdge:800,
renderPartialSums:true
},
params || {});
var forecastModel;
var answerUnit; // will be set in setModel
var scaleFactorForDisplay; // result of a call to UnitUtil.calculateScaleFactorForDisplay indicating how all sankey arms should be scaled; will be set in setModel
// clicking on the root svg/vml elements is buggy in IE8, so instead put a regular div on top that
// can catch clicks on the root
div.append($('', {
css: {
background: '#000000',
position: 'absolute',
top: params.rootVerticalPosition - params.rootTubeWidth/2,
width: 30,
height: params.rootTubeWidth,
opacity: 0,
zIndex: 2,
cursor: 'pointer'
},
click: function() {
selfSankey.clickListener(null, false);
}
}));
RENDER_OPTIONS = $.extend(true, {}, DEFAULT_NODE_RENDER_OPTIONS, params.renderOptions || {});
RENDER_OPTIONS.cash = $.extend(true, {}, RENDER_OPTIONS.positive, DEFAULT_NODE_RENDER_OPTIONS.cash, params.renderOptions && params.renderOptions.cash || {});
params.getWidth = function(estimatedHeight){
return Math.max(div.width(), estimatedHeight || 0)
}
selfSankey.params = params;
var headerDropdown = new HeaderDropdown(
div.find(".headerDropdown"),
function(selectedIndex) {
updateValueText();
});
var rootNode;
// create a text-measuring function, which will be needed by the Nodes
var textMeasurerDiv = $('', {'class': 'textMeasurer'});
div.append(textMeasurerDiv);
var textMeasurer = function(text, fontSize) {
return textMeasurerDiv
.text(text)
.css({fontSize: fontSize + 'px'})
.width();
};
if(periodSelectionManager)
periodSelectionManager.addChangeListener(function() {
params.selectedPeriod = periodSelectionManager.getSelectedPeriod();
setModel(forecastModel);
// if the previously selected id doesn't exist in the new model,
// we reset the sankey to make sure that e.g. the inspector respects
// the new state of the sankey
if(params.selected && !nodes[params.selected]) {
selfSankey.clickListener(null, false);
}
});
setModel(startingForecastModel);
// ==============================
// ========== METHODS ==========
// ==============================
function setModel(newForecastModel) {
if(forecastModel)
forecastModel.removeChangeListener(modelChangeListener);
forecastModel = newForecastModel;
div
.find('.sshDivTblSumRect,.sshDivTblSum')
.remove();
//var tree = tree || forecastModel.companyData.md.treeData;
// per TREF-3106, get the largest value present anywhere in the tree, and use that
// to determine how all units should be scaled
try {
scaleFactorForDisplay = forecastModel.getLargestScaleFactor(periodSelectionManager.getSelectedPeriod());
} catch(e) {
scaleFactorForDisplay = undefined;
}
// fb2788: older models may not have a sankeyDecimalPrecision field set; if not, we calculate it here on the client
// since the default value depends on the value of the sankey root answer
try {
// if sankeyDecimalPrecision was null on page load, set a flag so we know we need to recalculate it for each model
if(!tf.modelPreferences || tf.modelPreferences.sankeyDecimalPrecision === null || tf.modelPreferences.sankeyDecimalPrecision === undefined)
tf.recalculateSankeyDecimalPrecision = true;
if(tf.recalculateSankeyDecimalPrecision && scaleFactorForDisplay) {
// scale the value to how it will be displayed, e.g. a value of 100 for "100mil" instead of 1e8
var scaledLargestValue = scaleFactorForDisplay.realValue * scaleFactorForDisplay.displayNumericScale;
// this logic forces the sankey decimal precision to be exactly enough decimals to match the required general # of significant figures,
// for the largest value
tf.modelPreferences = tf.modelPreferences || {};
tf.modelPreferences.sankeyDecimalPrecision = Math.max(0, (tf.decimalPrecision || 3) - 1 - Math.floor(Math.log(Math.abs(scaledLargestValue))/Math.log(10)));
// this if block should only be called once
tf.recalculateSankeyDecimalPrecision = false;
}
} catch(e) {}
answerUnit = forecastModel.companyData.getSankeyRootAnswer().answerUnit;
if (!answerUnit) answerUnit = "";
var answerUnitOptionDollar = "Dollars ($)";
var answerUnitOptionPercent = "Percent";
if (forecastModel.companyData.il.provider == 'PFIZER') {
answerUnitOptionDollar += " NPV";
answerUnitOptionPercent = "NPV " + answerUnitOptionPercent;
}
headerDropdown.setOptions(
[answerUnit == "$" ? answerUnitOptionDollar : (answerUnit == "" ? "Units" : answerUnit), answerUnitOptionPercent]);
$.each(nodes, function(id, node) {
node.clear();
});
nodes = {};
paper.clear();
if(SeriesUtil.getValueIdentifiers(root)[params.selectedPeriod]) {
rootNode = new Node(
root,
forecastModel,
paper,
div,
null, //parent
nodes,
{click: createNodeClickListener, mouseover: createNodeMouseOverListener, mouseout: createNodeMouseOutListener},
params,
answerUnit,
scaleFactorForDisplay
);
$.each(paper.canvas.childNodes, function(id, node) {
node.style['cursor'] = 'pointer';
});
$('a.sshDivTblA', div).each(function () {
if (params.nameDecoratorCallback && params.editableDivisionNames) {
var collectionId = $(this).data('datum').identifier;
// first, check divisions
var diffChangeType = findSankeyDiffChangeType('Division', collectionId, '*', false);
// if not there, check super divisions
if (_.isEmpty(diffChangeType)) {
diffChangeType = findSankeyDiffChangeType('SuperDivision', collectionId, '*', false);
};
if (diffChangeType.direct) {
$(this).addClass('directChange')
};
if (diffChangeType.indirect) {
$(this).addClass('indirectChange')
};
var divisionDatum = forecastModel.companyData.getDivisionDatum(collectionId);
// If this division is linked 1-1 to a stream, then update one along with the other
// for this you need to link the two models so they get the save name update
var updateLinked = (divisionDatum !== undefined &&
divisionDatum.streams !== undefined &&
divisionDatum.streams.length == 1);
params.nameDecoratorCallback(false, $(this), collectionId, {
type: 'DIVISION',
currentDivision: collectionId,
linkedModel: updateLinked ? divisionDatum.streams[0].identifier : undefined
});
}
});
forecastModel.addChangeListener(modelChangeListener);
// render the initial sankey
applyDynamicData(calculateDynamicData());
updateValueText();
} else {
// for some reason we don't have a sankey, so show an error message
var t = paper.text(150, 70, 'No Breakdown Available')
.attr({'font-size': 20, fill: '#fff'});
}
};
selfSankey.setModel = setModel;
function modelChangeListener(isFinal, driverSetChanged) {
updateValueText();
if(isFinal) {
var dynamicData = calculateDynamicData();
var duration = 500;
$.each(nodes, function(id, node) {
node.bloop(duration, dynamicData, params.inspectorLeftEdge);
});
setTimeout(function() {
applyDynamicData(dynamicData, 500);
}, duration);
}
}
/*
* Methods for applying dynamic data
*/
/**
* Updates the % value text on the RHS of sankey arms.
*/
function updateValueText() {
var selectedPeriod = periodSelectionManager ? periodSelectionManager.getSelectedPeriod() : null;
var denominator = calculateDenominatorForPercentages(selectedPeriod);
var useAbsolute = !headerDropdown.getSelected();
$.each(nodes, function(id, node) {
node.updateValueText(selectedPeriod, useAbsolute, denominator);
});
renderPartialSums(currentDynamicData, useAbsolute)
}
/**
* Updates the state of the sankey to match the given dynamicData.
*
* @param {Object} dynamicData
* @param {int} duration number of ms over which the sankey should animate to the new state. Can
* be 0 or null/undefined if the sankey should change immediately rather than animate.
* @param {Function} callback will be called at the end of the animation, or immediately if there is no animation.
* Can be null.
*/
function applyDynamicData(dynamicData, duration, callback) {
duration = duration || 0;
currentDynamicData = dynamicData;
rootNode.applyDynamicNodeData(dynamicData, duration);
// the white "DIVISION" label at the top needs to be left aligned with the division labels
div
.find('.sshDivTblHeader.sshDivTblLHS')
.animate({left: dynamicData.columns[NODE_STATE_NORMAL].getRightEdge() + 10}, duration);
// the white "PERCENT" / "DOLLARS" dropdown on the top right needs to be right aligned with the number column
div
.find('.sshDivTblHeader.sshDivTblRHS')
.add(headerDropdown.popupDiv)
.animate({right: dynamicData.params.getWidth() - dynamicData.params.textWidth - 12}, duration);
renderPartialSums(dynamicData, !headerDropdown.getSelected(), duration);
if(callback) {
if(duration) {
setTimeout(callback, duration);
} else {
callback();
}
}
paper.setSize(params.width, dynamicData.maxY+30);
if(params.heightChangeEvent)
params.heightChangeEvent();
}
/**
* gives the total height of the sankey visualization
* @return {Number}
*/
selfSankey.height = function() {
return currentDynamicData ? currentDynamicData.maxY : null;
};
/**
* gives the y coordinate (relative to the main sankey div) of any sankey arm that's extended to
* meet the insector. Can return null if no arm is extended.
* @return {Number}
*/
selfSankey.extenderY = function() {
return currentDynamicData ? currentDynamicData.extenderY : null;
};
/**
* Draws the red/green partial sum brackets to the RHS of the sankey values
* @param {Object} dynamicData
* @param {boolean} useAbsolute whether to use absolute or % values
* @param {int} duration duration of the animation, or null if no animation
* and just update immediately
*/
function renderPartialSums(dynamicData, useAbsolute, duration) {
if(dynamicData.params.renderPartialSums==false)return;
duration = duration || 0;
var numbersColumnRightEdge = dynamicData.params.textWidth;
var lineHeight = 16;// TODO textContainer.css('lineHeight');
var selectedPeriod = periodSelectionManager ? periodSelectionManager.getSelectedPeriod() : null;
var denominator = calculateDenominatorForPercentages(selectedPeriod);
// fade out any old partial sums
div
.find('.sshDivTblSumRect,.sshDivTblSum')
.addClass('oldPartialSum') // tag the old partial sums with a class so we can easily remove them without accidentally removing the new partial sums
.fadeOut(duration, function() {
div
.find('.oldPartialSum')
.remove();
});
// create new partial sum divs
$.each(dynamicData.partialSums, function(i, partialSum) {
div
.append($('
', {
'class': 'sshDivTblSumRect ' + (partialSum.positive ? 'pos' : 'neg'),
css: {
top: partialSum.yTop + 'px',
height: (partialSum.yBottom - partialSum.yTop) + 'px',
left: (numbersColumnRightEdge + 10) + 'px'
}
}))
});
div
.find('.sshDivTblSumRect,.sshDivTblSum')
.not('.oldPartialSum')
.fadeIn(duration);
}
/**
* Helper function for applyDynamicData, calculates the value that should be used as the denominator
* for all the division percentages that appear on the RHS.
* @param {Object} params
* @return {Number}
*/
function calculateDenominatorForPercentages(selectedPeriod) {
var result = 0;
$.each(rootNode.rightChildren, function(i, child) {
var val = child.value(selectedPeriod);
if(val > 0)
result += val;
});
return result;
}
/*
* Methods for calculating dynamic data
*/
/**
* Calculates and returns dynamicData for the sankey matching the given params
* @param {Object} overrideParams key/value pairs of sankey parameters. For any values
* not defined here, we'll use the default values. Can be null to use all default values. Here are the accepted fields:
*{Number} rootTubeWidth: width of the root of the sankey
*{int} heightForText: approximate line-height of the text divs that contain the nodes' names
*{int} width: width of the sankey's rendering area
*{int} height: height of the sankey's rendering area
*{int} widthForRHSColumn: amount of width to allocate for the % value column on the RHS of the sankey
*{int} minArmSpacing: minimum amount of vertical pixels to put between each sankey arm
*{int} maxArmSpacing: maximum amount of vertical pixels to put between each sankey arm
*{int} rootVerticalPosition: vertical position from the top of the sankey area to the midpoint of the root node
*{String} selectedPeriod: code of the selected period to render; can be null if the model type doesn't have a selected period (e.g. DCF models)
*{String} selected: identifier of the currently selected node in the sankey; can be null if e.g. sankey is in default state
* {int} fontSize: if set, fixes a particular font size for all nodes in the sankey
* fully extended to be flush with inspector
* @return {Object} with following fields:
* {Object} nodes: map from node identifiers to dynamic datum for each node
* {Object} params: the sankey parameters used to generate this dynamic data
* {Object} columns: map from node state to corresponding Column
* {Array} partialSums: array of objects with data on each partial sum bracket. can be an empty array, but cannot be null
*/
function calculateDynamicData(overrideParams) {
var paramsToUse = $.extend({}, params, overrideParams || {});
// create (empty) data for each node; these will be filled in in the rest of this method
var dynamicData = {};
$.each(nodes, function(id, node) {
dynamicData[id] = {};
});
paramsToUse.state = determineState(paramsToUse);
/*
* fill in some more properties on the nodes
*/
rootNode.calculateStateAndVisibility(paramsToUse, dynamicData, true);
rootNode.calculateTubeWidths(params.rootTubeWidth, paramsToUse, dynamicData);
rootNode.calculateFontSizes(paramsToUse, dynamicData);
var spacingCounts = rootNode.countSpaces(paramsToUse, dynamicData);
var armSpacing = calculateArmSpacing(paramsToUse, spacingCounts)
var estimatedHeight = _.reduce(dynamicData, function(acc, e) { return acc + (e.fontSize || 0) }, 0) + armSpacing * _.size(dynamicData)
paramsToUse.textWidth = Math.max(
0.75 * paramsToUse.getWidth(estimatedHeight),
Math.min(rootNode.measureMaxTextWidth(dynamicData, textMeasurer) + paramsToUse.widthForRHSColumn, 0.85 * paramsToUse.getWidth(estimatedHeight))
);
/*
* figure out the columns that will define the x-positions of everything in the sankey
*/
var columns = getColumns(rootNode, paramsToUse, dynamicData, textMeasurer);
/*
* assign positions to each of the nodes
*/
assignXPositions(columns, dynamicData);
assignYPositions(paramsToUse, dynamicData);
/*
* Calculate positions of any "partial sums" along the RHS
*/
var partialSums = generatePartialSums(paramsToUse, dynamicData);
return {
params: paramsToUse,
nodes: dynamicData,
columns: columns,
partialSums: partialSums
};
}
/**
* Helper function for calculateDynamicData, returns the state of the sankey -- e.g. is a superdivision selected? division selected?
* @return {int} sankey state; must be one of the SANKEY_STATE_* values defined at top of this file
*/
function determineState(params) {
var selectedNode;
if(params.selected) {
$.each(nodes, function(id, node) {
if(id == params.selected && node.parent) {
selectedNode = node;
return false;
}
});
}
if(!selectedNode)
return params.retracted ? SANKEY_STATE_DIVISION_SELECTED : SANKEY_STATE_NORMAL;
else if(selectedNode.rightChildren.length)
return SANKEY_STATE_SUPERDIVISION_SELECTED;
else if(selectedNode.parent.parent)
return SANKEY_STATE_SUBDIVISION_SELECTED;
else
return SANKEY_STATE_DIVISION_SELECTED;
}
/**
* Calculates the arm spacing
*/
function calculateArmSpacing(params, spacingCounts) {
var armSpacing
if(params.fused)
armSpacing = 0;
else {
// ideally we want the spacing between each arm to be (total_height - non_spacing_height) / num_spaces
// but we also restrict the spacing between each arm to the min/max provided in the input parameters
armSpacing = (params.height - spacingCounts.nonSpacingHeight) / spacingCounts.numSpaces;
armSpacing = Math.max(params.minArmSpacing, armSpacing);
armSpacing = Math.min(params.maxArmSpacing, armSpacing);
}
return armSpacing
}
/**
* Sets the x positions (basically assigning a column to each node) on dynamicData
* @param {Object} columns map from node state to Column
* @param {Object} dynamicData map from node identifiers to dynamic datum for each node
*/
function assignXPositions(columns, dynamicData) {
rootNode.assignXPositions(columns, dynamicData);
}
/**
* Recurses over the nodes in the tree and saves their calculated y values in dynamicData
* @param {Object} params sankey parameters
* @param {Object} dynamicData map from node identifiers to dynamic datum for each node
*/
function assignYPositions(params, dynamicData) {
var spacingCounts = rootNode.countSpaces(params, dynamicData);
var armSpacing = calculateArmSpacing(params, spacingCounts)
/*
* here we calculate the vertical position of the center of the sankey arms
*/
// this is the y coordinate of the top of the first sankey arm
var yStart;
if(params.fused) {
yStart = params.rootVerticalPosition - spacingCounts.nonSpacingHeight / 2;
} else {
var sankeyArmTotalHeight = spacingCounts.nonSpacingHeight + (armSpacing * spacingCounts.numSpaces);
var actualRootTubeWidth = dynamicData[rootNode.datum.identifier].tubeWidth;
// ideally, the arms are vertically centered within the available height
var desiredCenter = params.height / 2;
// however, the center can't be so low that the top of the first arm is within 20 pixels of the top of the root
var maxCenter = params.rootVerticalPosition - actualRootTubeWidth / 2 - 20 + sankeyArmTotalHeight / 2;
// also, we don't want the center of the arms to be above the midpoint of the arrow on the root
var minCenter = params.rootVerticalPosition + (params.rootTubeWidth - actualRootTubeWidth) / 2;
// so we adjust the desired center according to these constraints, with the minCenter constraint
// overriding the maxCenter constraint
if(desiredCenter > maxCenter)
desiredCenter = maxCenter;
if(desiredCenter < minCenter)
desiredCenter = minCenter;
yStart = Math.max(0, desiredCenter - sankeyArmTotalHeight / 2);
}
rootNode.assignYPositions(
armSpacing,
{y: yStart},
params,
dynamicData);
}
/**
* Creates the partial sums that should be shown in this state of the sankey.
* @return {Array} array of partial sum objects, each with fields:
* {boolean} positive: whether the sum should be green or red
* {Number} yTop: top of bracket
* {Number} yBottom: bottom of bracket
* {Number} value: sum value associated with this bracket
*/
function generatePartialSums(params, dynamicNodeData) {
var result = [];
if(params.state == SANKEY_STATE_NORMAL) {
var positiveSum = createPartialSum(rootNode.getPositiveOrNegativeRightChildren(true, params.selectedPeriod), dynamicNodeData);
if(positiveSum)
result.push(positiveSum);
var negativeSum = createPartialSum(rootNode.getPositiveOrNegativeRightChildren(false, params.selectedPeriod), dynamicNodeData);
if(negativeSum)
result.push(negativeSum);
} else if(params.state == SANKEY_STATE_SUPERDIVISION_SELECTED) {
var selectedNode = nodes[params.selected];
if(selectedNode) {
var superDivisionSum = createPartialSum(selectedNode.rightChildren, dynamicNodeData);
if(superDivisionSum)
result.push(superDivisionSum);
}
}
return result;
}
/**
* Creates a single partial sum of the given nodes. Can return null if e.g. there aren't enough nodes
* to warrant a partial sum.
* @param {Array} nodesInPartialSum array of Node objects who should be added to make this partial sum
* @param {Object} dynamicNodeData
* @return {Object} partial sum struct; see docs on generatePartialSums
*/
function createPartialSum(nodesInPartialSum, dynamicNodeData) {
// only show a sum if there are 2 or more arms
//
if(nodesInPartialSum && nodesInPartialSum.length > 1) {
// iterate over all the nodes, adding up their values, and determining the top and bottom of the bracket
//
var value = 0;
var yTop = Number.MAX_VALUE;
var yBottom = Number.MIN_VALUE;
$.each(nodesInPartialSum, function(i, node) {
var dynamicDatum = dynamicNodeData[node.datum.identifier];
if(dynamicDatum) {
yTop = Math.min(yTop, dynamicDatum.y - dynamicDatum.effectiveTubeWidth/2);
yBottom = Math.max(yBottom, dynamicDatum.y + dynamicDatum.effectiveTubeWidth/2);
value += dynamicDatum.value;
}
});
return {
positive: value >= 0,
yTop: yTop + 5, // push the partial sums down by 5px because the division text tends to sit a little below the centerline of the sankey arms
yBottom: yBottom + 5,
value: value
};
}
}
/**
* Sets the currently selected node in the sankey tree.
* @param {String} selected id of the selected node, or can be null for default state
* @param {boolean} retracted whether the sankey's arms should be pulled to the left;
* only applies when no node is selected
* @param {boolean} animate whether to animate the transition or just have it adjust instantly
* @param {Function} callback will be called with no arguments when animation is complete
*/
selfSankey.setSelected = setSelected;
function setSelected(selected, retracted, animate, callback) {
// if we're already at the desired state, don't do any animations
if(params.selected == selected && params.retracted == !!retracted) {
if(callback) callback();
return;
}
params.selected = selected;
params.retracted = !!retracted;
// this is the final state, after the animation is done
var newDynamicData = calculateDynamicData();
if(animate) {
// determine the sankey state at each phase of the animation, by interpolating individual fields between the current and final states
// the division click animation occurs in 5 phases:
// - hide any text that needs to be hidden, and retract any inspector extension
// - hide any sankey arms that need to be hidden
// - move the sankey arms to their new position
// - show any sankey arms that need to be made visible
// - show any text on arms that were just made visible, and extend any inspector extension
var phases = [];
// hide text phase: turn textVisible, rhsValueTextVisible, and extended OFF
var hideTextPhase = dynamicDataInterpolater(currentDynamicData, newDynamicData, ['textVisible', 'rhsValueTextVisible', 'extended'], false, false);
if(hideTextPhase.changed || currentDynamicData.partialSums.length) {
hideTextPhase.columns = currentDynamicData.columns;
hideTextPhase.partialSums = [];
phases.push(hideTextPhase);
}
// hide phase: turn visible OFF
var hidePhase = dynamicDataInterpolater(hideTextPhase, newDynamicData, ['visible'], false, false);
if(hidePhase.changed) {
hidePhase.columns = currentDynamicData.columns;
hidePhase.partialSums = [];
phases.push(hidePhase);
}
// move phase: set invertFields=true so that all fields BESIDES visible, textVisible, rhsValueTextVisible, and extended are moved to the new position
var movePhase = dynamicDataInterpolater(hidePhase, newDynamicData, ['visible', 'textVisible', 'rhsValueTextVisible', 'extended'], true, false);
movePhase.columns = newDynamicData.columns;
movePhase.partialSums = [];
phases.push(movePhase);
// show phase: turn visible ON
var showPhase = dynamicDataInterpolater(movePhase, newDynamicData, ['visible'], false, true);
if(showPhase.changed) {
showPhase.columns = newDynamicData.columns;
showPhase.partialSums = [];
phases.push(showPhase);
}
// show text phase: turn textVisible, rhsValueTextVisible, and extended ON
var showTextPhase = dynamicDataInterpolater(showPhase, newDynamicData, ['textVisible', 'rhsValueTextVisible', 'extended'], false, true);
if(showTextPhase.changed || newDynamicData.partialSums.length) {
phases.push(showTextPhase);
}
// execute each phase sequentially
chainPhases(phases, RENDER_OPTIONS.animationDuration, callback);
} else {
// no animation, so can just set the new state immediately
applyDynamicData(newDynamicData, 0, callback);
}
};
/**
* Helper function for animations. Builds an intermediate sankey state between the two given ones.
* The returned dynamicData will have each node's data identical to oldData (or newData, if invertFields=true),
* EXCEPT for the given fields. For those fields, if the value differs between the old and new data, then the value
* will be set to overrideValue.
*
* @param {Object} oldData old dynamicData
* @param {Object} newData new dynamicData
* @param {Array} fields array of Strings indicating the fields of each node's dynamicNodeDatum that should be changed
* @param {boolean} invertFields if true, fields will default to values from newData, otherwise default to values from oldData
* @param {boolean} overrideValue the value to which any of the given fields should be set IF they differ between old and new data
* @param {Object} dynamicData
*/
function dynamicDataInterpolater(oldData, newData, fields, invertFields, overrideValue) {
var result = {};
var changed;
$.each(oldData.nodes, function(key, oldDatum) {
newDatum = newData.nodes[key];
result[key] = {};
if(newDatum && oldDatum) {
// iterate over the keys that appear in either oldDatum or newDatum.
// we do this by creating a new object via $.extend which has all of oldDatum and newDatum
// copied into it, then iterate over its keys. The values of this composite object are discarded
$.each($.extend({}, oldDatum, newDatum), function(field, meaninglessValue) {
if($.inArray(field, fields) >= 0 && !!oldDatum[field] != !!newDatum[field]) {
if(!!(invertFields ? newDatum[field] : oldDatum[field]) != overrideValue)
changed = true;
result[key][field] = overrideValue;
} else {
result[key][field] = invertFields ? newDatum[field] : oldDatum[field];
}
});
}
});
return $.extend(true, {}, newData, {nodes: result, changed: changed});
}
/**
* Executes a series of animation phases sequentially
* @param {Array} phases array of dynamicData for each phase of the animation
* @param {int} phaseDuration duration of each phase
* @param {Function} callback will be called when all animations are complete
*/
function chainPhases(phases, phaseDuration, callback) {
applyDynamicData(
phases[0],
phaseDuration,
phases.length > 1
? function() { chainPhases(phases.slice(1), phaseDuration, callback); }
: callback);
}
/**
* Sets whether the sankey is in a "retracted" state. The "retracted" state
* squishes all division arms to the left so they overlap less with the derived
* model popup & secondary driver inspectors. Note that calling this method
* (with either retracted=true or retracted=false) will deselect any selected division.
*
* @param {boolean} retracted
* @param {boolean} needsAnimation whether to animate the transition or just have it adjust instantly.
* If no argument passed, defaults to true
* @param {Function} optional callback to be called once the animation is done
*/
selfSankey.setRetracted = function(retracted, callback, needsAnimation) {
var animate = true;
// explicitly declare false - don't catch on undefined.
if (needsAnimation === false){
animate = needsAnimation;
}
setSelected(null, retracted, animate, callback);
};
function createNodeClickListener(identifier) {
var func = function() {
var node = nodes[identifier];
if(!node || !node.parent) {
selfSankey.clickListener(null, false);
} else if (params.selected == identifier) {
// extend parent
selfSankey.clickListener(node.parent.datum.identifier, false);
}else {
if(node.rightChildren.length) {
// super division
selfSankey.clickListener(identifier, false);
gaEvent(['modelwidget', 'superdivision', node.datum.text]);
} else {
// division, so e.g. need to open inspector
selfSankey.clickListener(identifier, true);
gaEvent(['modelwidget', 'division', node.datum.text]);
}
}
return false;
};
return func;
}
function createNodeMouseOverListener(identifier) {
return function() {
if(params.selected != identifier) {
div.find(".sshDivTblDiv[data-id=" + identifier + ']')
.addClass("sshDivTblDivGlow");
}
};
}
function createNodeMouseOutListener(identifier) {
return function() {
div.find(".sshDivTblDivGlow").removeClass("sshDivTblDivGlow");
};
}
/**
* Calculate and set the dimensions, and then shrink the sankey chart to fit the container
*/
var dimensions = (function getActualDimensions() {
var $labels = div.find('.sshDivTblLHS.sshDivTblDiv')
// Gets the position of the label at the bottom-right corner of the chart
var corner = _.max($labels.map(function() {
return {
offset: { left: parseFloat($(this).css('left')), top: parseFloat($(this).css('top')) },
height: $(this).outerHeight(),
width: $(this).outerWidth()
}
}).toArray(), function(label) {
return label.offset.top
})
return {
height: corner.offset.top + corner.height,
width: corner.offset.left + corner.width
}
})()
div.css('height', dimensions.height +'px')
div.css('width', dimensions.width +'px')
var $svg = div.find('svg')
$svg.attr('width', dimensions.width)
$svg.attr('height', dimensions.height)
var aspectRatio = dimensions.width / dimensions.height
, widthRatio = containerDimensions.width / dimensions.width
, heightRatio = containerDimensions.height / dimensions.height
div.css('zoom', aspectRatio > 1 ? widthRatio : heightRatio)
div.show() // Show the chart since we're done rendering
}; // end SankeyDiagram
// =============================================================
// ========================== NODE =============================
// =============================================================
/**
* Represents a single node in the sankey tree.
*
* To make animations and state changes easier, a Node's properties are split into its immutable properties (in the datum object)
* and its dynamic properties (in currentDynamicDatum). Its immutable properties are set in the constructor and never changed.
* Its dynamic properties can be set using applyDynamicNodeData.
*
* The immutable fields on the datum object are:
* {String} identifier: unique identifier for the node (generally a collection identifier)
* {Sting} text: user-readable name for the node
* {boolean} reversed: if true, node should appear as an outflow coming off the left side of the sankey (e.g. debt)
* {Object} identifiers: map from each period code to the corresponding identifier that backs this node
* {boolean} cash: whether this node represents cash
* {boolean} debt: whether this node represents debt
* {boolean} bottom: if true, this node should be sorted to the bottom of the sankey arms
* {Array} rightChildren: array of data objects for any children that come off the right side of the sankey (normal sankey arms)
* {Array} reversedChildren: array of data objects for any children that come off the left side of the sankey (e.g. debt)
*
* While the dynamic properties on currentDynamicDatum are:
* {int} state: one of the NODE_STATE_* values
* {boolean} visible: whether the node is currently visible
* {boolean} textVisible: whether the text of the node is currently visible (node can be visible while text is invisible, e.g. for selected super divisions)
* {boolean} rhsValueTextVisible: whether the % value text on the far RHS is currently visible
* {Number} value: dollar value associated with this node
* {Number} tubeWidth: width in pixels of this node's sankey arm
* {Number} effectiveTubeWidth: the amount of vertical space the arm takes up, including its text, if visible
* {int} fontSize: font size of the text
* {Column} column: reference to the column in which this node lives
* {Number} y: vertical coordinate of the end of the sankey arm
* {Number} connectorY: vertical coordinate of the left end of the sankey arm, where it connects to its parent node
*
*
* @param {Object} datum holds all the static data about this node -- e.g. its name, whether it's cash/debt or not, etc.
* Generally provided by the static JSON company data's treeData field.
* @param {ForecastModel} forecastModel
* @param {Paper} paper raphael's paper object
* @param {jQuery} container the div that contains the sankey stuff; needed because the Node will create text divs that
* need to be added to the container
* @param {Node} parent parent of this node, or null if root node
* @param {Object} nodes a map from node identifiers to the Node objects themselves.
* @param {Object} listeners -- should have "click", "mouseover", and "mouseout" fields with functions that take an identifier
* and return a click listener for that identifier
* @param {String} answerUnit -- the unit of the sankey root answer, which we should use for formatting any values
* @param {Object} scaleFactorForDisplay -- a result of UnitUtil.calculateScaleFactorForDisplay appropriate for formatting all values
* in the sankey -- used to ensure that all sankey values are formatted with the same scale factor
* @constructor
*/
function Node(datum, forecastModel, paper, container, parent, nodes, listeners, params, answerUnit, scaleFactorForDisplay) {
var selfNode = this;
var connector = parent ? paper.path('') : null; // the bezier curve of the sankey arm
var extender = parent ? paper.path('') : null; // the extender path
var rootElements = parent ? null : [paper.path(''), paper.path('')]; // the rectangular cap at the end of the sankey arm, if necessary
var rightChildren = []; // array of Nodes that are the children that come off to the right of the sankey. immutable. not sorted in any particular order.
var reversedChildren = []; // array of Nodes that are the children that come off to the left of the sankey. immutable. not sorted in any particular order.
var allChildren; // array of Nodes that is the union of rightChildren and reversedChildren. also immutable. not sorted.
var currentDynamicDatum; // current status of any dynamic properties, e.g. value, tubeWidth, state
// create the divs that hold the node's name, and % value
// note that the structure & CSS classes here match the templates for the server-side sankey rendering, in e.g. tags/widget/sankeyDivision.tag
var textContainer;
if(datum.reversed) {
textContainer = $('
', {
'class': 'sshDivTblRHS sshDivTblVal clientSide'
}))
;
//}
// listening for both "click" and "touchstart" events for better compatibility with
// iPads and iPad simulators.
// Note that we do this with a separate .on(...) call instead of using the attributes above
// because the touchstart attribute isn't well-supported by jQuery.
// Also, the "touchstart" listener has a downside that if a user tries to scroll or zoom
// in the sankey area using touch, the actions may be interpreted as clicks on divisions
// instead, which isn't ideal. In theory iPad should be able to use just click listeners
// here but it seems buggy.
textContainer.on('click touchstart', listeners.click(datum.identifier));
// Add chart link for division
var link = $('');
link.attr('href', "#");
link.attr('class', 'sm_chart');
link.data('datum', datum);
var xCloseDiv = $("", {
"class": "xCloseDivisionDiv"
}).append(link);
textContainer.append(xCloseDiv);
link.click({datum: datum, companyData: forecastModel.companyData, unit: forecastModel.companyData.getSankeyRootAnswer().answerUnit}, chartPopup);
}
}
container.append(textContainer);
if(connector) {
connector.node.onclick = listeners.click(datum.identifier);
connector.node.onmouseover = listeners.mouseover(datum.identifier);
connector.node.onmouseout = listeners.mouseout(datum.identifier);
}
// save this node into the map of all nodes
nodes[datum.identifier] = selfNode;
// create Nodes recursively for all children
// note that models from new parser have rightChildren and reversedChilden fields
// models from parser have a single "child" field, and its elements have an isNegative
// field to distinguish right from reversed
// (once old models have been transitioned to new system, can remove the datum.child processing part
if(datum.componentBreakdowns && datum.componentBreakdowns.length > 0 && datum.componentBreakdowns[0].components.length > 0) {
$.each(datum.componentBreakdowns[0].components, function(i, childDatum) {
if(SeriesUtil.getValueIdentifiers(childDatum)[params.selectedPeriod])
rightChildren.push(new Node(childDatum, forecastModel, paper, container, selfNode, nodes, listeners, params, answerUnit, scaleFactorForDisplay));
});
}
if(datum.reversedChildren) {
$.each(datum.reversedChildren, function(i, childDatum) {
if(SeriesUtil.getValueIdentifiers(childDatum)[params.selectedPeriod])
reversedChildren.push(new Node(childDatum, forecastModel, paper, container, selfNode, nodes, listeners, params, answerUnit, scaleFactorForDisplay));
});
}
if(datum.bitFlags && (datum.bitFlags & 524288)) datum.cash = true;
// this simply builds a new array that contains all the elements of rightChildren and reversedChildren,
// without modifying rightChildren or reversedChildren
allChildren = $.merge($.merge([], rightChildren), reversedChildren);
// =====================================
// =========== METHODS ==================
// =====================================
/**
* @param {Object} dynamicDatum
* @return {Object} set of options like the ones defined in DEFAULT_NODE_RENDER_OPTIONS
* for cash, positive, negative, reversed, or root
*/
function getRenderOptions(dynamicDatum) {
return RENDER_OPTIONS[dynamicDatum.state == NODE_STATE_REVERSE
? 'reversed'
: (datum.cash
? 'cash'
: (dynamicDatum.positive
? 'positive'
: 'negative'))];
}
selfNode.clear = function() {
if(textContainer)
textContainer.remove();
if(connector) {
connector.node.onclick = connector.node.onmouseover = connector.node.onmouseout = null;
}
};
/**
* Runs the "bloop" animation where a sankey arm's width changes from right-to-left, as used when
* the user modifies a chart.
* @param {int} duration
* @param {Object} dynamicData note that only the tubeWidth property will be used
* @param {Number} clipWidth width of the region over which the right-to-left change should propagate
*/
selfNode.bloop = function(duration, dynamicData, clipWidth) {
var dynamicDatum = dynamicData.nodes[datum.identifier];
// just like current dynamic data, except with the tubeWidth from teh new dynamic data
var dynamicDatumToUse = $.extend({}, currentDynamicDatum, {tubeWidth: dynamicDatum.tubeWidth});
// tells whether the tubewidth is growing or shrinking
var growing = currentDynamicDatum.tubeWidth < dynamicDatum.tubeWidth;
/*
* The bloop works by making a new copy of the elements, and wiping out the old element and/or wiping in the new element
*/
if(connector && currentDynamicDatum.visible) {
var oldConnector = connector;
connector = paper.path('');
connector.node.onclick = oldConnector.node.onclick;
connector.node.onmouseover = oldConnector.node.onmouseover;
connector.node.onmouseout = oldConnector.node.onmouseout;
var newPath = createConnectorPath(dynamicDatumToUse, dynamicData, connector);
connector.attr(newPath);
setConnectorFill(dynamicDatumToUse);
bloopHelper(oldConnector, connector, growing, duration, clipWidth);
}
if(extender && currentDynamicDatum.extended) {
var oldExtender = extender;
extender = paper.path('');
var newPath = createExtenderPath(dynamicDatumToUse, dynamicData.params, extender);
extender.attr(newPath);
var options = getRenderOptions(dynamicDatumToUse);
extender.attr({fill: options.extenderFill});
bloopHelper(oldExtender, extender, growing, duration, clipWidth);
}
};
/**
* helper function for bloop, wipes in a new element from right to left
* @param {Element} oldElement
* @param {Element} newElement
* @param {boolean} growing tells whether the tubewidth is growing or shrinking
* @param {int} duration
* @param {Number} clipWidth
*/
function bloopHelper(oldElement, newElement, growing, duration, clipWidth) {
if(growing) {
// for growing tubes we wipe in the new element, and then hide the old element
newElement
.attr({'clip-rect': [clipWidth, 0, 0, 1000].join(' ')})
.animate(
{'clip-rect': [0, 0, clipWidth, 1000].join(' ')},
duration,
'linear',
function() {
removeClipRect(newElement);
oldElement.remove();
});
} else {
// for shrinking tubes we wipe out the old element, then hide it
oldElement
.attr({'clip-rect': [0, 0, clipWidth, 1000].join(' ')})
.animate(
{'clip-rect': [0, 0, 0, 1000].join(' ')},
duration,
'linear',
function() {
oldElement.remove();
});
}
}
/**
* Calculates the attributes to be used for the connector bezier
* @param {Object} dynamicDatum
* @param {Object} dynamicData
* @param {Element} element the element to which the attributes will be applied (needed for de-duping)
* @return {Object} element attributes
*/
function createConnectorPath(dynamicDatum, dynamicData, element) {
var options = getRenderOptions(dynamicDatum);
var path = [];
var tubeWidth = dynamicDatum.tubeWidth;
if(tubeWidth= 0)
positiveValue += value;
else
negativeValue -= value;
});
return negativeValue / (positiveValue + negativeValue);
}
/**
* Takes a set of element attributes and returns a set with only the attributes
* that differ from the current state of the element. This is useful when animating,
* so we don't animate attributes that aren't actually changing. This avoids flickering
* in animations
* @param {Element} element
* @param {Object} attrs
* @return {Object}
*/
function dedupeElementAttrs(element, attrs) {
var newAttrs = $.extend({}, attrs);
$.each(attrs, function(key, val) {
if($.isArray(val)) {
if(deepEqualsArrays(element.attr(key), val)) {
delete newAttrs[key];
}
} else {
if(element.attr(key) === val)
delete newAttrs[key];
}
});
return newAttrs;
}
/**
* Helper function for dedupeElementAttrs.
* @return {boolean} true iff the given params are both arrays, and
* their elements are equal (including a deep equality check for nested arrays)
*/
function deepEqualsArrays(arr1, arr2) {
if(!$.isArray(arr1) || !$.isArray(arr2) || arr1.length != arr2.length)
return false;
var result = true;
$.each(arr1, function(i, el1) {
var el2 = arr2[i];
if($.isArray(el1)) {
if(!deepEqualsArrays(el1, el2)) {
result = false;
return false;
}
} else {
if(el1 !== el2) {
result = false;
return false;
}
}
});
return result;
}
/**
* @param {Object} obj
* @return {booelan} true iff the given object has any fields
*/
function hasKeys(obj) {
var result = false;
$.each(obj, function() {
result = true;
return false;
});
return result;
}
/**
* Sets the proper fill attribute on the connector
* @param {Object} dynamicDatum
*/
function setConnectorFill(dynamicDatum) {
var options = getRenderOptions(dynamicDatum);
connector.attr({fill: options[parent && parent.parent ? 'subFill' : 'superFill']});
}
/**
* Removes the clip-rect attribute from an element
* @param {Element} element
*/
function removeClipRect(element) {
// setting clip-rect to null causes problems in IE, so instead we set the clip rect to some
// very large rectangle
element.attr({'clip-rect': '0 0 1000 1000'});
}
/**
* Updates the state of the node to match the given dynamicData.
*
* @param {Object} dynamicData map from node identifiers to dynamicDatum objects
* This only needs to be changed when first creating the sankey, or when the sankey's values change b/o a user modification
* @param {int} duration the number of ms over which the animation for the state change should occur. Can be 0 or null/undefined
* if the sankey should update immediately, with no animation.
*/
selfNode.applyDynamicNodeData = function(dynamicData, duration) {
var dynamicDatum = dynamicData.nodes[datum.identifier];
var options = getRenderOptions(dynamicDatum);
var inspectorVisible = dynamicData.params.state == SANKEY_STATE_DIVISION_SELECTED || dynamicData.params.state == SANKEY_STATE_SUBDIVISION_SELECTED;
if(!parent) { //root node
// note we don't bother animating the root node, since its changes are generally minor
var positiveRootAttrs = createRootPath(dynamicDatum, dynamicData.params, rootElements[0], true);
if(hasKeys(positiveRootAttrs))
rootElements[0].attr(positiveRootAttrs);
var negativeRootAttrs = createRootPath(dynamicDatum, dynamicData.params, rootElements[1], false);
if(hasKeys(negativeRootAttrs))
rootElements[1].attr(negativeRootAttrs);
}
else if(connector) {
// update the bezier path, if it exists
if(dynamicDatum.visible) {
var connectorAttrs = createConnectorPath(dynamicDatum, dynamicData, connector);
// direct children of root get a different fill than grandchildren, because the root is grey
// also note that we set the fill now, rather than as part of animation, because animating fills leads to flicking in SVG animations
setConnectorFill(dynamicDatum);
// note that we do not animate debt nodes, since their changes are generally minor
if(duration && dynamicDatum.state != NODE_STATE_REVERSE) {
if(currentDynamicDatum && currentDynamicDatum.visible) {
removeClipRect(connector);
if(hasKeys(connectorAttrs)) {
connector
.animate(
connectorAttrs,
duration,
'<>'
);
}
} else {
// in this case the node is going from invisible to visible, so do a "wipe" animation where the node appears from left to right using a clipping mask
connector
.attr(connectorAttrs)
.attr({'clip-rect': [dynamicDatum.column.getLeftEdge(), 0, 0, 1000].join(' ')})
.show()
.animate(
{'clip-rect': [dynamicDatum.column.getLeftEdge(), 0, dynamicDatum.column.getRightEdge() - dynamicDatum.column.getLeftEdge(), 1000].join(' ')},
duration,
'linear',
function() {
removeClipRect(connector);
}
);
}
} else {
connector
.attr(connectorAttrs)
.show();
}
} else {
if(currentDynamicDatum && currentDynamicDatum.visible) {
// in this case the node is going from visible to invisible, so do a "wipe" animation where the node disappears from right to left using a clipping mask
connector
.attr({'clip-rect': [dynamicDatum.column.getLeftEdge(), 0, dynamicDatum.column.getRightEdge() - dynamicDatum.column.getLeftEdge(), 1000].join(' ')})
.animate(
{'clip-rect': [dynamicDatum.column.getLeftEdge(), 0, 0, 1000].join(' ')},
duration,
'linear',
function() {
connector.hide()
});
}
}
}
setTextPosition(dynamicData, duration);
renderExtender(dynamicData, duration);
// recursively update any children
$.each(allChildren, function(i, child) {
child.applyDynamicNodeData(dynamicData, duration);
});
currentDynamicDatum = dynamicDatum;
};
/**
* Helper function for applyDynamicNodeData that renders the extender element
*/
function renderExtender(dynamicData, duration) {
if(!extender)return;
duration = duration || 0;
var dynamicDatum = dynamicData.nodes[datum.identifier];
var attrs = createExtenderPath(dynamicDatum, dynamicData.params, extender, datum);
var options = getRenderOptions(dynamicDatum);
var oldExtended = currentDynamicDatum && currentDynamicDatum.extended;
var newExtended = dynamicDatum.extended;
if(newExtended) {
dynamicData.extenderY=dynamicDatum.y;//we will store the position of the extederY so we can align the inspector with it
extender.attr({fill: options.extenderFill});
if(oldExtended) {
// extender was visible and remains visible, just need to move it
if(hasKeys(attrs))
extender.animate(attrs, duration, '<>');
} else {
// showing extender
extender
.attr(attrs)
.attr({'clip-rect': [dynamicDatum.column.getRightEdge(), 0, 0, 1000].join(' ')})
.show()
.animate(
{'clip-rect': [dynamicDatum.column.getRightEdge(), 0, dynamicData.params.inspectorLeftEdge - dynamicDatum.column.getRightEdge(), 1000].join(' ')},
duration,
'<>'
);
}
} else if(oldExtended) {
// hiding extender
extender
.attr({'clip-rect': [currentDynamicDatum.column.getRightEdge(), 0, dynamicData.params.inspectorLeftEdge - currentDynamicDatum.column.getRightEdge(), 1000].join(' ')})
.animate(
{'clip-rect': [currentDynamicDatum.column.getLeftEdge(), 0, 0, 1000].join(' ')},
duration,
'<>',
function() {
extender.hide()
}
);
}
}
/**
* Helper function for applyDynamicNodeData which moves the text divs to the appropriate position/visibility/style.
* @param {Objet} dynamicDatum
* @param {int} duration
*/
function setTextPosition(dynamicData, duration) {
var dynamicDatum = dynamicData.nodes[datum.identifier];
duration = duration || 0;
// check if we should be showing text at all
if(dynamicDatum.textVisible) {
if(dynamicDatum.state == NODE_STATE_REVERSE) {
textContainer.css({
top: dynamicDatum.y + dynamicDatum.tubeWidth + 10 // pushes the text down enough to clear the debt arrow
});
} else {
var x = dynamicDatum.column.getRightEdge();
var lineHeight = 16;// TODO textContainer.css('lineHeight');
var rhsValueTextVisible = dynamicDatum.rhsValueTextVisible;
var durationForTextProps;
var height = RENDER_OPTIONS.selectedTextBoxMinHeight;//DEFAULT_NODE_RENDER_OPTIONS.selectedTextBoxMinHeight;
if(height < dynamicDatum.tubeWidth) height = dynamicDatum.tubeWidth + (dynamicDatum.extended?10:0); //extra 10 is to make the text box when selected slightly larger the arm width
var width = '';
var maxWidth = '';
if (rhsValueTextVisible) {
width = dynamicData.params.textWidth + 5 - (x + 10 - 3);
} else if (dynamicDatum.extended) {
//as much room as the inspector leaves,
//minus the padding and some space
maxWidth = params.inspectorLeftEdge - x - 50;
}
if(currentDynamicDatum && currentDynamicDatum.textVisible) {
durationForTextProps = duration;
} else {
durationForTextProps = 0;
textContainer.fadeIn(duration);
}
var lineHeight = !dynamicDatum.extended? height : dynamicDatum.fontSize + 4+((height>RENDER_OPTIONS.selectedTextBoxMinHeight)?(height-RENDER_OPTIONS.selectedTextBoxMinHeight)/2:0);
var sshDivTblAVisible = textContainer.find('.sshDivTblA').is(':visible');
var sshDivTblRHSVisible = textContainer.find('.sshDivTblRHS').is(':visible');
var sshDivTblSubVal = !!dynamicDatum.extended;
if (sshDivTblAVisible&&!sshDivTblRHSVisible&&sshDivTblSubVal&&(lineHeight==35)){
// In this scenario, a singular division within the superdivision/root has a the label and subvalue overlap because line height is too big for sshDivTblAVisible
lineHeight = 25;
}
textContainer
.toggleClass('sshDivTblDivSel', !!dynamicDatum.extended)
.toggleClass('pos', dynamicDatum.value>=0)
.toggleClass('neg', dynamicDatum.value<0)
.css({width: width +dynamicData.params.widthForRHSColumn, maxWidth: maxWidth})
.animate({
top: dynamicDatum.y,
left: x,
height: height,
'line-height': lineHeight + 'px'
}, durationForTextProps)
.find('.sshDivTblA')
.css({width: ''})
.animate({
fontSize: dynamicDatum.fontSize + 'px'
}, durationForTextProps)
.end()
.find('.sshDivTblRHS')
.css('display', rhsValueTextVisible?'inline-block':'none')
.animate({
'line-height':height + 'px'
}, durationForTextProps)
.end()
.find('.sshDivTblSubVal')
.toggle(!!dynamicDatum.extended)
.animate({'line-height': dynamicDatum.fontSize + 'px'})
;
}
} else {
// in this case text should NOT be shown
if(textContainer.is(':visible')) {
textContainer.fadeOut(duration);
}
}
}
/**
* Helper function for applyDynamicData which sets the text for the node's name and % value.
* @param {String} selectedPeriod
* @param {Boolean} useAbsolute whether to use the % value, or $ per share value
* @param {Number} denominator the value to use for the denominator of % value calculations
*/
selfNode.updateValueText = function(selectedPeriod, useAbsolute, denominator) {
// TODO support for text on reversed children (e.g. debt)
var value = selfNode.value(selectedPeriod);
var formattedValue = format(value, denominator, useAbsolute, answerUnit, scaleFactorForDisplay, datum.identifier);
if (answerUnit != null &&
!answerUnit.match(/\$/) &&
!answerUnit.match(/\u20AC/) &&
!answerUnit.match(/\u00A4/) &&
!(answerUnit == 'GBP' || answerUnit.match(/GBP/)) &&
!(answerUnit == 'EUR' || answerUnit.match(/EUR/)) ) {
var unitRe = new RegExp(answerUnit);
formattedValue = formattedValue.replace(unitRe, '')
}
}
/**
* Returns the dollar value associated with this node.
*
* @param {String} selectedPeriod code for the currently selected period, or null if the model type does not have
* a selected period (e.g. DCF models)
* @return {Number} value of this node
*/
selfNode.value = function(selectedPeriod) {
var val = forecastModel.cs.getValue(SeriesUtil.getValueIdentifiers(datum)[selectedPeriod]) //datum.valueIdentifier[selectedPeriod]);
if(isNaN(val))
val = 0;
return val;
};
/**
*
*/
selfNode.positive = function(selectedPeriod) {
var value = selfNode.value(selectedPeriod);
var result;
if(value != 0) {
result = value > 0;
} else {
result = datum.generallyPositive;
}
return result;
};
/**
* Sets the state, value, visible, rhsValueTextVisible, extended, and textVisible fields on the dynamicData.
* Also recursively calls calculateStateAndVisibility on all children.
*
* @param {Object} params sankey parameters
* @param {Object} dynamicData map from node identifiers to dynamicDatum for each node
* @param {boolean} parentExpanded whether the parent node is expanded, i.e. whether it's children are visible.
* For instance, in the default sankey state where nothing's been selected, only the root is expanded. If a super-division
* is selected, then both the root and that super-division are expanded.
*/
selfNode.calculateStateAndVisibility = function(params, dynamicData, parentExpanded) {
var dynamicDatum = dynamicData[datum.identifier];
var selected = params.selected == datum.identifier;
var childSelected = !!(params.selected && $.grep(allChildren, function(child){return child.datum.identifier == params.selected}).length);
var expanded = parentExpanded && (parent == null || selected || childSelected);
var state;
if(parent == null)
state = NODE_STATE_ROOT;
else if(datum.reversed)
state = NODE_STATE_REVERSE;
else if(rightChildren.length) {
// super division
state = selected || childSelected ? NODE_STATE_SELECTED_SUPERDIVISION : NODE_STATE_NORMAL;
} else {
// division
if(selected)
state = NODE_STATE_SELECTED_DIVISION;
else if(parent.parent)
state = NODE_STATE_NORMAL_SUBDIVISION;
else
state = NODE_STATE_NORMAL;
}
dynamicDatum.state = state;
dynamicDatum.value = selfNode.value(params.selectedPeriod);
dynamicDatum.positive = selfNode.positive(params.selectedPeriod);
dynamicDatum.visible = parentExpanded;
dynamicDatum.textVisible = parentExpanded && isTreeVisibleEnd(dynamicDatum);
var inspectorVisible = (params.state == SANKEY_STATE_DIVISION_SELECTED || params.state == SANKEY_STATE_SUBDIVISION_SELECTED);
dynamicDatum.extended = (inspectorVisible && selected);
dynamicDatum.rhsValueTextVisible =
(params.state == SANKEY_STATE_NORMAL || params.state == SANKEY_STATE_SUPERDIVISION_SELECTED)
&& isTreeVisibleEnd(dynamicDatum);
$.each(allChildren, function(i, child) {
child.calculateStateAndVisibility(params, dynamicData, expanded);
});
};
/**
* Sets the tubeWidth and effectiveTubeWidth fields on the dynamicData.
* Also recursively calls calculateTubeWidths on all children.
*
* @param {Number} tubeWidth the tube width that the parent has allocated for this child
* @param {Object} params sankey parameters
* @param {Object} dynamicData map from node identifiers to dynamic datum for each node. state field must be set.
*/
selfNode.calculateTubeWidths = function(tubeWidth, params, dynamicData) {
var positiveValue = 0;
var negativeValue = 0;
var hasChildren = false;
var dynamicDatum = dynamicData[datum.identifier];
$.each(rightChildren, function(i, child) {
positiveValue += Math.abs(child.value(params.selectedPeriod));
hasChildren = true;
});
$.each(reversedChildren, function(i, child) {
negativeValue += Math.abs(child.value(params.selectedPeriod));
hasChildren = true;
});
if(hasChildren) {
dynamicDatum.tubeWidth = tubeWidth == 0 || positiveValue == 0 ? 0 : tubeWidth * (positiveValue - negativeValue) / positiveValue;
$.each(allChildren, function(i, child) {
child.calculateTubeWidths(tubeWidth == 0 || positiveValue == 0? 0 : tubeWidth * Math.abs(child.value(params.selectedPeriod)) / positiveValue, params, dynamicData);
});
} else {
dynamicDatum.tubeWidth = tubeWidth;
}
// if the node's name is visible, make sure we have an effective tube width wide enough to fit the text's line-height
dynamicDatum.effectiveTubeWidth = isTreeVisibleEnd(dynamicDatum)
? Math.max(dynamicDatum.tubeWidth, params.heightForText) + (dynamicDatum.state == NODE_STATE_SELECTED_DIVISION ? 20 : 0)
: dynamicDatum.tubeWidth;
};
/**
* Sets the fontSize field on dynamicData.
* Also recursively calls calculateFontSizes on all children.
*
* @param {Object} params sankey parameters
* @param {Object} dynamicData map from node identifiers to dynamic datum for each node.
*/
selfNode.calculateFontSizes = function(params, dynamicData) {
$.each(allChildren, function(i, child) {
child.calculateFontSizes(params, dynamicData);
});
var dynamicDatum = dynamicData[datum.identifier];
var fontSize;
// if we're given a fixed font size, use it
if(params.fixedFontSize) {
fontSize = params.fixedFontSize;
// otherwise, try to scale font sizes so that when the forecast inspector isn't open, we give nodes
// with larger tubeWidths larger names as well
} else if(dynamicDatum.state == NODE_STATE_SELECTED_DIVISION) {
fontSize = 16;
} else if(params.state == SANKEY_STATE_DIVISION_SELECTED || params.state == SANKEY_STATE_SUBDIVISION_SELECTED) {
fontSize = 18;
} else {
var ratio = dynamicDatum.tubeWidth / params.rootTubeWidth;
if(ratio > 0.4)
fontSize = 28;
else if(ratio > 0.25)
fontSize = 24;
else
fontSize = 22;
}
dynamicDatum.fontSize = fontSize;
};
/**
* Measures the width of the largest division text in this node or any of its children. Following fields
* on dynamicData must be set: state, visible, text, fontSize.
*
* @param {Object} dynamicData map from node identifiers to dynamic datum for each node
* @param {Function} textMeasurer
* @return {Number}
*/
selfNode.measureMaxTextWidth = function(dynamicData, textMeasurer) {
var dynamicDatum = dynamicData[datum.identifier];
var maxWidth;
if(dynamicDatum.state == NODE_STATE_ROOT
|| dynamicDatum.state == NODE_STATE_REVERSE
|| !dynamicDatum.visible) {
maxWidth = 0;
} else {
maxWidth = textMeasurer(datum.name, dynamicDatum.fontSize);
}
$.each(allChildren, function(i, child) {
maxWidth = Math.max(child.measureMaxTextWidth(dynamicData, textMeasurer), maxWidth);
});
return maxWidth;
};
/**
* Recursively sets the column field on dynamicData for this node and all its children.
* Following fields on dynamicData must be set: state
*
* @param {Object} map from node state to Column
* @param {Object} dynamicData map from node identifiers to dynamic datum for each node
*/
selfNode.assignXPositions = function(columns, dynamicData) {
var dynamicDatum = dynamicData[datum.identifier];
dynamicDatum.column = columns[dynamicDatum.state];
$.each(allChildren, function(i, child) {
child.assignXPositions(columns, dynamicData);
});
};
/**
* Recurively sets the y and connectorY fields on dynamicData for this node all its children.
* Following fields on dynamic must be set: tubeWidth, effectiveTubeWidth
*
* @param {Number} armSpacing the vertical space to put between each sankey arm
* @param {Object} currentY object with a "y" field that indicates the current y position as we scan from top to bottom setting sankey arms' positions
* @param {Object} params sankey parameters
* @param {Object} dynamicData map from node identifiers to dynamic datum for each node
*/
selfNode.assignYPositions = function(armSpacing, currentY, params, dynamicData) {
var dynamicDatum = dynamicData[datum.identifier];
var effectiveTubeWidth = params.fused ? dynamicDatum.tubeWidth : dynamicDatum.effectiveTubeWidth; // in fused state, ignore any text so that arms move right up against each other
var y;
if(dynamicDatum.state == NODE_STATE_REVERSE) {
var parentResult = dynamicData[parent.datum.identifier];
dynamicDatum.y = parentResult.y + parentResult.tubeWidth / 2 + dynamicDatum.tubeWidth / 2;
} else if(isTreeVisibleEnd(dynamicDatum)) {
dynamicDatum.y = currentY.y + (effectiveTubeWidth / 2);
currentY.y += effectiveTubeWidth + armSpacing;
} else {
var oldCurrentY = currentY.y;
var sortedRightChildren = $.merge([], rightChildren);
sortedRightChildren.sort(createNodeSorter(params.selectedPeriod));
$.each(sortedRightChildren, function(i, child) {
child.assignYPositions(armSpacing, currentY, params, dynamicData);
});
if(dynamicDatum.state == NODE_STATE_ROOT) {
dynamicDatum.y = params.rootVerticalPosition;
} else {
// put this node vertically centered between its children
dynamicDatum.y = oldCurrentY + (currentY.y - armSpacing - oldCurrentY) / 2 - (effectiveTubeWidth / 2);
}
var connectorY = dynamicDatum.y - (dynamicDatum.tubeWidth / 2);
$.each(sortedRightChildren, function(i, child) {
var childResult = dynamicData[child.datum.identifier];
childResult.connectorY = connectorY + (childResult.tubeWidth/ 2);
connectorY += childResult.tubeWidth;
});
$.each(reversedChildren, function(i, child) {
child.assignYPositions(armSpacing, currentY, params, dynamicData);
});
}
};
/**
* counts the number of spaces between arms of this sankey node and any of its expanded children
*
* @param {Object} params sankey parameters
* @param {Object} dynamicData map from node identifiers to dynamic datum for each node
* @return {Object} an object with fields:
* - numSpaces: number of spaces
* - nonSpacingHeight: the height of all arms of this node's children
*/
selfNode.countSpaces = function(params, dynamicData) {
var spaces = {
nonSpacingHeight: 0,
numSpaces: 0
};
var dynamicDatum = dynamicData[datum.identifier];
if(!isTreeVisibleEnd(dynamicDatum)
&& rightChildren.length) {
$.each(rightChildren, function(i, child) {
var childSpaces = child.countSpaces(params, dynamicData);
spaces.nonSpacingHeight += childSpaces.nonSpacingHeight;
spaces.numSpaces += childSpaces.numSpaces;
});
spaces.numSpaces += rightChildren.length - 1;
} else {
spaces.nonSpacingHeight += (params.fused ? dynamicDatum.tubeWidth : dynamicDatum.effectiveTubeWidth);
}
return spaces;
};
/**
* Returns all the positive (or negative) children on the right side of this NODE.
*
* @param {boolean} positive if true, returns positive children. If false, returns negative children
*/
selfNode.getPositiveOrNegativeRightChildren = function(positive, selectedPeriod) {
positive = !!positive;
return $.grep(rightChildren, function(child) {
return child.positive(selectedPeriod) == positive;
});
}
/**
* tells whether this node is the leaf node in the currently visible tree.
* The "state" field of dynamicDatum must be set.
* @param {Object} dynamicDatum
* @return {boolean}
*/
function isTreeVisibleEnd(dynamicDatum) {
return dynamicDatum.state != NODE_STATE_ROOT && dynamicDatum.state != NODE_STATE_SELECTED_SUPERDIVISION;
}
$.extend(selfNode, {
connector: connector,
rightChildren: rightChildren,
reversedChildren: reversedChildren,
allChildren: allChildren,
datum: datum,
parent: parent
});
}
function createNodeSorter(selectedPeriod) {
var defaultNodeSorter = function(a, b) {
var cashA = a.datum.cash, cashB = b.datum.cash;
if(cashA && !cashB)
return 1;
else if(!cashA && cashB)
return -1;
else {
var bottomA = a.datum.bottom, bottomB = b.datum.bottom;
if(bottomA && !bottomB)
return 1;
else if(!bottomA && bottomB)
return -1;
else {
var positiveA = a.positive(selectedPeriod), positiveB = b.positive(selectedPeriod);
if(positiveA && !positiveB)
return -1;
else if(!positiveA && positiveB)
return 1;
else {
var valA = Math.abs(a.value(selectedPeriod)), valB = Math.abs(b.value(selectedPeriod));
if(valA > valB)
return -1;
else if(valA < valB)
return 1;
else
return 0;
}
}
}
};
// TREF-5920: if the ORDER_SANKEY_BY_ROW tag is present, we order the
if(SANKEY_INITIAL_LOAD_DATA.modelData.orderSankeyByRow) {
return function nodeSorter(a, b) {
var rowA = a.datum.row, rowB = b.datum.row;
var isARealRow = !isNaN(rowA) && rowA >= 0;
var isBRealRow = !isNaN(rowB) && rowB >= 0;
// Note that virtual rows will have negative row numbers,
// and sankey arms that were created in the rearrangement interface (ie not from the original Excel) won't have
// row numbers at all. We put them at the bottom, below all rows from the Excel.
if(isARealRow && !isBRealRow) {
return -1;
} else if(!isARealRow && isBRealRow) {
return 1;
} else if(!isARealRow && !isBRealRow) {
return defaultNodeSorter(a, b);
} else {
if(rowA > rowB)
return 1;
else if(rowA < rowB)
return -1;
else
return 0;
}
};
} else {
return defaultNodeSorter;
}
}
// =============================================================
// =========================== COLUMNS ========================
// =============================================================
/**
* Represents a vertical band or column in the sankey rendering.
* Columns are currently in a 1-1 relationship with node states.
*
* Column objects are created and managed by the Columns object.
*
* Columns are assumed to abut their left neighbor, but not necessarily
* abut their right neighbor. Columns can overlap. And multiple columns
* can share the same left neighbor. E.g., the "super division" column and
* "sub division" column might together occupy the same space as the "top level
* division" column.
*
* As such, Column objects form a tree structure with the column for the root node
* as the root of the tree, and the leftNeighbor field representing each Column's parent.
*
* A Column's left edge is simply given by the right edge of its leftNeighbor. A Column's
* width is an independent variable. And a column's right edge is a variable derived by
* adding its leftNeighbor's right edge with its width.
* @constructor
*/
function Column() {
this.width = 0;
}
var colProto = Column.prototype;
colProto.getLeftEdge = function() {
return this.leftNeighbor ? this.leftNeighbor.getRightEdge() : 0;
};
colProto.getRightEdge = function() {
return this.getLeftEdge() + this.width;
};
colProto.setRightEdge = function(rightEdge) {
this.width = rightEdge - this.getLeftEdge();
};
/**
* creates the set of columns. Used by calculateDynamicData.
* @param {Node} rootNode
* @param {Object} params sankey parameters
* @param {Object} dynamicData map from node identifier to the dynamicDatum for each node
* @param {Function} textMeasurer
* @return {Object} map from node state to Column
*/
function getColumns(rootNode, params, dynamicData, textMeasurer) {
var columns = {};
columns[NODE_STATE_ROOT] = new Column();
columns[NODE_STATE_REVERSE] = new Column();
var availableWidthForSankey = calculateSankeyWidth(rootNode, params, dynamicData, textMeasurer);
createColumns(columns, params.state);
sizeColumns(columns, params.state, availableWidthForSankey);
// 15px of horizontal shaft on the root before the arrow head begins appears about right
// for very small images (i.e. thumbnails), cut it down to 6
columns[NODE_STATE_REVERSE].width = columns[NODE_STATE_ROOT].width = getRootArrowWidth(params.rootTubeWidth) + (availableWidthForSankey < 100 ? 6 : 15);
return columns;
}
function getRootArrowWidth(tubeWidth) {
return Math.min(15, 0.2 * tubeWidth);
}
/**
* Helper function for generateColumns. Decides how much of the total width we allocate to the sankey arms, and how much to the division text.
* @param {Node} rootNode
* @param {Object} params sankey parameters
* @param {Object} dynamicData map from node identifier to the dynamicDatum for each node
* @param {Function} textMeasurer
* @return {Number} amount of width to allocate for the sankey arms
*/
function calculateSankeyWidth(rootNode, params, dynamicData, textMeasurer) {
var maxTextWidth = rootNode.measureMaxTextWidth(dynamicData, textMeasurer);
// use some heuristics to estimate what the min/max width of the sankey should be in order to look reasonable
var minSankeyWidth = 2 * params.rootTubeWidth // larger root tube width means we need more space to make arms curve
+ (10 * Math.max(0, rootNode.rightChildren.length - 4)); // when you get significantly more than 4 children, some of the arms have
// to curve a significant distance vertically, and they'll require more horizontal space to curve
var maxSankeyWidth = params.getWidth() * 0.4; // it looks weird if the sankey is ~50% or more of the total width, so pick a max of 40%
// if you assume we're using minSankeyWidth for the sankey arms, this is the total width of the sankey + text
var totalWidthAssumingMinSankey = minSankeyWidth + maxTextWidth + params.widthForRHSColumn;
// if totalWidthAssumingMinSankey is less than the total available width, we'll have some excess width that
// we can distribute
var excessWidth = Math.max(params.getWidth() - totalWidthAssumingMinSankey, 0);
// by adding half the excessWidth back onto the minSankeyWidth, we're basically taking the excessWidth and allocating
// 50% of it to the sankey, and 50% of it to the text. This has been a pretty good heuristic to make the sankey arms
// and text look balanced
return availableWidthForSankey = Math.min(minSankeyWidth + excessWidth / 2, maxSankeyWidth);
}
function createColumns(columns, sankeyState) {
switch(sankeyState) {
case SANKEY_STATE_NORMAL: //this is usually the first visible state of sankey on page
appendToRightOf(columns, NODE_STATE_ROOT, NODE_STATE_NORMAL); //in normal state only NORMAL [aka UNSELECTED DIVISIONs or SUPERDIVISIONs] are visible,
break;
case SANKEY_STATE_DIVISION_SELECTED: //only possible on a 2 level tree, where only ROOT and DIVISIONs are present
appendToRightOf(columns, NODE_STATE_ROOT, NODE_STATE_NORMAL); // UNSELECTED DIVISIONS are visible
appendToRightOf(columns, NODE_STATE_ROOT, NODE_STATE_SELECTED_DIVISION); // and 1 SELECTED DIVISION
break;
case SANKEY_STATE_SUPERDIVISION_SELECTED: //only possible on a 3 level tree, where only ROOT , SUPERDIVISIONs and SUBDIVISIONs are present
appendToRightOf(columns, NODE_STATE_ROOT, NODE_STATE_NORMAL); // UNSELECTED SUPERDIVISIONS are visible
appendToRightOf(columns, NODE_STATE_ROOT, NODE_STATE_SELECTED_SUPERDIVISION); // as well 1 SELECTED SUPERDIVISION
appendToRightOf(columns, NODE_STATE_SELECTED_SUPERDIVISION, NODE_STATE_NORMAL_SUBDIVISION); //and the UNSELECTED children of the SUPERDIVISION, SUBDIVISIONS
break;
case SANKEY_STATE_SUBDIVISION_SELECTED: //only possible on a 3 level tree, where only ROOT , SUPERDIVISIONs and SUBDIVISIONs are present
appendToRightOf(columns, NODE_STATE_ROOT, NODE_STATE_NORMAL);
appendToRightOf(columns, NODE_STATE_ROOT, NODE_STATE_SELECTED_SUPERDIVISION);
appendToRightOf(columns, NODE_STATE_SELECTED_SUPERDIVISION, NODE_STATE_NORMAL_SUBDIVISION);
appendToRightOf(columns, NODE_STATE_SELECTED_SUPERDIVISION, NODE_STATE_SELECTED_DIVISION);
break;
}
}
function appendToRightOf(columns, left, right) {
var leftCol = columns[left];
var rightCol = new Column();
if(leftCol)
rightCol.leftNeighbor = leftCol;
columns[right] = rightCol;
}
function sizeColumns(columns, sankeyState, availableWidthForSankey) {
switch(sankeyState) {
case SANKEY_STATE_NORMAL://inspector box NOT visible
columns[NODE_STATE_NORMAL].setRightEdge(availableWidthForSankey); //in normal mode, the division and subdivision stretch for as much room as available
break;
case SANKEY_STATE_DIVISION_SELECTED: //inspector box IS visible, top-level nodes get pushed down to 50%
columns[NODE_STATE_NORMAL].setRightEdge(0.5 * availableWidthForSankey);
columns[NODE_STATE_SELECTED_DIVISION].setRightEdge(0.5 * availableWidthForSankey);
break;
case SANKEY_STATE_SUPERDIVISION_SELECTED: //inspector box NOT visible
columns[NODE_STATE_NORMAL].setRightEdge(0.7 * availableWidthForSankey); //unselected superdivisions
columns[NODE_STATE_SELECTED_SUPERDIVISION].setRightEdge(0.4 * availableWidthForSankey); //selected superdivisions
columns[NODE_STATE_NORMAL_SUBDIVISION].setRightEdge(availableWidthForSankey);// unselected subdivisions, take up remainder of available space
break;
case SANKEY_STATE_SUBDIVISION_SELECTED: //inspector box IS visible
columns[NODE_STATE_NORMAL].setRightEdge(0.5 * availableWidthForSankey); //unselected superdivisions
columns[NODE_STATE_SELECTED_SUPERDIVISION].setRightEdge(0.2 * availableWidthForSankey); //selected superdivisions
columns[NODE_STATE_NORMAL_SUBDIVISION].setRightEdge(0.7 * availableWidthForSankey);// unselected selected subdivision get shrunk down
columns[NODE_STATE_SELECTED_DIVISION].setRightEdge(0.7 * availableWidthForSankey); //selected subdivision get shrunk down
break;
}
}
// =============================================================
// =========================== HELPER FUNCTIONS ========================
// =============================================================
/**
* Formats a value suitable for displaying in the RHS value column of the sankey
* @param {Number} value value to display
* @param {Number} denominator denominator to use for percentage calculations,
* only applies if useAbsolute = false
* @param {boolean} useAbsolute whether to use absolute or percentage values
* @param {String} answerUnit unit (generally a currency) in which absolute values should be shown
*/
function format(value, denominator, useAbsolute, answerUnit, scaleFactorForDisplay, identifier) {
return useAbsolute
? UnitUtil.getDisplayString(value, answerUnit, false, scaleFactorForDisplay, identifier, true)
: (100 * value / denominator).toFixed(1) + '%'; // rounds to 1 decimal point, e.g. 71.2%
}
/**
* This will pass in the data needed to create a ChartPopup for the division.
*/
function chartPopup(event) {
event.preventDefault();
$("div.chartPopup").modal("hide").remove();
var datum = event.data.datum;
if(window.oldCharts){
new ChartPopup({
dialogOptions: {title: datum.name},
modelManager: window.demoWidget.modelManager,
companyData: event.data.companyData,
periodToId: datum.valueIdentifier,
unit: event.data.unit,
collectionIdentifier: datum.identifier
});
}else{
// TREF-3156 event logging
logModelAccessEvent(tf.modelId, "VIEW_OUTPUT_CHART", {"divisionId": datum.identifier});
new ModelChartPopup({
dialogOptions: {title: datum.name},
modelManager: window.demoWidget.modelManager,
plots : [datum.identifier],
companyData: event.data.companyData,
periodToId: SeriesUtil.getValueIdentifiers(datum),
unit: event.data.unit,
collectionIdentifier: datum.identifier
});
}
return false;
}
// initialize the sankey colorings
var checkbox = $("#showChangesSinceLastUpload");
if (checkbox.length > 0) {
hideUnhideChangesSinceLastUpload(checkbox.prop("checked"));
}
// toggles the class 'hideReviewedRow' of all of the rows
$('#showReviewedRows').click(function() {
$('.changes-since-last-upload-table .row').toggleClass('hideReviewedRow');
});
// simulate clicks on the
$('.changes-since-last-upload-table .row .reviewedCheckbox[checked]').each(function(){
updateFrontEndWithCheckboxState($(this));
});
// toggles the class 'reviewedRow' on the row of the checkbox clicked and the classes 'directChange' and 'directChangeBox' of the corresponding items on the Sankey
$('.changes-since-last-upload-table .row .reviewedCheckbox').click(function() {
var checkbox = $(this);
$.ajax({
type: "POST",
url: window.tf.urls.setReviewedEndpoint + '&number=' +checkbox.attr('number') + '&reviewed=' + checkbox.is(':checked'),
success: function (data) {
if (data.success === 'true') {
updateFrontEndWithCheckboxState(checkbox);
} else {
alert(data.message);
//revert checkbox state on failure
checkbox.prop('checked', !checkbox.is(':checked'));
}
},
error: function (data) {
alert("Your change could not be saved. Please try again.");
//revert checkbox state on failure
checkbox.prop('checked', !checkbox.is(':checked'));
}
});
});
function updateFrontEndWithCheckboxState(checkbox) {
var row = checkbox.closest('.row');
row.toggleClass('reviewedRow');
var id = checkbox.attr('identifier');
var variables = $('.variables', row).text().split(',');
var changeType = $('.changeType', row).text().toUpperCase();
// modify tf.previousSankeyDiff to reflect the state of the checkbox
variables.forEach(function(variable){
var variable = variable.trim();
if(variable === 'Component') {
variable = 'Division';
};
if(variable === 'Output') {
variable = 'Answer';
};
var id1 = tf.previousSankeyDiff['changeDirectness'][variable.trim()][id];
var directChangeTypes;
if(id1){
directChangeTypes = id1.direct;
}
if(directChangeTypes) {
directChangeTypes.forEach(function(changeType1) {
// remove it
directChangeTypes.splice(_.indexOf(directChangeTypes, changeType1), 1);
});
directChangeTypes.forEach(function(changeType1) {
if(!checkbox.is(':checked')) {
// add it
directChangeTypes.push(changeType1);
};
});
};
});
// sankey arm
$('div.sshDivTblLHS.sshDivTblDiv[data-id=' + id + ']>a','.mainCont').toggleClass('directChange', !checkbox.is(':checked'));
// driver thumbnail
$('div.driver[data-id=' + id + ']','.mainCont').toggleClass('directChange', !checkbox.is(':checked'));
// driver on the chart
$('div.cw_tab_title[data-id=' + id + ']>div','.mainCont').toggleClass('directChangeBoxed', !checkbox.is(':checked'));
// category
$('div.category[data-id=' + id + ']>h4','.mainCont').toggleClass('directChangeBoxed', !checkbox.is(':checked'));
// stream on the inspector (both in the chart and thumbnail mode)
$('div.section-bar[data-id=' + id + ']>h3','.mainCont').toggleClass('directChangeBoxed', !checkbox.is(':checked'));
// answer
$('div.innercwFVHover[data-id=' + id + ']').toggleClass('directChangeBoxed', !checkbox.is(':checked'));
};
})();
/**
* Event handler for when the user checks/unchecks the "Show Changes Since Last Upload" checkbox for the sankey diff.
* @param {Element} checkbox the checkbox element
*/
function setChangesSinceLastUpload(checkbox) {
var wrappedCheckbox = $(checkbox);
var showIt = wrappedCheckbox.prop("checked");
$.ajax({
type: "POST",
url: window.tf.urls.setShowWhatsChangedEndpoint + "&show=" + showIt,
success: function (data) {
if (data.success === 'true') {
hideUnhideChangesSinceLastUpload(wrappedCheckbox.prop("checked"));
} else {
alert(data.message);
//revert checkbox state on failure
wrappedCheckbox.prop('checked', !showIt);
}
},
error: function (data) {
alert("Your change could not be saved. Please try again.");
//revert checkbox state on failure
wrappedCheckbox.prop('checked', !showIt);
}
});
}
/**
* Hide or show the "Changes Since Last Upload" table and sankey color highlighting
* @param {boolean} show true to show, false to hide
*/
function hideUnhideChangesSinceLastUpload(show) {
if (show) {
$('.mainCont').addClass('sankeyDiffVisible');
$('#structuralDiffChanges').slideDown()
} else {
$('.mainCont').removeClass('sankeyDiffVisible');
$('#structuralDiffChanges').slideUp()
}
}
/**
* Open the correct division and optional driver in the sankey, and scroll the sankey into view
* @param {string} divisionAndDriverString the division and optional driver, in a JSON parseable string
*/
function openSankeyFromDiffLink(divisionAndDriverString) {
window.demoWidget.setState(JSON.parse(divisionAndDriverString));
$('html, body').animate({
scrollTop: $(".mainContOrRequestScenario").offset().top
}, 1500);
}
;;
// @include lib/jquery.ui.min.js
// @include lib/underscore.js
// @include infrastructure/driverUtil.js
// @include chart/sankey.js
/*
* This file creates a toggle chart
*/
$(function() {
var chartIdx = 0
if ($.widget) {
$.widget('custom.sankeyChart', {
_create: function() {
this.series = []
this.chartIdx = ++chartIdx
},
sizeContainer: function() {
this.rerender()
},
addSeries: function(seriesToAdd) {
this.series.push(seriesToAdd)
},
updateSeries: function(seriesId, data, options, resetOptions) {
this.series = this.series.map(function(series) {
if (series.id === seriesId) {
if (data)
series.data = data
if (options && resetOptions) {
series.options = options
} //replace previous options
else if (options) {
series.options = $.extend(true, {}, series.options, options) //update existing options with new options
}
}
return series
})
},
removeSeries: function(seriesIds) {
var removeSeries = SeriesUtil.removeSeries(seriesIds)
this.series = SeriesUtil.is2dArray(this.series) ?
this.series.map(removeSeries).filter(function (e) { return !_.isEmpty(e) }) :
removeSeries(this.series)
},
getSeries: function() {
return this.series
},
setRedraw: function(performRedraw) {
if (performRedraw)
this.rerender()
},
reflow: function() {
this.rerender()
},
rerender: function() {
var $toggleChart = this.render()
if ($toggleChart) {
this.element.find('.js-sankey-chart').remove()
this.element.append($toggleChart)
}
},
render: function() {
var driver = this.element.parent().modelChart('getDriver')
var $titleContainer = this.element.find('.titleContainer')
var $chart = $('
', { 'class': 'js-sankey-chart' })
.css('height', this.element.height() - $titleContainer.height())
.css('width', this.element.width())
var sankey = new _SankeyDiagram(
$chart,
{
inspectorLeftEdge: 0,
editableDivisionNames: false,
renderPartialSums: false
},
demoWidget.modelManager.get('active'),
this.options.tf.periodSelectionManager || (window.demoWidget || {}).periodSelectionManager,
demoWidget.companyData.il,
this.series[0][0].data, // just pass in the first series since it's a componentBreakdown
{ width: this.element.width(), height: this.element.height() }
)
return $chart
},
getEditableSeries: function() {
return this.series.filter(function(series) {
return series.options &&
series.options.tf &&
series.options.tf.series &&
series.options.tf.series.editable
})
},
getValuesMap: function(value) {
var editableSeries = this.getEditableSeries()
var valuesMap = {}
if (editableSeries.length !== 1) {
console.error('There should be exactly one editable series for a toggle chart')
}
else {
var chartData = editableSeries[0].data.chartData[0].array[0]
valuesMap[chartData.Identifier] = value
}
return valuesMap
}
})
}
});
;;
// @include lib/jquery.ui.min.js
// @include infrastructure/seriesUtil.js
// @include chart/trefisChart.js
// @include chart/toggleChart.js
// @include chart/sankeyChart.js
/*
* This widget delegates control to the appropriate chart type
*/
$(function() {
if ($.widget) {
$.widget('custom.chartCtrl', {
_create: function() {
this.element.chart(this.options)
this.element.toggleChart({})
this.element.sankeyChart(this.options)
this.element.find('.js-toggle-chart').hide()
},
// Add modelManager for charts that need it
addModelManager: function(modelManager) {
this.element.toggleChart('addModelManager', modelManager)
},
updateSeries: function(seriesId, data, options, resetOptions, dontUpdateAxis) {
this.element.chart('updateSeries', seriesId, data, options, resetOptions, dontUpdateAxis)
this.element.toggleChart('updateSeries', seriesId, data, options, resetOptions)
if (SeriesUtil.isToggleChart(this.element.toggleChart('getEditableSeries')))
this.element.toggleChart('rerender')
},
updateChartTitle: function(newTitle) {
this.element.chart('updateChartTitle', newTitle)
},
updateXAxisDisplay: function(displayOptions){
this.element.chart('updateXAxisDisplay',displayOptions);
},
updateYAxisDisplay: function(displayOptions){
this.element.chart('updateYAxisDisplay',displayOptions);
},
updateYAxisRange: function(rangeOptions){
this.element.chart('updateYAxisRange',rangeOptions);
},
updateDecimalPrecision: function(decimalPrecision){
this.element.chart('updateDecimalPrecision',decimalPrecision)
},
setShowDataLabels: function(showDataLabels) {
this.element.chart('setShowDataLabels', showDataLabels)
},
addSeries: function(seriesToAdd) {
var chartType = this.getChartType(seriesToAdd)
switch (chartType) {
case 'sankey':
this.element.sankeyChart('addSeries', seriesToAdd)
this.element.sankeyChart('reflow')
break;
case 'toggle':
this.element.toggleChart('addSeries', seriesToAdd)
this.element.toggleChart('reflow')
break;
default:
this.element.chart('addSeries', seriesToAdd)
}
this.toggleChartType(chartType)
},
setRedraw: function(redraw, performRedraw) {
this.element.chart('setRedraw', redraw, performRedraw)
this.element.toggleChart('setRedraw', performRedraw)
this.toggleChartType(this.getChartType())
},
setChartTooltipPosition: function(position) {
this.element.chart('setChartTooltipPosition', position)
},
isBeingDragged: function(seriesId) {
this.element.chart('isBeingDragged', seriesId)
},
removeSeries: function(seriesIds) {
this.element.chart('removeSeries', seriesIds)
this.element.toggleChart('removeSeries', seriesIds)
this.element.sankeyChart('removeSeries', seriesIds)
},
rerender: function() {
this.element.chart('rerender')
this.element.toggleChart('rerender')
this.toggleChartType(this.getChartType())
},
sizeContainer: function() {
if (this.getChartType() === 'toggle')
this.element.toggleChart('sizeContainer')
else if (this.getChartType() === 'sankey')
this.element.sankeyChart('sizeContainer')
else
this.element.chart('sizeContainer')
},
reflow: function() {
this.element.chart('reflow')
this.element.toggleChart('reflow')
this.toggleChartType(this.getChartType())
},
mergeAreaSeriesData: function(data) {
return this.element.chart('mergeAreaSeriesData', data)
},
getChartType: function(series) {
if (SeriesUtil.isToggleChart(series || this.element.toggleChart('getSeries')))
return 'toggle'
else if (SeriesUtil.isSankeyChart(series || this.element.sankeyChart('getSeries')))
return 'sankey'
else
return null
},
// Toggles the visibilty for the given chart type
toggleChartType: function(chartType) {
this.element.find('.chart:not(.titleContainer), .js-toggle-chart, .js-sankey-chart').hide()
switch (chartType) {
case 'toggle':
this.element.find('.js-toggle-chart').show()
break;
case 'sankey':
this.element.find('.js-sankey-chart').show()
break;
default:
this.element.find('.chart').show()
}
},
_destroy: function() {
}
});
}
});
;;
// lib/jquery.min.js
// @include lib/jquery.ui.min.js
// @include chart/trefisChart.js
// @include infrastructure/period.js
// @include properties.js
/***
In summer 2017 we removed the periods from the main chartMenu.js
This menu may grow differently that the chartMenu, despite having very similar functionality
*/
;$(function() {
if($.widget) {
$.widget( 'custom.chartPeriodMenu', {
//widget defaults
options:{
chart: null, //the parent model chart object
isCondensed: false
},
_create: function(){//widget 'constructor'
this.attachHandlers();
this.update();
// idea here is that at a certain size, or some width's we need to condense this menu.
if (this.options.isCondensed){
// handle drop up menu case...
}
},
_destroy:function(){
},
/* Overrides bootstrap's dropdown toggle to work as a hover */
/**
* attach click handlers
**/
attachHandlers : function(){
var chart = this.options.chart;
var _this = this;
this.element.on("click", ".period", function(event){
if(!$(this).hasClass("active")){
if (!_this.options.editMode){
chart.setActivePeriodType($(this).data("period"));
} else {
chart.updateStoreComponent('activePeriod',$(this).data("period"))
}
_this.update();
}
event.preventDefault();
})
},
/**
* update ui state
*/
update: function(){
this.updateDeltas();
this.updatePeriodTypes();
},
/**
* gets the period types for all the modified drivers in the active chart
*/
allModifiedPeriodTypes: function() {
return this.options.chart.options.plots.map(function(plot) {
return !plot.code || !this.options.chart.options.modelManager? {} ://not all charts are guaranteed to have a model manager
this.options.chart.options.modelManager.get('active').modifiedOrAffectedPeriodTypes(plot.code ? plot.code : plot);
}, this).reduce(function(acc, periodTypes) {
return $.extend(acc, periodTypes);
}, {});
},
delta: 'Δ',
deltaIcon: function() {
return $(''+ this.delta +'');
},
clearDeltas: function() {
$(this.element).find('.period i.custicon').remove();
},
updateDeltas: function() {
this.clearDeltas();
var modifiedPeriodTypes = this.allModifiedPeriodTypes();
var numDeltas = Object.keys(modifiedPeriodTypes).length;
if (!$.isEmptyObject(modifiedPeriodTypes))
for (periodType in modifiedPeriodTypes)
$(this.element).find('.period-'+ periodType +' a').prepend(this.deltaIcon());
$(this.element).find('.menuHeading ~ .custicon').html(numDeltas > 0 ? numDeltas + this.delta : '');
},
/**
* updates the ui state of the period-type entries, anual, quarterly, etc...
* hides unavailable plot types, marks the currently active type
*/
updatePeriodTypes : function(){
var chart = this.options.chart;
var periods = chart.getPeriods()||[]
var activeClass = 'active',
chartMenuOption = 'chart-period-menu-option'
// if only one period, just make the menu hidden, but not display none
// so that it remains the same size as charts next to it
if (periods.length === 1){
this.element.css('visibility','hidden');
} else {
this.element.css('visibility','visible');
}
this.element.find('.period').removeClass(activeClass+' '+chartMenuOption); //hide all period entries
for(var i=0; i 1) {
periodCountSuffix = ' ' + periods.length + 'P';
}
var isWaterfall = chart.getSeriesType() == 'waterfall';
var activePeriodType = chart.getActivePeriodType();
if(!isWaterfall){
this.element.find('.period-'+activePeriodType).addClass(activeClass) //mark the active period type with active class
this.element.find('.menuHeading').html(tf.period.typeShortNames[activePeriodType] + periodCountSuffix);
// for non waterfalls, we need the dividers.
this.element.find('.type-divider').show();
if (this.allModifiedPeriodTypes()[activePeriodType])
this.element.find('.menuHeading').addClass('active-period');
else
this.element.find('.menuHeading').removeClass('active-period');
}
// removing stuff that was here. was causing errors, and we only have single periods in waterfall
// TODO: what needs to be here if we wnat to show multiple periods in waterfalls.
this.element.find('.period-menu').not('.hide').find('.'+chartMenuOption).first().addClass('first')
},
/**
* dynamically add a new menu entry that doesnt exist in the chart template at build time
*
* @param label - html or text for the menu item
* @param callback - function to fire when item is selected, the callback will be passed in a single parameter, which is the element that was clicked aka $(this)
*
*/
addMenuEntry: function(label, callback){
var entry = $("