code stringlengths 1 2.08M | language stringclasses 1 value |
|---|---|
$(function() {
$("#tabs-mark > ul").myTab({
tabClassActive : 'ui-tabs-selected',
tabClassContainer : 'tab_container',
tabClassPanel : 'ui-tabs-panel',
});
$('#slider-content').rhinoslider({
controlsPlayPause: false,
autoPlay: true,
showBullets: 'always',
changeBullets: 'before',
showControls: 'always',
showTime: 4000,
effect: 'fade',
effectTime: 500
});
$('.image_in_home').cycle({
fx: 'turnDown',
delay: -4000,
timeout: 500
});
$("#FmrContact").validationEngine();
$("#formTemoin").validationEngine();
// --- bloc right qui glisse
var $sidebar = $(".rightFixed"),
$window = $(window),
offset = $sidebar.offset(),
topPadding = 15;
if (typeof offset !== "undefined") {
$window.scroll(function() {
if ($window.scrollTop() > offset.top) {
$sidebar.stop().animate({
marginTop: $window.scrollTop() - offset.top + topPadding
});
} else {
$sidebar.stop().animate({
marginTop: 0
});
}
});
}
}); | JavaScript |
/**
* YouTube JavaScript Functions
*/
function onYouTubePlayerReady(playerId) {
ytplayer = document.getElementById("jfxytplayer");
ytplayer.addEventListener("onStateChange", "onPlayerStateChange");
ytplayer.addEventListener("onError", "onPlayerError");
}
function onPlayerStageChange(newState) {
//alert("onPlayerStageChange: " + newState);
}
function onPlayerError(errorCode) {
//alert("onPlayerError: " + errorCode);
}
// functions for the api calls
function loadNewVideo(id, startSeconds) {
if (ytplayer) {
ytplayer.loadVideoById(id, parseInt(startSeconds));
}
}
function cueNewVideo(id, startSeconds) {
if (ytplayer) {
ytplayer.cueVideoById(id, startSeconds);
}
}
function play() {
if (ytplayer) {
ytplayer.playVideo();
}
}
function pause() {
if (ytplayer) {
ytplayer.pauseVideo();
}
}
function stop() {
if (ytplayer) {
ytplayer.stopVideo();
}
}
function getPlayerState() {
if (ytplayer) {
return ytplayer.getPlayerState();
}
}
function seekTo(seconds) {
if (ytplayer) {
ytplayer.seekTo(seconds, true);
}
}
function getBytesLoaded() {
if (ytplayer) {
return ytplayer.getVideoBytesLoaded();
}
}
function getBytesTotal() {
if (ytplayer) {
return ytplayer.getVideoBytesTotal();
}
}
function getCurrentTime() {
if (ytplayer) {
return ytplayer.getCurrentTime();
}
}
function getDuration() {
if (ytplayer) {
return ytplayer.getDuration();
}
}
function getStartBytes() {
if (ytplayer) {
return ytplayer.getVideoStartBytes();
}
}
function mute() {
if (ytplayer) {
ytplayer.mute();
}
}
function unMute() {
if (ytplayer) {
ytplayer.unMute();
}
}
function getEmbedCode() {
alert(ytplayer.getVideoEmbedCode());
}
function getVideoUrl() {
alert(ytplayer.getVideoUrl());
}
function setVolume(newVolume) {
if (ytplayer) {
ytplayer.setVolume(newVolume);
}
}
function getVolume() {
if (ytplayer) {
return ytplayer.getVolume();
}
}
function clearVideo() {
if (ytplayer) {
ytplayer.clearVideo();
}
}
| JavaScript |
function showSaveAsImageApplet() {
document.getElementById("SaveAsImageApplet").innerHTML = "<IFRAME alt=SaveAsImage scrolling=no frameborder=0 src=http://javafxdemos.googlecode.com/hg/resource/SaveAsImage/SaveAsImage.html width=355 height=267 ></IFRAME>";
}
| JavaScript |
function showSaveAsImageApplet() {
document.getElementById("SaveAsImageApplet").innerHTML = "<IFRAME alt=SaveAsImage scrolling=no frameborder=0 src=http://javafxdemos.googlecode.com/hg/resource/SaveAsImage/1.3/SaveAsImage.html width=355 height=267 ></IFRAME>";
}
| JavaScript |
function showInterestingPhotosApplet() {
document.getElementById("InterestingPhotosApplet").innerHTML = "<IFRAME alt=ShoppingService scrolling=no frameborder=0 src=http://javafxdemos.googlecode.com/hg/resource/InterestingPhotos/InterestingPhotos.html height=330 width=250 ></IFRAME>";
}
| JavaScript |
function showYahooShoppingApplet() {
document.getElementById("YahooShoppingApplet").innerHTML = "<IFRAME alt=ShoppingService scrolling=no frameborder=0 src=http://javafxdemos.googlecode.com/hg/resource/YahooShopping/YahooShopping.html height=340 width=250 ></IFRAME>";
}
| JavaScript |
function showControlSkinApplet() {
document.getElementById("ControlSkinApplet").innerHTML = "<IFRAME alt=ControlSkin scrolling=no frameborder=0 src=http://javafxdemos.googlecode.com/hg/resource/ControlSkin/ControlSkin.html height=320 width=195 ></IFRAME>";
}
| JavaScript |
function showCustomRssTaskApplet() {
document.getElementById("CustomRssTaskApplet").innerHTML = "<IFRAME alt=CustomRssTask scrolling=no frameborder=0 src=http://javafxdemos.googlecode.com/hg/resource/CustomRssTask/CustomRssTask.html height=50 width=410 ></IFRAME>";
}
| JavaScript |
(function() {
var write_string = '<iframe src="http://widgets.dzone.com/links/widgets/zoneit.html?t=';
write_string += window.dzone_style ? window.dzone_style : '1';
write_string += '&url=http://blogs.sun.com/rakeshmenonp/entry/javafx_custom_feed_parsers';
if (window.dzone_title) write_string += '&title=' + encodeURIComponent(dzone_title);
else write_string += '&title=' + encodeURIComponent(document.title);
if (window.dzone_blurb) write_string += '&description=' + encodeURIComponent(dzone_blurb);
if (window.dzone_style == '2') write_string += '" height="25" width="155" scrolling="no" frameborder="0"></iframe>';
else write_string += '" height="70" width="50" scrolling="no" frameborder="0"></iframe>';
document.write(write_string);
})() | JavaScript |
function showFontTTFApplet() {
document.getElementById("FontTTFApplet").innerHTML = "<IFRAME alt=ShoppingService scrolling=no frameborder=0 src=http://javafxdemos.googlecode.com/hg/resource/FontTTF/FontTTF.html height=110 width=210 ></IFRAME>";
}
| JavaScript |
function showFileBrowserApplet() {
document.getElementById("FileBrowserApplet").innerHTML = "<IFRAME alt=FileBrowser scrolling=no frameborder=0 src=http://javafxdemos.googlecode.com/hg/resource/FileBrowser/FileBrowser.html width=330 height=330 ></IFRAME>";
}
| JavaScript |
function showPieRecruitApplet() {
document.getElementById("PieRecruitApplet").innerHTML = "<IFRAME alt=PieRecruit scrolling=no frameborder=0 src=http://javafxdemos.googlecode.com/hg/resource/PieRecruit/PieRecruit.html height=260 width=230 ></IFRAME>";
}
| JavaScript |
function showJavaFXJavaScriptApplet() {
document.getElementById("JavaFXJavaScriptApplet").innerHTML = "<IFRAME alt=JavaFXJavaScript scrolling=no frameborder=0 src=http://javafxdemos.googlecode.com/hg/resource/JavaFXJavaScript/JavaFXJavaScript.html width=307 height=412 ></IFRAME>";
}
| JavaScript |
(function() {
var write_string = '<iframe src="http://widgets.dzone.com/links/widgets/zoneit.html?t=';
write_string += window.dzone_style ? window.dzone_style : '1';
write_string += '&url=http://blogs.sun.com/rakeshmenonp/en_US/entry/javafx_javascript';
if (window.dzone_title) write_string += '&title=' + encodeURIComponent(dzone_title);
else write_string += '&title=' + encodeURIComponent(document.title);
if (window.dzone_blurb) write_string += '&description=' + encodeURIComponent(dzone_blurb);
if (window.dzone_style == '2') write_string += '" height="25" width="155" scrolling="no" frameborder="0"></iframe>';
else write_string += '" height="70" width="50" scrolling="no" frameborder="0"></iframe>';
document.write(write_string);
})() | JavaScript |
function showZOrderApplet() {
document.getElementById("ZOrderApplet").innerHTML = "<IFRAME alt=ZOrder scrolling=no frameborder=0 src=http://javafxdemos.googlecode.com/hg/resource/ZOrder/ZOrder.html width=305 height=305 ></IFRAME>";
}
| JavaScript |
(function() {
var write_string = '<iframe src="http://widgets.dzone.com/links/widgets/zoneit.html?t=';
write_string += window.dzone_style ? window.dzone_style : '1';
write_string += '&url=http://blogs.sun.com/rakeshmenonp/en_US/entry/javafx_z_order_of_nodes';
if (window.dzone_title) write_string += '&title=' + encodeURIComponent(dzone_title);
else write_string += '&title=' + encodeURIComponent(document.title);
if (window.dzone_blurb) write_string += '&description=' + encodeURIComponent(dzone_blurb);
if (window.dzone_style == '2') write_string += '" height="25" width="155" scrolling="no" frameborder="0"></iframe>';
else write_string += '" height="70" width="50" scrolling="no" frameborder="0"></iframe>';
document.write(write_string);
})()
| JavaScript |
function showJavaFXWindowApplet() {
document.getElementById("JavaFXWindowApplet").innerHTML = "<IFRAME alt=JavaFXWindow scrolling=no frameborder=0 src=http://javafxdemos.googlecode.com/hg/resource/JavaFXWindow/JavaFXWindow.html width=360 height=520 ></IFRAME>";
}
| JavaScript |
(function() {
var write_string = '<iframe src="http://widgets.dzone.com/links/widgets/zoneit.html?t=';
write_string += window.dzone_style ? window.dzone_style : '1';
write_string += '&url=http://blogs.sun.com/rakeshmenonp/en_US/entry/javafx_custom_window';
if (window.dzone_title) write_string += '&title=' + encodeURIComponent(dzone_title);
else write_string += '&title=' + encodeURIComponent(document.title);
if (window.dzone_blurb) write_string += '&description=' + encodeURIComponent(dzone_blurb);
if (window.dzone_style == '2') write_string += '" height="25" width="155" scrolling="no" frameborder="0"></iframe>';
else write_string += '" height="70" width="50" scrolling="no" frameborder="0"></iframe>';
document.write(write_string);
})()
| JavaScript |
function showRegisterFontApplet() {
document.getElementById("RegisterFontApplet").innerHTML = "<IFRAME alt=RegisterFont scrolling=no frameborder=0 src=http://javafxdemos.googlecode.com/hg/resource/RegisterFont/RegisterFont.html width=310 height=160 ></IFRAME>";
}
| JavaScript |
(function() {
var write_string = '<iframe src="http://widgets.dzone.com/links/widgets/zoneit.html?t=';
write_string += window.dzone_style ? window.dzone_style : '1';
write_string += '&url=http://blogs.sun.com/rakeshmenonp/en_US/entry/javafx_register_font';
if (window.dzone_title) write_string += '&title=' + encodeURIComponent(dzone_title);
else write_string += '&title=' + encodeURIComponent(document.title);
if (window.dzone_blurb) write_string += '&description=' + encodeURIComponent(dzone_blurb);
if (window.dzone_style == '2') write_string += '" height="25" width="155" scrolling="no" frameborder="0"></iframe>';
else write_string += '" height="70" width="50" scrolling="no" frameborder="0"></iframe>';
document.write(write_string);
})() | JavaScript |
function showTextEffectApplet() {
document.getElementById("TextEffectApplet").innerHTML = "<IFRAME alt=TextEffect scrolling=no frameborder=0 src=http://javafxdemos.googlecode.com/hg/resource/TextEffect/TextEffect.html width=355 height=155 ></IFRAME>";
}
| JavaScript |
(function() {
var write_string = '<iframe src="http://widgets.dzone.com/links/widgets/zoneit.html?t=';
write_string += window.dzone_style ? window.dzone_style : '1';
write_string += '&url=http://blogs.sun.com/rakeshmenonp/en_US/entry/javafx_text_effects';
if (window.dzone_title) write_string += '&title=' + encodeURIComponent(dzone_title);
else write_string += '&title=' + encodeURIComponent(document.title);
if (window.dzone_blurb) write_string += '&description=' + encodeURIComponent(dzone_blurb);
if (window.dzone_style == '2') write_string += '" height="25" width="155" scrolling="no" frameborder="0"></iframe>';
else write_string += '" height="70" width="50" scrolling="no" frameborder="0"></iframe>';
document.write(write_string);
})() | JavaScript |
function showJavaFXPrintApplet() {
document.getElementById("JavaFXPrintApplet").innerHTML = "<IFRAME alt=JavaFXPrint scrolling=no frameborder=0 src=http://javafxdemos.googlecode.com/hg/resource/JavaFXPrint/JavaFXPrint.html width=325 height=335 ></IFRAME>";
}
| JavaScript |
(function() {
var write_string = '<iframe src="http://widgets.dzone.com/links/widgets/zoneit.html?t=';
write_string += window.dzone_style ? window.dzone_style : '1';
write_string += '&url=http://blogs.sun.com/rakeshmenonp/entry/javafx_printing';
if (window.dzone_title) write_string += '&title=' + encodeURIComponent(dzone_title);
else write_string += '&title=' + encodeURIComponent(document.title);
if (window.dzone_blurb) write_string += '&description=' + encodeURIComponent(dzone_blurb);
if (window.dzone_style == '2') write_string += '" height="25" width="155" scrolling="no" frameborder="0"></iframe>';
else write_string += '" height="70" width="50" scrolling="no" frameborder="0"></iframe>';
document.write(write_string);
})()
| JavaScript |
function showColorPickerApplet() {
document.getElementById("ColorPickerApplet").innerHTML = "<IFRAME alt=ColorPicker scrolling=no frameborder=0 src=http://javafxdemos.googlecode.com/hg/resource/ColorPicker/ColorPicker.html height=470 width=410 ></IFRAME>";
}
| JavaScript |
function showComboBoxApplet() {
document.getElementById("ComboBoxApplet").innerHTML = "<IFRAME alt=ComboBox scrolling=no frameborder=0 src=http://javafxdemos.googlecode.com/hg/resource/ComboBox/ComboBox.html height=330 width=330></IFRAME>";
}
| JavaScript |
function showSlideShowApplet() {
document.getElementById("SlideShowApplet").innerHTML = "<IFRAME alt=SlideShow scrolling=no frameborder=0 src=http://javafxdemos.googlecode.com/hg/resource/SlideShow/SlideShow.html height=430 width=500 ></IFRAME>";
}
| JavaScript |
(function() {
var write_string = '<iframe src="http://widgets.dzone.com/links/widgets/zoneit.html?t=';
write_string += window.dzone_style ? window.dzone_style : '1';
write_string += '&url=http://blogs.sun.com/rakeshmenonp/entry/javafx_upload_file';
if (window.dzone_title) write_string += '&title=' + encodeURIComponent(dzone_title);
else write_string += '&title=' + encodeURIComponent(document.title);
if (window.dzone_blurb) write_string += '&description=' + encodeURIComponent(dzone_blurb);
if (window.dzone_style == '2') write_string += '" height="25" width="155" scrolling="no" frameborder="0"></iframe>';
else write_string += '" height="70" width="50" scrolling="no" frameborder="0"></iframe>';
document.write(write_string);
})()
| JavaScript |
function showJavaFXYTApplet() {
document.getElementById("JavaFXYTApplet").innerHTML = "<IFRAME alt=JavaFXYT scrolling=no frameborder=0 src=http://javafxdemos.googlecode.com/hg/resource/JavaFXYT/JavaFXYT.html width=428 height=532 ></IFRAME>";
}
| JavaScript |
(function() {
var write_string = '<iframe src="http://widgets.dzone.com/links/widgets/zoneit.html?t=';
write_string += window.dzone_style ? window.dzone_style : '1';
write_string += '&url=http://blogs.sun.com/rakeshmenonp/en_US/entry/javafx_youtube';
if (window.dzone_title) write_string += '&title=' + encodeURIComponent(dzone_title);
else write_string += '&title=' + encodeURIComponent(document.title);
if (window.dzone_blurb) write_string += '&description=' + encodeURIComponent(dzone_blurb);
if (window.dzone_style == '2') write_string += '" height="25" width="155" scrolling="no" frameborder="0"></iframe>';
else write_string += '" height="70" width="50" scrolling="no" frameborder="0"></iframe>';
document.write(write_string);
})() | JavaScript |
/**
* YouTube JavaScript Functions
*/
function onYouTubePlayerReady(playerId) {
ytplayer = document.getElementById("jfxytplayer");
ytplayer.addEventListener("onStateChange", "onPlayerStateChange");
ytplayer.addEventListener("onError", "onPlayerError");
}
function onPlayerStageChange(newState) {
//alert("onPlayerStageChange: " + newState);
}
function onPlayerError(errorCode) {
//alert("onPlayerError: " + errorCode);
}
// functions for the api calls
function loadNewVideo(id, startSeconds) {
if (ytplayer) {
ytplayer.loadVideoById(id, parseInt(startSeconds));
}
}
function cueNewVideo(id, startSeconds) {
if (ytplayer) {
ytplayer.cueVideoById(id, startSeconds);
}
}
function play() {
if (ytplayer) {
ytplayer.playVideo();
}
}
function pause() {
if (ytplayer) {
ytplayer.pauseVideo();
}
}
function stop() {
if (ytplayer) {
ytplayer.stopVideo();
}
}
function getPlayerState() {
if (ytplayer) {
return ytplayer.getPlayerState();
}
}
function seekTo(seconds) {
if (ytplayer) {
ytplayer.seekTo(seconds, true);
}
}
function getBytesLoaded() {
if (ytplayer) {
return ytplayer.getVideoBytesLoaded();
}
}
function getBytesTotal() {
if (ytplayer) {
return ytplayer.getVideoBytesTotal();
}
}
function getCurrentTime() {
if (ytplayer) {
return ytplayer.getCurrentTime();
}
}
function getDuration() {
if (ytplayer) {
return ytplayer.getDuration();
}
}
function getStartBytes() {
if (ytplayer) {
return ytplayer.getVideoStartBytes();
}
}
function mute() {
if (ytplayer) {
ytplayer.mute();
}
}
function unMute() {
if (ytplayer) {
ytplayer.unMute();
}
}
function getEmbedCode() {
alert(ytplayer.getVideoEmbedCode());
}
function getVideoUrl() {
alert(ytplayer.getVideoUrl());
}
function setVolume(newVolume) {
if (ytplayer) {
ytplayer.setVolume(newVolume);
}
}
function getVolume() {
if (ytplayer) {
return ytplayer.getVolume();
}
}
function clearVideo() {
if (ytplayer) {
ytplayer.clearVideo();
}
}
| JavaScript |
(function() {
var write_string = '<iframe src="http://widgets.dzone.com/links/widgets/zoneit.html?t=';
write_string += window.dzone_style ? window.dzone_style : '1';
write_string += '&url=http://blogs.sun.com/rakeshmenonp/en_US/entry/javafx_fps_meter';
if (window.dzone_title) write_string += '&title=' + encodeURIComponent(dzone_title);
else write_string += '&title=' + encodeURIComponent(document.title);
if (window.dzone_blurb) write_string += '&description=' + encodeURIComponent(dzone_blurb);
if (window.dzone_style == '2') write_string += '" height="25" width="155" scrolling="no" frameborder="0"></iframe>';
else write_string += '" height="70" width="50" scrolling="no" frameborder="0"></iframe>';
document.write(write_string);
})() | JavaScript |
function showLoadImageApplet() {
document.getElementById("LoadImageApplet").innerHTML = "<IFRAME alt=LoadImage scrolling=no frameborder=0 src=http://javafxdemos.googlecode.com/hg/resource/LoadImage/LoadImage.html height=235 width=310 ></IFRAME>";
}
| JavaScript |
(function() {
var write_string = '<iframe src="http://widgets.dzone.com/links/widgets/zoneit.html?t=';
write_string += window.dzone_style ? window.dzone_style : '1';
write_string += '&url=http://blogs.sun.com/rakeshmenonp/en_US/';
if (window.dzone_title) write_string += '&title=' + encodeURIComponent(dzone_title);
else write_string += '&title=' + encodeURIComponent(document.title);
if (window.dzone_blurb) write_string += '&description=' + encodeURIComponent(dzone_blurb);
if (window.dzone_style == '2') write_string += '" height="25" width="155" scrolling="no" frameborder="0"></iframe>';
else write_string += '" height="70" width="50" scrolling="no" frameborder="0"></iframe>';
document.write(write_string);
})() | JavaScript |
function showDrawApplet() {
document.getElementById("DrawApplet").innerHTML = "<IFRAME alt=Draw scrolling=no frameborder=0 src=http://javafxdemos.googlecode.com/hg/resource/Draw/Draw.html height=305 width=455 ></IFRAME>";
}
| JavaScript |
function showLineChartApplet() {
document.getElementById("LineChartApplet").innerHTML = "<IFRAME alt=LineChart scrolling=no frameborder=0 src=http://javafxdemos.googlecode.com/hg/resource/LineChart/LineChart.html height=330 width=430 ></IFRAME>";
}
| JavaScript |
function showProgressListenerFXApplet() {
document.getElementById("ProgressListenerFXApplet").innerHTML = "<IFRAME alt=ProgressListenerFX scrolling=no frameborder=0 src=http://javafxdemos.googlecode.com/hg/resource/ProgressListener/ProgressListenerFX.html width=245 height=330 ></IFRAME>";
}
| JavaScript |
(function() {
var write_string = '<iframe src="http://widgets.dzone.com/links/widgets/zoneit.html?t=';
write_string += window.dzone_style ? window.dzone_style : '1';
write_string += '&url=http://rakeshmenonp.wordpress.com/2010/02/08/java-download-service-listener/';
if (window.dzone_title) write_string += '&title=' + encodeURIComponent(dzone_title);
else write_string += '&title=' + encodeURIComponent(document.title);
if (window.dzone_blurb) write_string += '&description=' + encodeURIComponent(dzone_blurb);
if (window.dzone_style == '2') write_string += '" height="25" width="155" scrolling="no" frameborder="0"></iframe>';
else write_string += '" height="70" width="50" scrolling="no" frameborder="0"></iframe>';
document.write(write_string);
})()
| JavaScript |
function showSVGPathApplet() {
document.getElementById("SVGPathApplet").innerHTML = "<IFRAME alt=ShoppingService scrolling=no frameborder=0 src=http://javafxdemos.googlecode.com/hg/resource/SVGPath/SVGPath.html height=590 width=470 ></IFRAME>";
}
| JavaScript |
function showLightEffectApplet() {
document.getElementById("LightEffectApplet").innerHTML = "<IFRAME alt=ShoppingService scrolling=no frameborder=0 src=http://javafxdemos.googlecode.com/hg/resource/LightEffect/LightEffect.html height=685 width=450 ></IFRAME>";
}
| JavaScript |
function showSudokuApplet() {
document.getElementById("SudokuApplet").innerHTML = "<IFRAME alt=ShoppingService scrolling=no frameborder=0 src=http://javafxdemos.googlecode.com/hg/resource/Sudoku/Sudoku.html height=418 width=290 ></IFRAME>";
}
| JavaScript |
function showJavaFXFacebookApplet() {
document.getElementById("JavaFXFacebookApplet").innerHTML = "<IFRAME alt=JavaFXFacebook scrolling=no frameborder=0 src=http://javafxdemos.googlecode.com/hg/resource/JavaFXFacebook/JavaFXFacebook.html width=250 height=330 ></IFRAME>";
}
| JavaScript |
(function() {
var write_string = '<iframe src="http://widgets.dzone.com/links/widgets/zoneit.html?t=';
write_string += window.dzone_style ? window.dzone_style : '1';
write_string += '&url=http://blogs.sun.com/rakeshmenonp/en_US/entry/javafx_image_viewer';
if (window.dzone_title) write_string += '&title=' + encodeURIComponent(dzone_title);
else write_string += '&title=' + encodeURIComponent(document.title);
if (window.dzone_blurb) write_string += '&description=' + encodeURIComponent(dzone_blurb);
if (window.dzone_style == '2') write_string += '" height="25" width="155" scrolling="no" frameborder="0"></iframe>';
else write_string += '" height="70" width="50" scrolling="no" frameborder="0"></iframe>';
document.write(write_string);
})()
| JavaScript |
function showLazyLoaderApplet() {
document.getElementById("LazyLoaderApplet").innerHTML = "<IFRAME alt=LazyLoader scrolling=no frameborder=0 src=http://javafxdemos.googlecode.com/hg/resource/LazyLoader/LazyLoader.html height=345 width=495 ></IFRAME>";
}
| JavaScript |
function showZemblyIPApplet() {
document.getElementById("ZemblyIPApplet").innerHTML = "<IFRAME alt=ZemblyIP scrolling=no frameborder=0 src=http://javafxdemos.googlecode.com/hg/resource/ZemblyIP/InterestingPhotos.html height=325 width=245 ></IFRAME>";
}
| JavaScript |
function showJavaFXWizardApplet() {
document.getElementById("JavaFXWizardApplet").innerHTML = "<IFRAME alt=JavaFXWizard scrolling=no frameborder=0 src=http://javafxdemos.googlecode.com/hg/resource/JavaFXWizard/JavaFXWizard.html width=390 height=260 ></IFRAME>";
}
| JavaScript |
function showStartupApplet() {
document.getElementById("StartupApplet").innerHTML = "<IFRAME alt=Startup scrolling=no frameborder=0 src=http://javafxdemos.googlecode.com/hg/resource/Startup/Startup.html width=210 height=210 ></IFRAME>";
}
| JavaScript |
function showModalDialogApplet() {
document.getElementById("ModalDialogApplet").innerHTML = "<IFRAME alt=ModalDialog scrolling=no frameborder=0 src=http://javafxdemos.googlecode.com/hg/resource/ModalDialog/ModalDialog.html width=310 height=210 ></IFRAME>";
}
| JavaScript |
(function() {
var write_string = '<iframe src="http://widgets.dzone.com/links/widgets/zoneit.html?t=';
write_string += window.dzone_style ? window.dzone_style : '1';
write_string += '&url=http://blogs.sun.com/rakeshmenonp/en_US/entry/javafx_modal_dialog';
if (window.dzone_title) write_string += '&title=' + encodeURIComponent(dzone_title);
else write_string += '&title=' + encodeURIComponent(document.title);
if (window.dzone_blurb) write_string += '&description=' + encodeURIComponent(dzone_blurb);
if (window.dzone_style == '2') write_string += '" height="25" width="155" scrolling="no" frameborder="0"></iframe>';
else write_string += '" height="70" width="50" scrolling="no" frameborder="0"></iframe>';
document.write(write_string);
})()
| JavaScript |
function showColorChooserApplet() {
document.getElementById("ColorChooserApplet").innerHTML = "<IFRAME alt=ShoppingService scrolling=no frameborder=0 src=http://javafxdemos.googlecode.com/hg/resource/ColorChooser/ColorChooser.html height=125 width=465 ></IFRAME>";
}
| JavaScript |
function showGlowEffectApplet() {
document.getElementById("GlowEffectApplet").innerHTML = "<IFRAME alt=ShoppingService scrolling=no frameborder=0 src=http://javafxdemos.googlecode.com/hg/resource/GlowEffect/GlowEffect.html height=260 width=235 ></IFRAME>";
}
| JavaScript |
function showStartupNoPackApplet() {
document.getElementById("StartupNoPackApplet").innerHTML = "<IFRAME alt=StartupNoPack scrolling=no frameborder=0 src=http://javafxdemos.googlecode.com/hg/resource/StartupNoPack/Startup.html width=210 height=210 ></IFRAME>";
}
| JavaScript |
function showPicasaViewerApplet() {
document.getElementById("PicasaViewerApplet").innerHTML = "<IFRAME alt=PicasaViewer scrolling=no frameborder=0 src=http://javafxdemos.googlecode.com/hg/resource/PicasaViewer/PicasaViewer.html width=425 height=285 ></IFRAME>";
}
| JavaScript |
(function() {
var write_string = '<iframe src="http://widgets.dzone.com/links/widgets/zoneit.html?t=';
write_string += window.dzone_style ? window.dzone_style : '1';
write_string += '&url=http://blogs.sun.com/rakeshmenonp/en_US/entry/javafx_picasa_viewer';
if (window.dzone_title) write_string += '&title=' + encodeURIComponent(dzone_title);
else write_string += '&title=' + encodeURIComponent(document.title);
if (window.dzone_blurb) write_string += '&description=' + encodeURIComponent(dzone_blurb);
if (window.dzone_style == '2') write_string += '" height="25" width="155" scrolling="no" frameborder="0"></iframe>';
else write_string += '" height="70" width="50" scrolling="no" frameborder="0"></iframe>';
document.write(write_string);
})()
| JavaScript |
function showDragNDropApplet() {
document.getElementById("DragNDropApplet").innerHTML = "<IFRAME alt=DragNDrop scrolling=no frameborder=0 src=http://javafxdemos.googlecode.com/hg/resource/DragNDrop/DragAndDrop.html width=305 height=230 ></IFRAME>";
}
| JavaScript |
function showMusicMJApplet() {
document.getElementById("MusicMJApplet").innerHTML = "<IFRAME alt=MusicMJ scrolling=no frameborder=0 src=http://javafxdemos.googlecode.com/hg/resource/MusicMJ/MusicMJ.html height=230 width=196 ></IFRAME>";
}
| JavaScript |
function showFishEyeMenuApplet() {
document.getElementById("FishEyeMenuApplet").innerHTML = "<IFRAME alt=FishEyeMenu scrolling=no frameborder=0 src=http://javafxdemos.googlecode.com/hg/resource/FishEyeMenu/FishEyeMenu.html width=580 height=160 ></IFRAME>";
}
| JavaScript |
function showBindCautionApplet() {
document.getElementById("BindCautionApplet").innerHTML = "<IFRAME alt=BindCaution scrolling=no frameborder=0 src=http://javafxdemos.googlecode.com/hg/resource/BindCaution/BindCaution.html height=105 width=335 ></IFRAME>";
}
| JavaScript |
(function() {
var write_string = '<iframe src="http://widgets.dzone.com/links/widgets/zoneit.html?t=';
write_string += window.dzone_style ? window.dzone_style : '1';
write_string += '&url=http://blogs.sun.com/rakeshmenonp/en_US/entry/javafx_for_windows_mobile_ea';
if (window.dzone_title) write_string += '&title=' + encodeURIComponent(dzone_title);
else write_string += '&title=' + encodeURIComponent(document.title);
if (window.dzone_blurb) write_string += '&description=' + encodeURIComponent(dzone_blurb);
if (window.dzone_style == '2') write_string += '" height="25" width="155" scrolling="no" frameborder="0"></iframe>';
else write_string += '" height="70" width="50" scrolling="no" frameborder="0"></iframe>';
document.write(write_string);
})() | JavaScript |
function showBookPanelApplet() {
document.getElementById("BookPanelApplet").innerHTML = "<IFRAME alt=BookPanel scrolling=no frameborder=0 src=http://javafxdemos.googlecode.com/hg/resource/BookPanel/BookPanel.html height=480 width=480 ></IFRAME>";
}
| JavaScript |
function showFlatCarouselApplet() {
document.getElementById("FlatCarouselApplet").innerHTML = "<IFRAME alt=FlatCarousel scrolling=no frameborder=0 src=http://javafxdemos.googlecode.com/hg/resource/FlatCarousel/FlatCarousel.html width=390 height=150 ></IFRAME>";
}
| JavaScript |
function showPalletEffectApplet() {
document.getElementById("PalletEffectApplet").innerHTML = "<IFRAME alt=ShoppingService scrolling=no frameborder=0 src=http://javafxdemos.googlecode.com/hg/resource/PalletEffect/PalletEffect.html height=422 width=453 ></IFRAME>";
}
| JavaScript |
function showUploadDownloadApplet() {
document.getElementById("UploadDownloadApplet").innerHTML = "<IFRAME alt=UploadDownload scrolling=no frameborder=0 src=http://javafxdemos.googlecode.com/hg/resource/UploadDownload/UploadDownload.html height=280 width=290 ></IFRAME>";
}
| JavaScript |
function showBlendModeApplet() {
document.getElementById("BlendModeApplet").innerHTML = "<IFRAME alt=ShoppingService scrolling=no frameborder=0 src=http://javafxdemos.googlecode.com/hg/resource/BlendMode/BlendMode.html height=465 width=285 ></IFRAME>";
}
| JavaScript |
function showRegisterFontApplet() {
document.getElementById("RegisterFontApplet").innerHTML = "<IFRAME alt=RegisterFont scrolling=no frameborder=0 src=http://javafxdemos.googlecode.com/hg/resource/RegisterFont/RegisterFont.html width=310 height=160 ></IFRAME>";
}
| JavaScript |
function showRippleEffectApplet() {
document.getElementById("RippleEffectApplet").innerHTML = "<IFRAME alt=RippleEffect scrolling=no frameborder=0 src=http://javafxdemos.googlecode.com/hg/resource/RippleEffect/RippleEffect.html width=300 height=265 ></IFRAME>";
}
| JavaScript |
function showRssAtomApplet() {
document.getElementById("RssAtomApplet").innerHTML = "<IFRAME alt=RssAtom scrolling=no frameborder=0 src=http://javafxdemos.googlecode.com/hg/resource/RssAtom/RssAtom.html height=50 width=410 ></IFRAME>";
}
| JavaScript |
function showMP3PlayerApplet() {
document.getElementById("MP3PlayerApplet").innerHTML = "<IFRAME alt=MP3Player scrolling=no frameborder=0 src=http://javafxdemos.googlecode.com/hg/resource/MP3Player/MP3Player.html height=350 width=515 ></IFRAME>";
}
| JavaScript |
(function() {
var write_string = '<iframe src="http://widgets.dzone.com/links/widgets/zoneit.html?t=';
write_string += window.dzone_style ? window.dzone_style : '1';
write_string += '&url=http://blogs.sun.com/rakeshmenonp/en_US/entry/javafx_the_echo_nest';
if (window.dzone_title) write_string += '&title=' + encodeURIComponent(dzone_title);
else write_string += '&title=' + encodeURIComponent(document.title);
if (window.dzone_blurb) write_string += '&description=' + encodeURIComponent(dzone_blurb);
if (window.dzone_style == '2') write_string += '" height="25" width="155" scrolling="no" frameborder="0"></iframe>';
else write_string += '" height="70" width="50" scrolling="no" frameborder="0"></iframe>';
document.write(write_string);
})() | JavaScript |
function showJavaFXDatabaseApplet() {
document.getElementById("JavaFXDatabaseApplet").innerHTML = "<IFRAME alt=JavaFXDatabase scrolling=no frameborder=0 src=http://javafxdemos.googlecode.com/hg/resource/JavaFXDatabase/JavaFXDatabase.html width=365 height=510 ></IFRAME>";
}
| JavaScript |
(function() {
var write_string = '<iframe src="http://widgets.dzone.com/links/widgets/zoneit.html?t=';
write_string += window.dzone_style ? window.dzone_style : '1';
write_string += '&url=http://blogs.sun.com/rakeshmenonp/en_US/entry/javafx_database_table';
if (window.dzone_title) write_string += '&title=' + encodeURIComponent(dzone_title);
else write_string += '&title=' + encodeURIComponent(document.title);
if (window.dzone_blurb) write_string += '&description=' + encodeURIComponent(dzone_blurb);
if (window.dzone_style == '2') write_string += '" height="25" width="155" scrolling="no" frameborder="0"></iframe>';
else write_string += '" height="70" width="50" scrolling="no" frameborder="0"></iframe>';
document.write(write_string);
})()
| JavaScript |
function showJavaFXOAuthApplet() {
document.getElementById("JavaFXOAuthApplet").innerHTML = "<IFRAME alt=JavaFXOAuth scrolling=no frameborder=0 src=http://javafxdemos.googlecode.com/hg/resource/JavaFXOAuth/JavaFXOAuth.html width=330 height=490 ></IFRAME>";
}
| JavaScript |
(function() {
var write_string = '<iframe src="http://widgets.dzone.com/links/widgets/zoneit.html?t=';
write_string += window.dzone_style ? window.dzone_style : '1';
write_string += '&url=http://blogs.sun.com/rakeshmenonp/en_US/entry/javafx_oauth';
if (window.dzone_title) write_string += '&title=' + encodeURIComponent(dzone_title);
else write_string += '&title=' + encodeURIComponent(document.title);
if (window.dzone_blurb) write_string += '&description=' + encodeURIComponent(dzone_blurb);
if (window.dzone_style == '2') write_string += '" height="25" width="155" scrolling="no" frameborder="0"></iframe>';
else write_string += '" height="70" width="50" scrolling="no" frameborder="0"></iframe>';
document.write(write_string);
})()
| JavaScript |
function showAnimationApplet() {
document.getElementById("AnimationApplet").innerHTML = "<IFRAME alt=Animation scrolling=no frameborder=0 src=http://javafxdemos.googlecode.com/hg/resource/Animation/Animation.html height=210 width=210 ></IFRAME>";
}
| JavaScript |
function showPlaceListApplet() {
document.getElementById("PlaceListApplet").innerHTML = "<IFRAME alt=PlaceList scrolling=no frameborder=0 src=http://javafxdemos.googlecode.com/hg/resource/PlaceList/PlaceList.html height=420 width=430 ></IFRAME>";
}
| JavaScript |
function showWeatherApplet() {
document.getElementById("WeatherApplet").innerHTML = "<IFRAME alt=Weather scrolling=no frameborder=0 src=http://javafxdemos.googlecode.com/hg/resource/Weather/Weather.html width=266 height=139 ></IFRAME>";
}
| JavaScript |
(function() {
var write_string = '<iframe src="http://widgets.dzone.com/links/widgets/zoneit.html?t=';
write_string += window.dzone_style ? window.dzone_style : '1';
write_string += '&url=http://blogs.sun.com/rakeshmenonp/entry/javafx_yahoo_weather';
if (window.dzone_title) write_string += '&title=' + encodeURIComponent(dzone_title);
else write_string += '&title=' + encodeURIComponent(document.title);
if (window.dzone_blurb) write_string += '&description=' + encodeURIComponent(dzone_blurb);
if (window.dzone_style == '2') write_string += '" height="25" width="155" scrolling="no" frameborder="0"></iframe>';
else write_string += '" height="70" width="50" scrolling="no" frameborder="0"></iframe>';
document.write(write_string);
})()
| JavaScript |
(function() {
var write_string = '<iframe src="http://widgets.dzone.com/links/widgets/zoneit.html?t=';
write_string += window.dzone_style ? window.dzone_style : '1';
write_string += '&url=http://blogs.sun.com/rakeshmenonp/entry/javafx_splash_screen';
if (window.dzone_title) write_string += '&title=' + encodeURIComponent(dzone_title);
else write_string += '&title=' + encodeURIComponent(document.title);
if (window.dzone_blurb) write_string += '&description=' + encodeURIComponent(dzone_blurb);
if (window.dzone_style == '2') write_string += '" height="25" width="155" scrolling="no" frameborder="0"></iframe>';
else write_string += '" height="70" width="50" scrolling="no" frameborder="0"></iframe>';
document.write(write_string);
})() | JavaScript |
(function() {
var write_string = '<iframe src="http://widgets.dzone.com/links/widgets/zoneit.html?t=';
write_string += window.dzone_style ? window.dzone_style : '1';
write_string += '&url=http://blogs.sun.com/rakeshmenonp/en_US/entry/javafx_splash_screen';
if (window.dzone_title) write_string += '&title=' + encodeURIComponent(dzone_title);
else write_string += '&title=' + encodeURIComponent(document.title);
if (window.dzone_blurb) write_string += '&description=' + encodeURIComponent(dzone_blurb);
if (window.dzone_style == '2') write_string += '" height="25" width="155" scrolling="no" frameborder="0"></iframe>';
else write_string += '" height="70" width="50" scrolling="no" frameborder="0"></iframe>';
document.write(write_string);
})() | JavaScript |
function showClipViewApplet() {
document.getElementById("ClipViewApplet").innerHTML = "<IFRAME alt=ClipView scrolling=no frameborder=0 src=http://javafxdemos.googlecode.com/hg/resource/ClipView/ClipView.html height=443 width=322 ></IFRAME>";
}
| JavaScript |
/*
Makes use of no third-party code (for better or worse)
Copyright (c) 2013
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
(function () {
'use strict';
var calories_per_day = 75,
seg_time = 30,
total_day_time = seg_time * 16,
seg_time = total_day_time / 16,
day_segs = 10,
dusk_segs = 4,
night_segs = 2,
day_time = seg_time * day_segs,
dusk_time = seg_time * dusk_segs,
night_time = seg_time * night_segs,
perish_warp = 1,
stack_size_largeitem = 10,
stack_size_meditem = 20,
stack_size_smallitem = 40,
healing_tiny = 1,
healing_small = 3,
healing_medsmall = 8,
healing_med = 20,
healing_medlarge = 30,
healing_large = 40,
healing_huge = 60,
healing_superhuge = 100,
sanity_supertiny = 1,
sanity_tiny = 5,
sanity_small = 10,
sanity_med = 15,
sanity_medlarge = 20,
sanity_large = 33,
sanity_huge = 50,
perish_superfast = 3*total_day_time*perish_warp,
perish_fast = 6*total_day_time*perish_warp,
perish_med = 10*total_day_time*perish_warp,
perish_slow = 15*total_day_time*perish_warp,
perish_preserved = 20*total_day_time*perish_warp,
perish_superslow = 40*total_day_time*perish_warp,
dry_fast = total_day_time,
dry_med = 2*total_day_time,
calories_tiny = calories_per_day/8, // berries
calories_small = calories_per_day/6, // veggies
calories_medsmall = calories_per_day/4,
calories_med = calories_per_day/3, // meat
calories_large = calories_per_day/2, // cooked meat
calories_huge = calories_per_day, // crockpot foods?
calories_superhuge = calories_per_day*2, // crockpot foods?
spoiled_health = -1,
spoiled_hunger = -10,
perish_fridge_mult = .5,
perish_ground_mult = 1.5,
perish_global_mult = 1,
perish_winter_mult = .75,
stale_food_hunger = .667,
spoiled_food_hunger = .5,
stale_food_health = .333,
spoiled_food_health = 0,
base_cook_time = night_time*.3333,
tips = [
'Cooking meat '
],
Strings = {
'butter': 'Butter',
'butterflywings': 'Butterfly Wings',
'fish': 'Fish'
},
food = {
butter: {
name: Strings.butter,
fat: 1,
dairy: 1,
health: healing_large,
hunger: calories_med,
perish: perish_superslow,
stack: stack_size_smallitem
},
butterflywings: {
name: Strings.butterflywings,
isveggie: true,
decoration: 2,
health: healing_medsmall,
hunger: calories_tiny,
perish: perish_fast,
stack: stack_size_smallitem
},
deerclopseyeball: {
name: 'Deerclops Eyeball',
uncookable: true,
health: healing_huge,
hunger: calories_huge,
sanity: -sanity_med
},
bird_egg: {
name: 'Egg',
egg: 1,
health: 0,
hunger: calories_tiny,
sanity: 0,
perish: perish_med,
stack: stack_size_smallitem,
rot: 'rottenegg'
},
bird_egg_cooked: {
name: 'Cooked Egg',
egg: 1,
precook: 1,
health: 0,
hunger: calories_small,
sanity: 0,
perish: perish_fast,
stack: stack_size_smallitem
},
rottenegg: {
name: 'Rotten Egg',
uncookable: true,
health: spoiled_health,
hunger: spoiled_hunger,
stack: stack_size_smallitem
},
fish: {
name: Strings.fish,
ismeat: true,
meat: 0.5,
fish: 1,
health: healing_tiny,
hunger: calories_small,
perish: perish_superfast,
stack: stack_size_smallitem
},
fish_cooked: {
name: 'Cooked Fish',
ismeat: true,
meat: 0.5,
fish: 1,
precook: 1,
health: healing_tiny,
hunger: calories_small,
perish: perish_fast,
stack: stack_size_smallitem
},
froglegs: {
name: 'Frog Legs',
ismeat: true,
meat: 0.5,
health: 0,
hunger: calories_small,
perish: perish_fast,
sanity: -sanity_small,
stack: stack_size_smallitem
},
froglegs_cooked: {
name: 'Cooked Frog Legs',
ismeat: true,
meat: 0.5,
precook: 1,
health: healing_tiny,
hunger: calories_small,
perish: perish_med,
sanity: 0,
stack: stack_size_smallitem
},
flowerhat: {
name: 'Garland',
health: healing_small,
hunger: 0,
sanity: sanity_small,
perish: perish_fast,
stack: 1,
uncookable: true
},
hambat: {
name: 'Ham Bat',
health: -healing_medsmall,
hunger: calories_med,
sanity: -sanity_med,
perish: perish_med,
stack: 1,
uncookable: true
},
honey: {
name: 'Honey',
sweetener: true,
health: healing_small,
hunger: calories_tiny,
perish: perish_superslow,
stack: stack_size_smallitem
},
honeycomb: {
name: 'Honeycomb',
sweetener: true
},
lightbulb: {
name: 'Light Bulb',
health: healing_tiny,
hunger: 0,
perish: perish_fast,
stack: stack_size_smallitem,
uncookable: true
},
mandrake: {
name: 'Mandrake',
veggie: 1,
magic: 1,
health: healing_huge,
hunger: calories_huge,
stack: stack_size_smallitem
},
mandrake_cooked: {
name: 'Cooked Mandrake',
uncookable: true,
veggie: 1,
magic: 1,
precook: 1,
health: healing_superhuge,
hunger: calories_superhuge,
stack: stack_size_smallitem
},
plantmeat: {
name: 'Leafy Meat',
uncookable: true,
health: 0,
hunger: calories_small,
sanity: -sanity_small,
perish: perish_fast,
stack: stack_size_smallitem
},
plantmeat_cooked: {
name: 'Cooked Leafy Meat',
uncookable: true,
health: healing_tiny,
hunger: calories_medsmall,
sanity: 0,
perish: perish_med,
stack: stack_size_smallitem
},
monstermeat: {
name: 'Monster Meat',
ismeat: true,
meat: 1,
monster: true,
health: -healing_med,
hunger: calories_medsmall,
sanity: -sanity_med,
perish: perish_fast,
stack: stack_size_meditem,
dry: 'monstermeat_dried',
drytime: dry_fast
},
monstermeat_cooked: {
name: 'Cooked Monster Meat',
ismeat: true,
meat: 1,
monster: true,
precook: 1,
health: -healing_small,
hunger: calories_medsmall,
sanity: -sanity_small,
perish: perish_slow,
stack: stack_size_meditem
},
monstermeat_dried: {
name: 'Monster Jerky',
ismeat: true,
meat: 1,
monster: true,
dried: 1,
health: -healing_small,
hunger: calories_medsmall,
sanity: -sanity_tiny,
perish: perish_preserved,
stack: stack_size_meditem
},
meat: {
name: 'Meat',
ismeat: true,
meat: 1,
health: healing_tiny,
hunger: calories_med,
sanity: -sanity_small,
perish: perish_fast,
stack: stack_size_meditem,
dry: 'meat_dried',
drytime: dry_med
},
meat_cooked: {
name: 'Cooked Meat',
ismeat: true,
meat: 1,
precook: 1,
health: healing_small,
hunger: calories_med,
sanity: 0,
perish: perish_med,
stack: stack_size_meditem
},
meat_dried: {
name: 'Jerky',
ismeat: true,
meat: 1,
dried: 1,
health: healing_med,
hunger: calories_med,
sanity: sanity_med,
perish: perish_preserved,
stack: stack_size_meditem
},
morsel: {
name: 'Morsel',
ismeat: true,
meat: 0.5,
health: 0,
hunger: calories_small,
sanity: -sanity_small,
perish: perish_fast,
stack: stack_size_smallitem,
drytime: dry_fast,
dry: 'smallmeat_dried'
},
morsel_cooked: {
name: 'Cooked Morsel',
ismeat: true,
meat: 0.5,
precook: 1,
health: healing_tiny,
hunger: calories_small,
sanity: 0,
perish: perish_med,
stack: stack_size_smallitem
},
smallmeat_dried: {
name: 'Small Jerky',
ismeat: true,
meat: 0.5,
dried: 1,
health: healing_medsmall,
hunger: calories_small,
sanity: sanity_small,
perish: perish_preserved,
stack: stack_size_smallitem
},
drumstick: {
name: 'Drumstick',
ismeat: true,
ideal: true,
meat: 0.5,
health: 0,
hunger: calories_small,
sanity: -sanity_small,
perish: perish_fast,
stack: stack_size_meditem,
drytime: dry_fast,
dry: 'smallmeat_dried'
},
drumstick_cooked: {
name: 'Fried Drumstick',
ismeat: true,
meat: 0.5,
precook: 1,
health: healing_tiny,
hunger: calories_small,
perish: perish_med,
stack: stack_size_meditem
},
batwing: {
name: 'Batilisk Wing',
ismeat: true,
health: healing_small,
hunger: calories_small,
sanity: -sanity_small,
perish: perish_fast,
stack: stack_size_smallitem,
drytime: dry_med,
dry: 'smallmeat_dried',
uncookable: true
},
batwing_cooked: {
name: 'Cooked Batilisk Wing',
ismeat: true,
health: healing_medsmall,
hunger: calories_medsmall,
sanity: 0,
perish: perish_med,
uncookable: true
},
red_mushroom: {
name: 'Red Cap',
veggie: 0.5,
ideal: true,
health: -healing_med,
hunger: calories_small,
sanity: 0,
perish: perish_med,
stack: stack_size_smallitem
},
red_mushroom_cooked: {
name: 'Cooked Red Cap',
veggie: 0.5,
health: healing_tiny,
hunger: 0,
sanity: -sanity_small,
perish: perish_med,
stack: stack_size_smallitem
},
green_mushroom: {
name: 'Green Cap',
veggie: 0.5,
ideal: true,
health: 0,
hunger: calories_small,
sanity: -sanity_huge,
perish: perish_med,
stack: stack_size_smallitem
},
green_mushroom_cooked: {
name: 'Cooked Green Cap',
veggie: 0.5,
health: -healing_tiny,
hunger: 0,
sanity: sanity_med,
perish: perish_med,
stack: stack_size_smallitem
},
blue_mushroom: {
name: 'Blue Cap',
veggie: 0.5,
ideal: true,
health: healing_med,
hunger: calories_small,
sanity: -sanity_med,
perish: perish_med,
stack: stack_size_smallitem
},
blue_mushroom_cooked: {
name: 'Cooked Blue Cap',
veggie: 0.5,
health: -healing_small,
hunger: 0,
sanity: sanity_small,
perish: perish_med,
stack: stack_size_smallitem
},
petals: {
name: 'Petals',
uncookable: true,
health: healing_tiny,
hunger: 0,
sanity: -sanity_tiny / 2,
perish: perish_fast,
stack: stack_size_smallitem
},
petals_evil: {
name: 'Dark Petals',
uncookable: true,
health: 0,
hunger: 0,
sanity: -sanity_tiny,
perish: perish_fast,
stack: stack_size_smallitem
},
seeds: {
name: 'Seeds',
uncookable: true,
health: 0,
hunger: calories_tiny / 2,
perish: perish_superslow,
stack: stack_size_smallitem
},
seeds_cooked: {
name: 'Toasted Seeds',
uncookable: true,
health: healing_tiny,
hunger: calories_tiny / 2,
perish: perish_med,
stack: stack_size_smallitem
},
spoiled_food: {
name: 'Rot',
uncookable: true,
health: spoiled_health,
hunger: spoiled_hunger,
stack: stack_size_smallitem
},
tallbirdegg: {
name: 'Tallbird Egg',
egg: 4,
health: healing_small,
hunger: calories_med
},
tallbirdegg_cooked: {
name: 'Fried Tallbird Egg',
egg: 4,
precook: 1,
health: 0,
hunger: calories_large,
perish: perish_fast
},
trunk_summer: {
name: 'Koalefant Trunk',
uncookable: true,
ismeat: true,
health: healing_medlarge,
hunger: calories_large,
sanity: 0,
perish: perish_fast,
stack: stack_size_meditem
},
trunk_summer_cooked: {
name: 'Koalefant Trunk Steak',
uncookable: true,
ismeat: true,
health: healing_large,
hunger: calories_huge,
sanity: 0,
perish: perish_slow,
stack: stack_size_meditem
},
twigs: {
name: 'Twigs',
inedible: 1
},
cavebanana: {
name: 'Cave Banana',
isfruit: true,
fruit: 1,
health: healing_tiny,
hunger: calories_small,
sanity: 0,
perish: perish_med
},
cavebanana_cooked: {
name: 'Cooked Banana',
isfruit: true,
fruit: 1,
precook: 1,
health: healing_small,
hunger: calories_small,
sanity: 0,
perish: perish_fast
},
carrot: {
name: 'Carrot',
isveggie: true,
veggie: 1,
health: healing_tiny,
hunger: calories_small,
perish: perish_med,
sanity: 0,
stack: stack_size_smallitem
},
carrot_cooked: {
name: 'Roasted Carrot',
isveggie: true,
veggie: 1,
precook: 1,
health: healing_small,
hunger: calories_small,
perish: perish_fast,
sanity: 0,
stack: stack_size_smallitem
},
corn: {
name: 'Corn',
ideal: true,
isveggie: true,
veggie: 1,
health: healing_small,
hunger: calories_med,
perish: perish_med,
sanity: 0,
stack: stack_size_smallitem
},
corn_cooked: {
name: 'Popcorn',
isveggie: true,
veggie: 1,
precook: 1,
health: healing_small,
hunger: calories_small,
perish: perish_slow,
sanity: 0,
stack: stack_size_smallitem
},
pumpkin: {
name: 'Pumpkin',
isveggie: true,
veggie: 1,
health: healing_small,
hunger: calories_large,
perish: perish_med,
sanity: 0,
stack: stack_size_meditem
},
pumpkin_cooked: {
name: 'Hot Pumpkin',
isveggie: true,
veggie: 1,
precook: 1,
health: healing_medsmall,
hunger: calories_large,
perish: perish_fast,
sanity: 0,
stack: stack_size_meditem
},
eggplant: {
name: 'Eggplant',
isveggie: true,
veggie: 1,
health: healing_medsmall,
hunger: calories_med,
perish: perish_med,
sanity: 0,
stack: stack_size_meditem
},
eggplant_cooked: {
name: 'Braised Eggplant',
isveggie: true,
veggie: 1,
precook: 1,
health: healing_med,
hunger: calories_med,
perish: perish_fast,
sanity: 0,
stack: stack_size_meditem
},
durian: {
name: 'Durian',
isfruit: true,
monster: 1,
fruit: 1,
health: -healing_small,
hunger: calories_med,
perish: perish_med,
sanity: -sanity_tiny,
stack: stack_size_meditem
},
durian_cooked: {
name: 'Extra Smelly Durian',
isfruit: true,
monster: 1,
fruit: 1,
precook: 1,
health: 0,
hunger: calories_med,
perish: perish_fast,
sanity: -sanity_tiny,
stack: stack_size_meditem
},
pomegranate: {
name: 'Pomegranate',
isfruit: true,
fruit: 1,
health: healing_small,
hunger: calories_tiny,
perish: perish_fast,
sanity: 0,
stack: stack_size_smallitem
},
pomegranate_cooked: {
name: 'Sliced Pomegranate',
isfruit: true,
fruit: 1,
precook: 1,
health: healing_med,
hunger: calories_small,
perish: perish_superfast,
sanity: 0,
stack: stack_size_smallitem
},
dragonfruit: {
name: 'Dragon Fruit',
isfruit: true,
fruit: 1,
health: healing_small,
hunger: calories_tiny,
perish: perish_fast,
sanity: 0,
stack: stack_size_smallitem
},
dragonfruit_cooked: {
name: 'Prepared Dragon Fruit',
isfruit: true,
fruit: 1,
precook: 1,
health: healing_med,
hunger: calories_small,
perish: perish_superfast,
sanity: 0,
stack: stack_size_smallitem
},
berries: {
name: 'Berries',
isfruit: true,
fruit: 0.5,
health: 0,
hunger: calories_tiny,
perish: perish_fast,
sanity: 0,
stack: stack_size_smallitem
},
berries_cooked: {
name: 'Roasted Berries',
isfruit: true,
fruit: 0.5,
precook: 1,
health: healing_tiny,
hunger: calories_small,
perish: perish_superfast,
sanity: 0,
stack: stack_size_smallitem
}
},
//note: qty not used yet, this is for rapid summation
COMPAREString = function () { return this.op + this.qty; },
COMPARISONS = {
'=': function (qty) { return qty === this.qty; },
'>': function (qty) { return qty > this.qty; },
'<': function (qty) { return qty < this.qty; },
'>=': function (qty) { return qty >= this.qty; },
'<=': function (qty) { return qty <= this.qty; }
},
NOQTY = {test: function (qty) { return !!qty; }, toString: function () { return ''; }},
COMPARE = function (op, qty) { return {op: op, qty: qty, test: COMPARISONS[op], toString: COMPAREString}; },
ORTest = function (cooker, names, tags) { return this.item1.test(cooker, names, tags) || this.item2.test(cooker, names, tags); },
ORString = function () { return this.item1 + ' or ' + this.item2; },
OR = function (item1, item2) { return {item1: item1, item2: item2, test: ORTest, toString: ORString, cancel: item1.cancel || item2.cancel}; },
NOTTest = function (cooker, names, tags) { return !this.item.test(cooker, names, tags); },
NOTString = function () { return this.item.toString().substring(0, this.item.toString().length - 1) + '|strike]'; },
NOT = function (item) { return {item: item, test: NOTTest, toString: NOTString, cancel: true}; },
NAMETest = function (cooker, names, tags) { return (names[this.name] || 0) + (names[this.name + '_cooked'] || 0); },
NAMEString = function () { return '[*' + food[this.name].name + '|' + food[this.name].img + ' ' + food[this.name].name + ']' + (food[this.name].cook ? '[*' + food[this.name].cook.name + '|' + food[this.name].cook.img + ']' : '') + (food[this.name].raw ? '[*' + food[this.name].raw.name + '|' + food[this.name].raw.img + ']' : '') + (this.qty ? this.qty : ''); },
NAME = function (name, qty) { return {name: name, qty: qty || NOQTY, test: NAMETest, toString: NAMEString}; }, //permits cooked variant
SPECIFICTest = function (cooker, names, tags) { return names[this.name]; },
SPECIFICString = function () { return '[*' + food[this.name].name + '|' + food[this.name].img + ' ' + food[this.name].name + ']' + (this.qty ? this.qty : ''); },
SPECIFIC = function (name, qty) { return {name: name, qty: qty || NOQTY, test: SPECIFICTest, toString: SPECIFICString}; }, //disallows cooked/uncooked variant
TAGTest = function (cooker, names, tags) { return tags[this.tag]; },
TAGString = function () { return '[tag:' + this.tag + '|' + this.tag + ']' + (this.qty ? this.qty : ''); },
TAG = function (tag, qty) { return {tag: tag, qty: qty || NOQTY, test: TAGTest, toString: TAGString}; },
recipes = {
butterflymuffin: {
name: 'Butter Muffin',
test: function(cooker, names, tags) {
return names.butterflywings && !tags.meat && tags.veggie;
},
requires: 'Butterfly Wings, veggie',
requirements: [NAME('butterflywings'), NOT(TAG('meat')), TAG('veggie')],
priority: 1,
weight: 1,
foodtype: "veggie",
health: healing_med,
hunger: calories_large,
perish: perish_slow,
sanity: sanity_tiny,
cooktime: 2
},
frogglebunwich: {
name: 'Froggle Bunwich',
test: function(cooker, names, tags) {
return (names.froglegs || names.froglegs_cooked) && tags.veggie;
},
requirements: [NAME('froglegs'), TAG('veggie')],
priority: 1,
foodtype: "meat",
health: healing_med,
hunger: calories_large,
perish: perish_slow,
sanity: sanity_tiny,
cooktime: 2
},
taffy: {
name: "Taffy",
test: function(cooker, names, tags) {
return tags.sweetener && tags.sweetener >= 3 && !tags.meat;
},
requirements: [TAG('sweetener', COMPARE('>=', 3)), NOT(TAG('meat'))],
priority: 10,
foodtype: "veggie",
health: -healing_small,
hunger: calories_small * 2,
perish: perish_slow,
sanity: sanity_med,
cooktime: 2
},
pumpkincookie: {
name: "Pumpkin Cookie",
test: function(cooker, names, tags) {
return (names.pumpkin || names.pumpkin_cooked) && tags.sweetener && tags.sweetener >= 2;
},
requirements: [NAME('pumpkin'), TAG('sweetener', COMPARE('>=', 2))],
priority: 10,
foodtype: "veggie",
health: 0,
hunger: calories_large,
perish: perish_med,
sanity: sanity_med,
cooktime: 2
},
stuffedeggplant: {
name: 'Stuffed Eggplant',
test: function(cooker, names, tags) {
return (names.eggplant || names.eggplant_cooked) && tags.veggie && tags.veggie > 1;
},
requirements: [NAME('eggplant'), TAG('veggie', COMPARE('>', 1))],
priority: 1,
foodtype: "veggie",
health: healing_small,
hunger: calories_large,
perish: perish_slow,
sanity: sanity_tiny,
cooktime: 2
},
fishsticks: {
name: 'Fishsticks',
test: function(cooker, names, tags) {
return tags.fish && names.twigs && (tags.inedible && tags.inedible <= 1);
},
requirements: [TAG('fish'), SPECIFIC('twigs'), TAG('inedible'), TAG('inedible', COMPARE('<=', 1))],
priority: 10,
foodtype: "meat",
health: healing_large,
hunger: calories_large,
perish: perish_med,
sanity: sanity_tiny,
cooktime: 2
},
honeynuggets: {
name: 'Honey Nuggets',
test: function(cooker, names, tags) {
return names.honey && tags.meat && tags.meat <= 1.5 && !tags.inedible;
},
requirements: [SPECIFIC('honey'), TAG('meat', COMPARE('<=', 1.5)), NOT(TAG('inedible'))],
priority: 2,
foodtype: "meat",
health: healing_med,
hunger: calories_large,
perish: perish_slow,
sanity: sanity_tiny,
cooktime: 2
},
honeyham: {
name: 'Honey Ham',
test: function(cooker, names, tags) {
return names.honey && tags.meat && tags.meat > 1.5 && !tags.inedible;
},
requirements: [SPECIFIC('honey'), TAG('meat', COMPARE('>', 1.5)), NOT(TAG('inedible'))],
priority: 2,
foodtype: "meat",
health: healing_medlarge,
hunger: calories_huge,
perish: perish_slow,
sanity: sanity_tiny,
cooktime: 2
},
dragonpie: {
name: 'Dragonpie',
test: function(cooker, names, tags) {
return (names.dragonfruit || names.dragonfruit_cooked) && !tags.meat;
},
requirements: [NAME('dragonfruit'), NOT(TAG('meat'))],
priority: 1,
foodtype: "veggie",
health: healing_large,
hunger: calories_huge,
perish: perish_slow,
sanity: sanity_tiny,
cooktime: 2
},
kabobs: {
name: 'Kabobs',
test: function(cooker, names, tags) {
return tags.meat && names.twigs && (!tags.monster || tags.monster <= 1) && (tags.inedible && tags.inedible <= 1);
},
requirements: [TAG('meat'), SPECIFIC('twigs'), OR(NOT(TAG('monster')), TAG('monster', COMPARE('<=', 1))), TAG('inedible'), TAG('inedible', COMPARE('<=', 1))],
priority: 5,
foodtype: "meat",
health: healing_small,
hunger: calories_large,
perish: perish_slow,
sanity: sanity_tiny,
cooktime: 2
},
mandrakesoup: {
name: 'Mandrake Soup',
test: function(cooker, names, tags) {
return names.mandrake;
},
requirements: [SPECIFIC('mandrake')],
priority: 10,
foodtype: "veggie",
health: healing_superhuge,
hunger: calories_superhuge,
perish: perish_fast,
sanity: sanity_tiny,
cooktime: 3
},
baconeggs: {
name: 'Bacon and Eggs',
test: function(cooker, names, tags) {
return tags.egg && tags.egg > 1 && tags.meat && tags.meat > 1 && !tags.veggie;
},
requirements: [TAG('egg', COMPARE('>', 1)), TAG('meat', COMPARE('>', 1)), NOT(TAG('veggie'))],
priority: 10,
foodtype: "meat",
health: healing_med,
hunger: calories_huge,
perish: perish_preserved,
sanity: sanity_tiny,
cooktime: 2
},
meatballs: {
name: 'Meatballs',
test: function(cooker, names, tags) {
return tags.meat && !tags.inedible;
},
requirements: [TAG('meat'), NOT(TAG('inedible'))],
priority: -1,
foodtype: "meat",
health: healing_small,
hunger: calories_small * 5,
perish: perish_med,
sanity: sanity_tiny,
cooktime: 0.75
},
bonestew: {
name: 'Meaty Stew',
test: function(cooker, names, tags) {
return tags.meat && tags.meat >= 3 && !tags.inedible;
},
requirements: [TAG('meat', COMPARE('>=', 3)), NOT(TAG('inedible'))],
priority: 0,
foodtype: "meat",
health: healing_small * 4,
hunger: calories_large * 4,
perish: perish_med,
sanity: sanity_tiny,
cooktime: 0.75
},
perogies: {
name: 'Pierogi',
test: function(cooker, names, tags) {
return tags.egg && tags.meat && tags.veggie && !tags.inedible;
},
requirements: [TAG('egg'), TAG('meat'), TAG('veggie'), NOT(TAG('inedible'))],
priority: 5,
foodtype: "meat",
health: healing_large,
hunger: calories_large,
perish: perish_preserved,
sanity: sanity_tiny,
cooktime: 1
},
turkeydinner: {
name: 'Turkey Dinner',
test: function(cooker, names, tags) {
return names.drumstick && names.drumstick > 1 && tags.meat && tags.meat > 1 && (tags.veggie || tags.fruit);
},
requirements: [SPECIFIC('drumstick', COMPARE('>', 1)), TAG('meat', COMPARE('>', 1)), OR(TAG('veggie'), TAG('fruit'))],
priority: 10,
foodtype: "meat",
health: healing_med,
hunger: calories_huge,
perish: perish_fast,
sanity: sanity_tiny,
cooktime: 3
},
ratatouille: {
name: 'Ratatouille',
test: function(cooker, names, tags) {
return !tags.meat && tags.veggie && !tags.inedible;
},
requirements: [NOT(TAG('meat')), TAG('veggie'), NOT(TAG('inedible'))],
priority: 0,
foodtype: "veggie",
health: healing_small,
hunger: calories_med,
perish: perish_slow,
sanity: sanity_tiny,
cooktime: 1
},
jammypreserves: {
name: 'Fist Full of Jam',
test: function(cooker, names, tags) {
return tags.fruit && !tags.meat && !tags.veggie && !tags.inedible;
},
requirements: [TAG('fruit'), NOT(TAG('meat')), NOT(TAG('veggie')), NOT(TAG('inedible'))],
priority: 0,
foodtype: "veggie",
health: healing_small,
hunger: calories_small * 3,
perish: perish_slow,
sanity: sanity_tiny,
cooktime: 0.5
},
fruitmedley: {
name: 'Fruit Medley',
test: function(cooker, names, tags) {
return tags.fruit && tags.fruit >= 3 && !tags.meat && !tags.veggie;
},
requirements: [TAG('fruit', COMPARE('>=', 3)), NOT(TAG('meat')), NOT(TAG('veggie'))],
priority: 0,
foodtype: "veggie",
health: healing_med,
hunger: calories_med,
perish: perish_fast,
sanity: sanity_tiny,
cooktime: 0.5
},
fishtacos: {
name: 'Fish Tacos',
test: function(cooker, names, tags) {
return tags.fish && (names.corn || names.corn_cooked);
},
requirements: [TAG('fish'), NAME('corn')],
priority: 10,
foodtype: "meat",
health: healing_med,
hunger: calories_large,
perish: perish_fast,
sanity: sanity_tiny,
cooktime: 0.5
},
waffles: {
name: 'Waffles',
test: function(cooker, names, tags) {
return names.butter && (names.berries || names.berries_cooked) && tags.egg;
},
requirements: [SPECIFIC('butter'), NAME('berries'), TAG('egg')],
priority: 10,
foodtype: "veggie",
health: healing_huge,
hunger: calories_large,
perish: perish_fast,
sanity: sanity_tiny,
cooktime: 0.5
},
monsterlasagna: {
name: 'Monster Lasagna',
test: function(cooker, names, tags) {
return tags.monster && tags.monster >= 2 && !tags.inedible;
},
requirements: [TAG('monster', COMPARE('>=', 2)), NOT(TAG('inedible'))],
priority: 10,
foodtype: "meat",
health: -healing_med,
hunger: calories_large,
perish: perish_fast,
sanity: -sanity_medlarge,
cooktime: 0.5
},
powcake: {
name: 'Powdercake',
test: function(cooker, names, tags) {
return names.twigs && names.honey && (names.corn || names.corn_cooked);
},
requirements: [SPECIFIC('twigs'), SPECIFIC('honey'), NAME('corn')],
priority: 10,
foodtype: "veggie",
health: -healing_small,
hunger: 0,
perishtime: 9000000,
sanity: 0,
cooktime: 0.5
},
wetgoop: {
name: 'Wet Goop',
test: function(cooker, names, tags) {
return true;
},
requirements: [],
trash: true,
priority: -2,
health: 0,
hunger: 0,
perish: perish_fast,
sanity: 0,
cooktime: 0.25
}
},
recipeCrunchData,
recipeCrunchString,
matchingNames = (function () {
var name,
tag,
tagsearch = /^tag[: ]/,
tagsplit = /^tag:? */,
recipe,
recipesearch = /^recipe[: ]/,
recipesplit = /^recipe:? */,
ingredient,
ingredientsearch = /^ingredient[: ]/,
ingredientsplit = /^ingredient:? */,
anywhere,
wordstarts,
allowUncookable = false,
filter = function (element) {
if (!allowUncookable && element.uncookable) {
element.match = 0;
} else if (element.lowerName.indexOf(name) === 0 || (element.raw && element.raw.lowerName.indexOf(name) === 0)) {
element.match = 3;
} else if (wordstarts.test(element.lowerName) === 0) {
element.match = 2;
} else if (anywhere.test(element.lowerName)) {
element.match = 1;
} else {
element.match = 0;
}
return element.match;
},
tagFilter = function (element) {
return element.match = element[tag] + 0 || 0;
},
recipeFilter = function (element) {
var i = 0, result, failed = true;
while (i < recipe.length) {
result = recipe[i].test(null, element.nameObject, element);
if (recipe[i].cancel) {
if (!result) {
failed = true;
break;
}
} else {
if (result) {
failed = false;
}
}
i++;
}
return element.match = failed ? 0 : 1;
},
ingredientFilter = function (recipe) {
var i = 0, result, failed = true;
while (i < recipe.requirements.length) {
result = recipe.requirements[i].test(null, ingredient.nameObject, ingredient);
if (recipe.requirements[i].cancel) {
if (!result) {
failed = true;
break;
}
} else {
if (result) {
failed = false;
}
}
i++;
}
return recipe.match = failed ? 0 : 1;
},
exact = function (element) {
return element.match = (element.lowerName === name) ? 1 : 0;
},
like = function (element) {
return element.match = (element.lowerName === name || (element.raw && element.raw.lowerName === name) || (element.cook && element.cook.lowerName === name)) ? 1 : 0;
},
byMatch = function (a, b) {
var aname, bname;
if (a.match === b.match) {
aname = a.raw ? a.raw.name : a.name;
bname = b.raw ? b.raw.name : b.name;
if (aname !== bname) {
return aname > bname ? 1 : aname < bname ? -1 : 0;
}
return a.name === b.name ? 0 : a.raw === b ? 1 : -1;
}
return b.match - a.match;
};
return function (arr, search, includeUncookable) {
allowUncookable = !!includeUncookable;
name = search.toLowerCase();
if (tagsearch.test(name)) {
tag = name.split(tagsplit)[1];
return arr.filter(tagFilter).sort(byMatch);
} else if (recipesearch.test(name)) {
recipe = recipes.byName(name.split(recipesplit)[1].toLowerCase());
if (recipe) {
recipe = recipe.requirements;
return arr.filter(recipeFilter).sort(byMatch);
} else {
return [];
}
} else if (ingredientsearch.test(name)) {
ingredient = food.byName(name.split(ingredientsplit)[1].toLowerCase());
if (ingredient) {
return arr.filter(ingredientFilter).sort(byMatch);
} else {
return [];
}
} else if (name.indexOf('*') === 0) {
name = name.substring(1);
return arr.filter(exact).sort(byMatch);
} else if (name.indexOf('~') === 0) {
name = name.substring(1);
return arr.filter(like).sort(byMatch);
} else {
wordstarts = new RegExp('\\b' + name + '.*');
anywhere = new RegExp('\\b' + name.split('').join('.*') + '.*');
return arr.filter(filter).sort(byMatch);
}
};
}()),
setIngredientValues = function (items, names, tags) {
var i, k, item;
for (i = 0; i < items.length; i++) {
item = items[i];
if (item !== null) {
names[item.id] = 1 + (names[item.id] || 0);
for (k in item) {
if (item.hasOwnProperty(k) && k !== 'perish' && !isNaN(item[k])) {
tags[k] = item[k] + (tags[k] || 0);
} else if (k === 'perish') {
tags[k] = Math.min(tags[k] || perish_preserved, item[k]);
}
}
}
}
},
getSuggestions = (function () {
var names,
tags;
return function (recipeList, items, exclude, itemComplete) {
var i, ii, valid;
recipeList.length = 0;
names = {};
tags = {};
setIngredientValues(items, names, tags);
for (i = 0; i < recipes.length; i++) {
valid = false;
for (ii = 0; ii < recipes[i].requirements.length; ii++) {
if (recipes[i].requirements[ii].test(null, names, tags)) {
if (!recipes[i].requirements[ii].cancel) {
valid = true;
}
} else if (!itemComplete && recipes[i].requirements[ii].cancel) {
valid = false;
break;
} else if (itemComplete && !recipes[i].requirements[ii].cancel) {
valid = false;
break;
}
}
valid && (!exclude || exclude.indexOf(recipes[i]) === -1) && recipeList.push(recipes[i]);
}
tags.img = '';
tags.name = 'Combined';
return recipeList;
};
}()),
getRecipes = (function () {
var recipeList = [],
names,
tags;
return function (items) {
var i;
recipeList.length = 0;
names = {};
tags = {};
setIngredientValues(items, names, tags);
for (i = 0; i < recipes.length; i++) {
recipes[i].test(null, names, tags) && recipeList.push(recipes[i]);
}
recipeList.sort(function (a, b) {
return b.priority - a.priority;
});
tags.img = '';
tags.name = 'Combined';
recipeList.unshift(tags);
return recipeList;
};
}()),
makeImage = (function () {
var canvas = document.createElement('canvas'),
ctx = canvas.getContext && canvas.toDataURL && canvas.getContext('2d'),
canvas32 = document.createElement('canvas'),
ctx32 = canvas32.getContext && canvas32.getContext('2d'),
images = {},
images32 = {},
canvasSupported = !!ctx,
requests = [],
cacheImage = function (url) {
var renderToCache = function (url, imageElement) {
ctx.clearRect(0, 0, 64, 64);
ctx.drawImage(imageElement, 0, 0, 64, 64);
ctx32.clearRect(0, 0, 32, 32);
ctx32.drawImage(imageElement, 0, 0, 32, 32);
try {
images[url] = canvas.toDataURL();
images32[url] = canvas32.toDataURL();
} catch (ex) {
canvasSupported = false;
}
requests.filter(function (request) { return request.url === url; }).forEach(function (request) {
if (request.url === url) {
delete request.img.dataset.pending;
if (noDataset) {
request.img.removeAttribute('data-pending');
}
if (request.d === 32) {
request.img.src = images32[url] || url;
} else {
request.img.src = images[url] || url;
}
}
});
requests = requests.filter(function (request) { return request.url !== url; });
};
return function (e) {
renderToCache(url, e.target);
}
},
queue = function (img, url, d) {
img.dataset.pending = url;
if (noDataset) {
img.setAttribute('data-pending', url);
}
requests.push({url: url, img: img, d: d});
},
makeImage = function (url, d) {
var img = new Image(), dummy, listener;
if (canvasSupported) {
if (images[url]) {
//image is cached
if (d === 32) {
img.src = images32[url];
} else {
img.src = images[url];
}
} else if (images[url] === null) {
//image is waiting to be loaded
queue(img, url, d);
} else {
//image has not been cached
images[url] = null;
dummy = new Image();
dummy.addEventListener('load', cacheImage(url), false);
dummy.src = url;
queue(img, url, d);
}
} else {
//if we can't cache the images with canvas, just do it normally
img.src = url;
}
return img;
};
canvas.width = 64;
canvas.height = 64;
canvas32.width = 32;
canvas32.height = 32;
makeImage.queue = queue;
return makeImage;
}()),
makeLinkable = (function () {
var linkSearch = /\[([^\|]*)\|([^\|\]]*)\|?([^\|\]]*)\]/,
leftSearch = /([^\|]\]\[[^\|]+\|[^\|\]]+)\|?([^\|\](?:left)]*)(?=\])/g,
rightSearch = /(\[[^\|]+\|[^\|\]]+)\|?([^\|\]]*)(?=\]\[)(?!\]\[\|)/g,
addLeftClass = function (a, b, c) { return b + '|' + (c.length === 0 ? 'left' : c + ' left'); },
addRightClass = function (a, b, c) { return b + '|' + (c.length === 0 ? 'right' : c + ' right'); },
titleCase = /_(\w)/g,
toTitleCase = function (a, b) { return ' ' + b.toUpperCase(); };
return function (str) {
var processed = str && str.replace(leftSearch, addLeftClass).replace(leftSearch, addLeftClass).replace(rightSearch, addRightClass),
results = processed && processed.split(linkSearch),
fragment, i, span, url, image;
if (!results || results.length === 1) {
return processed;
} else {
fragment = document.createDocumentFragment();
fragment.appendChild(document.createTextNode(results[0]));
for (i = 1; i < results.length; i += 4) {
if (results[i] === '' && results[i + 1] === '') {
fragment.appendChild(document.createElement('br'));
} else {
span = document.createElement('span');
span.className = results[i + 2] === '' ? 'link' : 'link ' + results[i + 2]; //IE doesn't support classList, too lazy to come up with a polyfill
span.dataset.link = results[i];
if (noDataset) {
span.setAttribute('data-link', results[i]);
}
if (results[i + 1] && results[i + 1].indexOf('img/') === 0) {
span.appendChild(document.createTextNode(results[i + 1].split(' ').slice(1).join(' ')));
url = results[i + 1].split(' ')[0];
image = makeImage(url, 32);
image.title = (url.substr(4, 1).toUpperCase() + url.substr(5).replace(titleCase, toTitleCase)).split('.')[0];
span.appendChild(image);
} else {
span.appendChild(document.createTextNode(results[i + 1] ? results[i + 1] : results[i]));
}
fragment.appendChild(span);
}
fragment.appendChild(document.createTextNode(results[i + 3]));
}
return fragment;
}
};
}()),
i,
index = 0,
mainElement = document.getElementById('main'),
foodElement = document.getElementById('food'),
recipesElement = document.getElementById('recipes'),
fragment, navbar = document.getElementById('navbar'),
noDataset = false;
if (!document.documentElement.dataset) {
noDataset = true;
Object.defineProperty(Element.prototype, 'dataset', {
get: function () {
if (!this.ds) {
this.ds = {};
Array.prototype.forEach.call(this.attributes, function (item) {
if (item.name.indexOf('data-') === 0) {
this.ds[item.name.substring(5)] = item.value;
}
}, this);
}
return this.ds;
}
});
}
//var info = [];
document.getElementById('stalehealth').appendChild(document.createTextNode(Math.round(stale_food_health * 1000) / 10 + '%'));
document.getElementById('stalehunger').appendChild(document.createTextNode(Math.round(stale_food_hunger * 1000) / 10 + '%'));
document.getElementById('spoiledhunger').appendChild(document.createTextNode(Math.round(spoiled_food_hunger * 1000) / 10 + '%'));
document.getElementById('spoiledsanity').appendChild(document.createTextNode(sanity_small));
document.getElementById('perishground').appendChild(document.createTextNode(Math.round(perish_ground_mult * 1000) / 10 + '%'));
document.getElementById('perishwinter').appendChild(document.createTextNode(Math.round(perish_winter_mult * 1000) / 10 + '%'));
document.getElementById('perishfridge').appendChild(document.createTextNode(Math.round(perish_fridge_mult * 1000) / 10 + '%'));
var info,
taggify = function (tag, name) { return '[tag:' + tag + '|' + (name || tag) + ']'; };
for (i in food) {
if (food.hasOwnProperty(i)) {
var f = food[i];
f.match = 0;
f.lowerName = f.name.toLowerCase();
f.id = i;
f.nameObject = {};
f.nameObject[i] = 1;
f.img = 'img/' + f.name.replace(/ /g, '_').toLowerCase() + '.png';
if (i.indexOf('_cooked') !== -1) {
f.cooked = true;
}
if (food[i + '_cooked']) {
f.cook = food[i + '_cooked'];
food[i + '_cooked'].raw = f;
}
f.info = [];
info = f.info;
f.fruit && info.push(taggify('fruit') + (f.fruit === 1 ? '' : '\xd7' + f.fruit));
f.veggie && info.push(taggify('veggie', 'vegetable') + (f.veggie === 1 ? '' : '\xd7' + f.veggie));
f.meat && info.push(taggify('meat') + (f.meat === 1 ? '' : '\xd7' + f.meat));
f.egg && info.push(taggify('egg') + (f.egg === 1 ? '' : '\xd7' + f.egg));
f.fish && info.push(taggify('fish'));
f.magic && info.push(taggify('magic'));
f.decoration && info.push(taggify('decoration'));
f.inedible && info.push(taggify('inedible'));
f.monster && info.push(taggify('monster', 'monster food'));
f.sweetener && info.push(taggify('sweetener'));
f.fat && info.push(taggify('fat'));
f.dairy && info.push(taggify('dairy'));
f.comment && info.push(f.comment);
food[index++] = f;
}
}
food.length = index;
index = 0;
for (i in recipes) {
if (recipes.hasOwnProperty(i)) {
recipes[i].match = 0;
recipes[i].name = recipes[i].name || i;
recipes[i].id = i;
recipes[i].lowerName = recipes[i].name.toLowerCase();
recipes[i].weight = recipes[i].weight || 1;
recipes[i].priority = recipes[i].priority || 0;
recipes[i].img = 'img/' + recipes[i].name.replace(/ /g, '_').toLowerCase() + '.png';
if (recipes[i].requirements) {
recipes[i].requires = makeLinkable(recipes[i].requirements.join('; '));
}
recipes[index++] = recipes[i];
}
}
recipes.length = index;
recipes.forEach = Array.prototype.forEach;
recipes.filter = Array.prototype.filter;
recipes.sort = Array.prototype.sort;
recipes.byName = function (name) {
var i = this.length;
while (i--) {
if (this[i].lowerName === name) {
return this[i];
}
}
};
var reduceRecipeButton = function (a, b) {
return a + '[recipe:' + b.name + '|' + b.img + ']';
};
var pl = function (str, n, plr) {
return n === 1 ? str : str + (plr || 's');
};
for (i in food) {
if (food.hasOwnProperty(i) && isNaN(i) && isNaN(food[i])) {
var f = food[i];
info = f.info;
f.cooked && info.push('from [*' + f.raw.name + '|' + f.raw.img + ']');
f.cook && info.push('cook: [*' + f.cook.name + '|' + f.cook.img + ']');
if (f.dry) {
if (!(f.dry instanceof Object)) {
f.dry = food[f.dry];
}
info.push('dry in ' + (f.drytime / total_day_time) + ' ' + pl('day', (f.drytime / total_day_time)) + ': [*' + f.dry.name + '|' + f.dry.img + ']');
}
f.info = info.join('; ');
if (!f.uncookable) {
f.recipes = [];
recipes.forEach(function (recipe) {
var qualifies = false, r = recipe.requirements, i = r.length;
while (i--) {
if (r[i].test(null, f.nameObject, f)) {
if (!r[i].cancel && !qualifies) {
qualifies = true;
}
} else {
if (r[i].cancel) {
qualifies = false;
break;
}
}
}
if (qualifies) {
f.recipes.push(recipe);
}
});
if (f.recipes.length > 0) {
f.ingredient = true;
f.info += (f.recipes.reduce(reduceRecipeButton, '[|][ingredient:' + f.name + '|Recipes] '));
}
} else {
f.info += ('[|]cannot be added to crock pot');
}
f.info = makeLinkable(f.info);
}
}
food.forEach = Array.prototype.forEach;
food.filter = Array.prototype.filter;
food.sort = Array.prototype.forEach;
food.byName = function (name) {
var i = this.length;
while (i--) {
if (this[i].lowerName === name) {
return this[i];
}
}
};
var usefulTags = ['id', 'health', 'hunger', 'fruit', 'veggie', 'meat', 'egg', 'fish', 'magic', 'decoration', 'inedible', 'monster', 'sweetener', 'fat', 'dairy'],
combinationGenerator = function (length, callback, startPos) {
var size = 4, index = 1, current = startPos || [0, 0, 0, 0], check, max = 0, iter = 0;
return function (batch) {
var overflow;
while (batch-- && index < length) {
callback(current);
current[0]++;
overflow = 0;
while (current[overflow] >= length) {
overflow++;
current[overflow]++;
}
check = size;
max = 0;
while (check--) {
if (current[check] >= length) {
current[check] = max;
} else if (current[check] > max) {
max = current[check];
}
}
if (overflow === size) {
return false;
break; //in case I copy and paste this for some reason and forget I need to get out of the loop
}
iter++;
}
return true;
};
};
recipeCrunchData = {};
recipeCrunchData.food = food.filter(function (item) {
return !item.uncookable && !item.skip && (item.ideal || (!item.cook && (!item.raw || !item.raw.ideal)));
}).map(function (item) {
var f = {}, t = usefulTags.length;
while (t--) {
if (item.hasOwnProperty(usefulTags[t])) {
f[usefulTags[t]] = item[usefulTags[t]];
}
}
return f;
});
recipeCrunchData.recipes = recipes.filter(function (item) {
return !item.trash;
}).sort(function (a, b) {
return b.priority - a.priority;
});
recipeCrunchData.test = recipeCrunchData.recipes.map(function (a) { return a.test; })
recipeCrunchData.tests = recipeCrunchData.recipes.map(function (a) { return a.test.toString(); })
recipeCrunchData.priority = recipeCrunchData.recipes.map(function (a) { return a.priority; });
var getRealRecipesFromCollection = function (items, mainCallback, chunkCallback, endCallback) {
var l = recipeCrunchData.test.length,
built = [],
renderedTo = 0,
lastTime,
block = 60,
desiredTime = 38,
foodFromIndex = function (index) {
return items[index];
},
callback = function (combination) {
var ingredients = combination.map(foodFromIndex), i, priority = null, names = {}, tags = {};
setIngredientValues(ingredients, names, tags);
for (var i = 0; i < l && (priority === null || recipeCrunchData.recipes[i].priority >= priority); i++) {
if (recipeCrunchData.test[i](null, names, tags)) {
built.push({ recipe: recipeCrunchData.recipes[i], ingredients: ingredients, tags: { health: tags.health, hunger: tags.hunger } });
priority = recipeCrunchData.recipes[i].priority;
}
}
},
getCombinations = combinationGenerator(items.length, callback),
computeNextBlock = function () {
var end = false,
start = Date.now();
if (getCombinations(block)) {
setTimeout(computeNextBlock, 0);
} else {
end = true;
}
for (; renderedTo < built.length && built[renderedTo]; renderedTo++) {
mainCallback(built[renderedTo]);
}
if (lastTime !== Date.now() - start) {
lastTime = Date.now() - start + 1;
block = desiredTime / lastTime * block + 1 | 0;
}
chunkCallback && chunkCallback();
end && endCallback && endCallback();
};
computeNextBlock();
};
//console.log(recipeCrunchData);
//delete recipeCrunchData.recipes;
//recipeCrunchString = JSON.stringify(recipeCrunchData); //recipeCrunch might also be used for multithreading later
//output.push('{| class="wikitable sortable"\n! width=145px |Name\n! width=40px |Health\n! width=50px |Food\n! width=60px |Perish\n|');
var setTab;
(function () {
var navtabs = navbar.getElementsByTagName('li'),
tabs = {},
elements = {},
storage,
activeIndex = 0,
activePage,
activeTab,
showTab = function (e) {
setTab(e.target.dataset.tab);
},
navtab;
setTab = function (tabID) {
activeTab.className = '';
activeTab = tabs[tabID];
activePage.style.display = 'none';
activePage = elements[tabID];
activeTab.className = 'selected';
activePage.style.display = 'block';
};
for (i = 0; i < navtabs.length; i++) {
navtab = navtabs[i];
if (navtab.dataset.tab) {
tabs[navtab.dataset.tab] = navtab;
elements[navtab.dataset.tab] = document.getElementById(navtab.dataset.tab);
elements[navtab.dataset.tab].style.display = 'none';
navtab.addEventListener('selectstart', function (e) { e.preventDefault(); }, false);
navtab.addEventListener('click', showTab, false);
}
}
activeTab = tabs['simulator'];
activePage = elements['simulator'];
if (window.localStorage && localStorage.foodGuideState) {
if (localStorage.foodGuideState[0] === '[') {
//converts from old format which causes errors
storage = {};
storage.pickers = JSON.parse(localStorage.foodGuideState);
localStorage.foodGuideState = JSON.stringify(storage);
} else {
storage = JSON.parse(localStorage.foodGuideState);
}
if (storage.activeTab && tabs[storage.activeTab]) {
activeTab = tabs[storage.activeTab];
activePage = elements[storage.activeTab];
}
}
activeTab.className = 'selected';
activePage.style.display = 'block';
window.addEventListener('beforeunload', function () {
var obj, serialized;
if (window.localStorage) {
if (!localStorage.foodGuideState) {
localStorage.foodGuideState = '{}';
}
obj = JSON.parse(localStorage.foodGuideState);
obj.activeTab = activeTab.dataset.tab;
localStorage.foodGuideState = JSON.stringify(obj);
}
});
}());
var queue = function (img) {
if (img.dataset.pending) {
makeImage.queue(img, img.dataset.pending, 32);
}
},
cells = function (cellType) {
var i, td, image, tr = document.createElement('tr'), cell, celltext;
for (i = 1; i < arguments.length; i++) {
td = document.createElement(cellType);
cell = arguments[i],
celltext = cell && cell.indexOf ? cell : cell.toString();
if (cell instanceof DocumentFragment) {
td.appendChild(cell.cloneNode(true));
Array.prototype.forEach.call(td.getElementsByTagName('img'), queue);
} else if (celltext.indexOf('img/') === 0) {
image = makeImage(celltext);
td.appendChild(image);
} else {
td.appendChild(document.createTextNode(celltext));
}
tr.appendChild(td);
}
return tr;
};
var makeSortableTable = function (headers, dataset, rowGenerator, defaultSort, hasSummary, linkCallback, highlightCallback, filterCallback, startRow, maxRows) {
var table, header, sorting, invertSort = false, firstHighlight, lastHighlight, rows,
generateAndHighlight = function (item, index, array) {
var row;
if ((!maxRows || rows < maxRows) && (!filterCallback || filterCallback(item))) {
row = rowGenerator(item);
if (highlightCallback && highlightCallback(item, array)) {
row.className = 'highlighted';
if (!firstHighlight) {
firstHighlight = row;
}
lastHighlight = row;
}
table.appendChild(row);
rows++;
}
},
create = function (e, sort, scrollHighlight) {
var tr, th, oldTable, sortBy, summary, links, i;
if (sort || (e && e.target.dataset.sort !== '') || sorting) {
sortBy = sort || (e && e.target.dataset.sort) || sorting;
if (hasSummary) {
summary = dataset.shift();
}
if (sortBy === 'name') {
dataset.sort(function (a, b) {
var aname = a.raw ? a.raw.name : a.name,
bname = b.raw ? b.raw.name : b.name;
if (aname !== bname) {
return aname > bname ? 1 : aname < bname ? -1 : 0;
}
return a.name === b.name ? 0 : a.raw === b ? 1 : -1;
});
} else {
dataset.sort(function (a, b) {
var sa = a[sortBy], sb = b[sortBy];
return !isNaN(sa) && !isNaN(sb) ? sb - sa : isNaN(sa) && isNaN(sb) ? 0 : isNaN(sa) ? 1 : -1;
});
}
if (sort || e) {
if (sorting === sortBy) {
invertSort = !invertSort;
} else {
sorting = sortBy;
invertSort = false;
}
}
if (invertSort) {
dataset.reverse();
}
if (hasSummary) {
dataset.unshift(summary);
}
}
tr = document.createElement('tr');
for (header in headers) {
th = document.createElement('th');
if (header.indexOf(':') === -1) {
th.appendChild(document.createTextNode(header));
} else {
th.appendChild(document.createTextNode(header.split(':')[0]));
th.title = header.split(':')[1];
}
if (headers[header]) {
if (headers[header] === sorting) {
th.style.background = invertSort ? '#555' : '#ccc';
th.style.color = invertSort ? '#ccc' : '#555';
th.style.borderRadius = '4px';
}
th.style.cursor = 'pointer';
th.dataset.sort = headers[header];
th.addEventListener('click', create, false);
}
tr.appendChild(th);
}
oldTable = table;
table = document.createElement('table');
table.appendChild(tr);
firstHighlight = null;
lastHighlight = null;
rows = 0;
dataset.forEach(generateAndHighlight);
if (linkCallback) {
table.className = 'links';
Array.prototype.forEach.call(table.getElementsByClassName('link'), function (element) {
element.addEventListener('click', linkCallback, false);
});
}
if (oldTable) {
oldTable.parentNode.replaceChild(table, oldTable);
}
if (scrollHighlight) {
if (firstHighlight && firstHighlight.offsetTop + table.offsetTop + mainElement.offsetTop + firstHighlight.offsetHeight > window.scrollY + window.innerHeight) {
firstHighlight.scrollIntoView(true);
} else if (lastHighlight && lastHighlight.offsetTop + table.offsetTop + mainElement.offsetTop < window.scrollY) {
lastHighlight.scrollIntoView(false);
}
}
};
if (defaultSort) {
create(null, defaultSort);
} else {
create();
}
table.update = function (scrollHighlight) {
create(null, null, scrollHighlight);
};
table.setMaxRows = function (max) {
maxRows = max;
this.update();
};
return table;
};
var sign = function (n) { return isNaN(n) ? '' : n > 0 ? '+' + n : n },
rawpct = function (base, val) {
return base < val ? (val - base) / Math.abs(base) : base > val ? -(base - val) / Math.abs(base) : 0;
},
pct = function (base, val) {
return !isNaN(base) && base !== val ? ' (' + sign(((base < val ? (val - base) / Math.abs(base) : base > val ? -(base - val) / Math.abs(base) : 0)*100).toFixed(0)) + '%)' : '';
};
var makeFoodRow = function (item) {
return cells('td', item.img ? item.img : '', item.name, sign(item.health), sign(item.hunger), isNaN(item.sanity) ? '' : sign(item.sanity), isNaN(item.perish) ? 'Never' : item.perish / total_day_time + ' ' + pl('day', item.perish / total_day_time), item.info || '');
};
var makeRecipeRow = function (item, health, hunger) {
return cells('td', item.img ? item.img : '', item.name, sign(item.health) + pct(health, item.health), sign(item.hunger) + pct(hunger, item.hunger), isNaN(item.sanity) ? '' : sign(item.sanity), isNaN(item.perish) ? 'Never' : item.perish / total_day_time + ' ' + pl('day', item.perish / total_day_time), (item.cooktime * base_cook_time + 0.5 | 0) + ' secs', item.priority || '0', item.requires || '');
};
(function () {
var foodHighlight,
foodHighlighted = [],
recipeHighlighted = [],
setFoodHighlight = function (e) {
var name = !e.target ? e : e.target.tagName === 'IMG' ? e.target.parentNode.dataset.link : e.target.dataset.link;
if (name.substring(0, 7) === 'recipe:' || name.substring(0, 11) === 'ingredient:') {
setTab('crockpot');
if (name.substring(0, 7) === 'recipe:') {
name = '*' + name.substring(7);
}
recipeHighlighted = matchingNames(recipes, name);
recipeTable.update(true);
} else {
if (foodHighlight !== name) {
foodHighlight = name;
foodHighlighted = matchingNames(food, name);
} else {
foodHighlight = '';
foodHighlighted.length = 0;
}
foodTable.update(true);
}
},
setRecipeHighlight = function (e) {
var name = !e.target ? e : e.target.tagName === 'IMG' ? e.target.parentNode.dataset.link : e.target.dataset.link;
setTab('foodlist');
foodHighlight = name;
foodHighlighted = matchingNames(food, name);
foodTable.update(true);
},
testFoodHighlight = function (item) {
return foodHighlighted.indexOf(item) !== -1;
},
testRecipeHighlight = function (item) {
return recipeHighlighted.indexOf(item) !== -1;
},
foodTable = makeSortableTable(
{'': '', 'Name': 'name', 'Health': 'health', 'Hunger': 'hunger', 'Sanity': 'sanity', 'Perish:Time to turn to rot': 'perish', 'Info': ''},
Array.prototype.slice.call(food),
makeFoodRow,
'name',
false,
setFoodHighlight,
testFoodHighlight
),
recipeTable = makeSortableTable(
{'': '', 'Name': 'name', 'Health': 'health', 'Hunger': 'hunger', 'Sanity': 'sanity', 'Perish:Time to turn to rot': 'perish', 'Cook Time': 'cooktime', 'Priority:One of the highest priority recipes for a combination will be made': 'priority', 'Requires:Dim, struck items cannot be used': ''},
Array.prototype.slice.call(recipes),
makeRecipeRow,
'name',
false,
setRecipeHighlight,
testRecipeHighlight
);
foodElement.appendChild(foodTable);
recipesElement.appendChild(recipeTable);
}());
var ingredientToIcon = function (a, b) {
return a + '[ingredient:' + food[b.id].name + '|' + food[b.id].img + ']';
},
makeRecipeGrinder = function (ingredients) {
var makableButton = document.createElement('button');
makableButton.appendChild(document.createTextNode('Calculate efficient recipes (may take some time)'));
makableButton.className = 'makablebutton';
makableButton.addEventListener('click', function () {
var idealIngredients = [],
i = ingredients ? ingredients.length : null,
selectedRecipe,
selectedRecipeElement,
addedRecipes = 0,
makableRecipes = [],
makableRecipe,
makableSummary,
splitCommaSpace = /, */,
makableFilter,
customFilter = null,
customFilterHolder,
customFilterInput,
usesIngredients = [],
excludesIngredients = [],
makableApply,
option,
made,
makableDiv,
makableTable,
checkExcludes = function (item) {
return excludesIngredients.indexOf(item.id) !== -1;
},
checkIngredient = function (item) {
return this.indexOf(food[item]) !== -1;
//return usesIngredients.indexOf(item.id) !== -1;
},
toggleFilter = function (e) {
if (excludesIngredients.indexOf(e.target.dataset.id) !== -1) {
excludesIngredients.splice(excludesIngredients.indexOf(e.target.dataset.id), 1);
}
if (usesIngredients.indexOf(e.target.dataset.id) !== -1) {
usesIngredients.splice(usesIngredients.indexOf(e.target.dataset.id), 1);
e.target.className = '';
} else {
usesIngredients.push(e.target.dataset.id);
e.target.className = 'selected';
}
makableTable.update();
},
toggleExclude = function (e) {
if (usesIngredients.indexOf(e.target.dataset.id) !== -1) {
usesIngredients.splice(usesIngredients.indexOf(e.target.dataset.id), 1);
}
if (excludesIngredients.indexOf(e.target.dataset.id) !== -1) {
excludesIngredients.splice(excludesIngredients.indexOf(e.target.dataset.id), 1);
e.target.className = '';
} else {
excludesIngredients.push(e.target.dataset.id);
e.target.className = 'excluded';
}
makableTable.update();
e.preventDefault();
},
setRecipe = function (e) {
if (selectedRecipeElement) {
selectedRecipeElement.className = '';
}
if (selectedRecipe === e.target.dataset.recipe) {
selectedRecipeElement = null;
selectedRecipe = null;
} else {
selectedRecipe = e.target.dataset.recipe;
selectedRecipeElement = e.target;
e.target.className = 'selected';
}
makableTable.update();
};
//TODO: optimize so much around this
if (i === null) {
i = food.length;
ingredients = food;
}
while (i--) {
if (ingredients[i].cook && idealIngredients.indexOf(ingredients[i].cook) === -1 && !ingredients[i].cook.uncookable) {
idealIngredients.push(ingredients[i].cook);
}
if (!ingredients[i].uncookable && (ingredients[i].ideal || !ingredients[i].cook || ingredients[i].cook.uncookable) && idealIngredients.indexOf(ingredients[i]) === -1) {
idealIngredients.push(ingredients[i]);
}
}
made = [];
makableTable = makeSortableTable(
{'': '', 'Name': 'name', 'Health': 'health', 'Health+:Health gained compared to ingredients': 'healthpls', 'Hunger': 'hunger', 'Hunger+:Hunger gained compared to ingredients': 'hungerpls', 'Ingredients': ''},
made,
function (data) {
var item = data.recipe,
health = data.tags.health,
hunger = data.tags.hunger;
return cells('td', item.img ? item.img : '', item.name, sign(item.health), sign(data.healthpls) + ' (' + sign((data.healthpct * 100) | 0) + '%)', sign(item.hunger), sign(data.hungerpls) + ' (' + sign((data.hungerpct * 100) | 0) + '%)',
makeLinkable(data.ingredients.reduce(ingredientToIcon, '')));
},
'hungerpls',
false,
null,
null,
function (data) {
return (!selectedRecipe || data.recipe.name === selectedRecipe) && (!excludesIngredients.length || !data.ingredients.some(checkExcludes)) && (!usesIngredients.length || usesIngredients.every(checkIngredient, data.ingredients));
},
0,
15
);
makableDiv = document.createElement('div');
makableSummary = document.createElement('div');
makableSummary.appendChild(document.createTextNode('Computing combinations..'));
makableDiv.appendChild(makableSummary);
makableRecipe = document.createElement('div');
makableRecipe.className = 'recipeFilter';
makableDiv.appendChild(makableRecipe);
makableFilter = document.createElement('div');
makableFilter.className = 'foodFilter';
idealIngredients.forEach(function (item) {
var img = makeImage(item.img, 32);
img.dataset.id = item.id;
img.addEventListener('click', toggleFilter, false);
img.addEventListener('contextmenu', toggleExclude, false);
img.title = item.name;
makableFilter.appendChild(img);
});
makableDiv.appendChild(makableFilter);
customFilterHolder = document.createElement('div');
customFilterInput = document.createElement('input');
customFilterInput.type = 'text';
customFilterInput.placeholder = 'use custom filter';
customFilterInput.className = 'customFilterInput';
customFilterHolder.appendChild(customFilterInput);
makableDiv.appendChild(makableTable);
makableButton.parentNode.replaceChild(makableDiv, makableButton);
getRealRecipesFromCollection(idealIngredients, function (data) { //row update
var i, img;
if (makableRecipes.indexOf(data.recipe.name) === -1) {
for (i = 0; i < makableRecipes.length; i++) {
if (data.recipe.name < makableRecipes[i]) {
break;
}
}
makableRecipes.splice(i, 0, data.recipe.name);
img = makeImage(recipes.byName(makableRecipes[i].toLowerCase()).img);
//TODO: optimize
img.dataset.recipe = makableRecipes[i];
img.addEventListener('click', setRecipe, false);
img.title = data.recipe.name;
if (i < makableRecipe.childNodes.length) {
makableRecipe.insertBefore(img, makableRecipe.childNodes[i]);
} else {
makableRecipe.appendChild(img);
}
}
if (!data.name) {
data.name = data.recipe.name;
data.health = data.recipe.health;
data.ihealth = data.tags.health;
data.healthpls = data.recipe.health - data.tags.health;
data.hunger = data.recipe.hunger;
data.ihunger = data.tags.hunger;
data.hungerpls = data.recipe.hunger - data.tags.hunger;
data.healthpct = rawpct(data.tags.health, data.recipe.health);
data.hungerpct = rawpct(data.tags.hunger, data.recipe.hunger);
data.sanity = data.recipe.sanity;
data.perish = data.recipe.perish;
}
made.push(data);
}, function () { //chunk update
/* this code provided updates to the table while the data was being crunched
var l = makableRecipes.length, img;
while (addedRecipes < l) {
img = makeImage(recipes.byName(makableRecipes[addedRecipes].toLowerCase()).img);
//TODO: optimize
img.dataset.recipe = makableRecipes[addedRecipes];
img.addEventListener('click', setRecipe, false);
makableRecipe.appendChild(img);
addedRecipes++;
makableRecipes.sort();
if (selectedRecipe !== makableRecipes[0]) {
selectedRecipe = makableRecipes[0];
selectedRecipeElement = makableRecipe.firstChild;
makableRecipe.firstChild.className = 'selected';
}
makableSummary.firstChild.textContent = 'Found ' + made.length + ' valid recipes..';
makableTable.update();
}*/
makableSummary.firstChild.textContent = 'Found ' + made.length + ' valid recipes..';
//makableTable.update();
}, function () { //computation finished
makableTable.setMaxRows(30);
makableSummary.firstChild.textContent = 'Found ' + made.length + ' valid recipes. Showing top 30 for selected recipe using all selected ingredients. Right-click to exclude ingredients.';
});
}, false);
return makableButton;
};
document.getElementById('statistics').appendChild(makeRecipeGrinder());
var highest = function (array, property) {
return array.reduce(function (previous, current) {
return Math.max(previous, current[property] || 0);
}, -100000);
};
window.food = food;
window.recipes = recipes;
window.matchingNames = matchingNames;
var setSlot = function (slotElement, item) {
var end = false;
if (item !== null) {
slotElement.dataset.id = item.id;
} else {
if (slotElement.nextSibling && getSlot(slotElement.nextSibling) !== null) {
setSlot(slotElement, getSlot(slotElement.nextSibling));
setSlot(slotElement.nextSibling, null);
end = true;
} else {
slotElement.dataset.id = null;
}
}
if (!end) {
if (item !== null) {
if (slotElement.firstChild) {
slotElement.replaceChild(makeImage(item.img), slotElement.firstChild);
} else {
slotElement.appendChild(makeImage(item.img));
}
} else {
if (slotElement.firstChild) {
slotElement.removeChild(slotElement.firstChild);
}
}
slotElement.title = item ? item.name : '';
}
},
getSlot = function (slotElement) {
return food[slotElement.dataset.id] || recipes[slotElement.dataset.id] || null;
};
(function () {
var pickers = document.getElementsByClassName('ingredientpicker'),
i = pickers.length;
while (i--) {
(function () {
var searchSelector = document.createElement('span'),
searchSelectorControls,
dropdown = document.createElement('div'),
ul = document.createElement('ul'),
picker = pickers[i],
index = i,
state,
from = picker.dataset.type === 'recipes' ? recipes : food,
allowUncookable = !picker.dataset.cookable,
parent = picker.nextSibling,
slots = parent.getElementsByClassName('ingredient'),
limited,
ingredients = [],
updateRecipes,
suggestions = [],
inventoryrecipes = [],
selected = null,
loaded = false,
results = document.getElementById('results'),
discoverfood = document.getElementById('discoverfood'),
discover = document.getElementById('discover'),
makable = document.getElementById('makable'),
clear = document.createElement('span'),
findPreviousMatching = function (el, test) {
var previous = el;
while (previous.previousSibling) {
previous = previous.previousSibling;
if (test(previous)) {
return previous;
}
}
return null;
},
findNextMatching = function (el, test) {
var next = el;
while (next.nextSibling) {
next = next.nextSibling;
if (test(next)) {
return next;
}
}
return null;
},
displaying = false,
appendSlot = function (id) {
var i, item = food[id] || recipes[id] || null;
if (limited) {
for (i = 0; i < slots.length; i++) {
if (getSlot(slots[i]) === null) {
setSlot(slots[i], item);
loaded && updateRecipes();
return i;
}
}
return -1;
} else {
if (slots.indexOf(id) === -1) {
slots.push(id);
i = document.createElement('span');
i.className = 'ingredient';
setSlot(i, item);
i.addEventListener('click', removeSlot, false);
parent.appendChild(i);
loaded && updateRecipes();
return 1;
}
return 1;
}
},
pickItem = function (e) {
var names,
target = e.target.tagName === 'IMG' ? e.target.parentNode : e.target,
result = appendSlot(target.dataset.id);
if (result !== -1) {
/*dropdown.removeChild(ul);
ul = document.createElement('div');
names = matchingNames(from, '', allowUncookable);
ul.dataset.length = 0;
names.forEach(liIntoPicker, ul);
dropdown.appendChild(ul);
if (ul.firstChild) {
ul.firstChild.className = 'selected';
}
picker.value = '';*/
/*if (result < slots.length - 1 || !limited) {
//picker.focus();
} else {
//picker.blur();
}*/
e && e.preventDefault && e.preventDefault();
//refreshLocation();
}
},
liIntoPicker = function (item) {
var img = makeImage(item.img, 32),
li = document.createElement('span');
li.appendChild(img);
li.appendChild(document.createTextNode(item.name));
li.dataset.id = item.id;
//li.dataset.tooltip = item.name;
if (ingredients.indexOf(item) !== -1) {
li.style.opacity = 0.5;
}
li.addEventListener('mousedown', pickItem, false);
this.appendChild(li);
this.dataset.length++;
/*if (this.dataset.length % 10 === 0) {
this.appendChild(document.createElement('br'));
}*/
},
updateFaded = function (el) {
if (ingredients.indexOf(food[el.dataset.id]) !== -1) {
if (!el.style.opacity) {
el.style.opacity = 0.5;
}
} else {
if (el.style.opacity) {
el.style.removeProperty('opacity');
}
}
},
removeSlot = function (e) {
var i, target = e.target.tagName === 'IMG' ? e.target.parentNode : e.target;
if (limited) {
if (getSlot(target) !== null) {
setSlot(target, null);
updateRecipes();
return target.dataset.id;
} else {
//picker.focus();
}
} else {
i = slots.indexOf(target.dataset.id);
slots.splice(i, 1);
parent.removeChild(target);
updateRecipes();
return slots[i] || null;
}
},
refreshLocation = function () {
/*if (mainElement.offsetLeft - dropdown.offsetWidth > 0) {
//to the left
dropdown.style.left = -dropdown.offsetWidth + 'px';
dropdown.style.top = picker.offsetTop + 'px';
} else if (mainElement.offsetLeft + picker.offsetLeft + picker.offsetWidth + dropdown.offsetWidth > window.innerWidth) {
//below
dropdown.style.left = picker.offsetLeft + 'px';
dropdown.style.top = picker.offsetTop + picker.offsetHeight + 'px';
} else {
//to the right
dropdown.style.left = picker.offsetLeft + picker.offsetWidth + 'px';
dropdown.style.top = picker.offsetTop + 'px';
}*/
},
refreshPicker = function () {
var names;
searchSelectorControls.splitTag();
names = matchingNames(from, searchSelectorControls.getSearch(), allowUncookable);
dropdown.removeChild(ul);
ul = document.createElement('div');
ul.dataset.length = 0;
names.forEach(liIntoPicker, ul);
dropdown.appendChild(ul);
//refreshLocation();
selected = null;
},
searchFor = function (e) {
var name = e.target.tagName === 'IMG' ? e.target.parentNode.dataset.link : e.target.dataset.link,
matches = matchingNames(from, name, allowUncookable);
if (matches.length === 1) {
appendSlot(matches[0].id);
} else {
picker.value = name;
refreshPicker();
//picker.focus();
}
},
coords;
if (parent.id === 'ingredients') {
//simulator
updateRecipes = function () {
var cooking,
health, hunger,
table;
ingredients = Array.prototype.map.call(slots, function (slot) {
return getSlot(slot);
});
cooking = getRecipes(ingredients);
health = cooking[0].health;
hunger = cooking[0].hunger;
table = makeSortableTable(
{'': '', 'Name': 'name', 'Health': 'health', 'Hunger': 'hunger', 'Sanity': 'sanity', 'Perish:Time to turn to rot': 'perish', 'Cook Time': 'cooktime', 'Priority:One of the highest priority recipes for a combination will be made': 'priority', 'Requires:Dim, struck items cannot be used': ''},
cooking,
function (item) {
return makeRecipeRow(item, health, hunger);
},
'priority',
true,
searchFor,
function (item, array) {
console.log(highest(array, 'priority'));
return array.length > 0 && item.priority === highest(array, 'priority');
}
);
if (results.firstChild) {
results.removeChild(results.firstChild);
}
if (results.firstChild) {
results.removeChild(results.firstChild);
results.removeChild(results.firstChild);
}
results.appendChild(table);
if (ingredients[0] !== null) {
getSuggestions(suggestions, ingredients, cooking);
if (suggestions.length > 0) {
results.appendChild(document.createTextNode('Add more ingredients to make:'));
table = makeSortableTable(
{'': '', 'Name': 'name', 'Health:(% more than ingredients)': 'health', 'Hunger:(% more than ingredients)': 'hunger', 'Sanity': 'sanity', 'Perish:Time to turn to rot': 'perish', 'Cook Time': 'cooktime', 'Priority:One of the highest priority recipes for a combination will be made': 'priority', 'Requires:Dim, struck items cannot be used': ''},
suggestions,
function (item) {
return makeRecipeRow(item, health, hunger);
},
'priority',
false,
searchFor
);
results.appendChild(table);
}
}
ul && ul.firstChild && Array.prototype.forEach.call(ul.getElementsByTagName('span'), updateFaded);
};
} else if (parent.id === 'inventory') {
//discovery
updateRecipes = function () {
var foodTable,
table;
ingredients = Array.prototype.map.call(parent.getElementsByClassName('ingredient'), function (slot) {
return getSlot(slot);
});
if (discoverfood.firstChild) {
discoverfood.removeChild(discoverfood.firstChild);
}
if (discover.firstChild) {
discover.removeChild(discover.firstChild);
}
if (makable.firstChild) {
makable.removeChild(makable.firstChild);
}
if (ingredients.length > 0) {
foodTable = makeSortableTable(
{'': '', 'Name': 'name', 'Health': 'health', 'Hunger': 'hunger', 'Sanity': 'sanity', 'Perish:Time to turn to rot': 'perish', 'Info': ''},
ingredients,
makeFoodRow,
'name'
);
discoverfood.appendChild(foodTable);
getSuggestions(inventoryrecipes, ingredients, null, true);
if (inventoryrecipes.length > 0) {
table = makeSortableTable(
{'': '', 'Name': 'name', 'Health': 'health', 'Hunger': 'hunger', 'Sanity': 'sanity', 'Perish:Time to turn to rot': 'perish', 'Cook Time': 'cooktime', 'Priority:One of the highest priority recipes for a combination will be made': 'priority', 'Requires:Dim, struck items cannot be used': ''},
inventoryrecipes,
makeRecipeRow,
'name'
)
discover.appendChild(table);
makable.appendChild(makeRecipeGrinder(ingredients));
}
}
ul && ul.firstChild && Array.prototype.forEach.call(ul.getElementsByTagName('span'), updateFaded);
};
}
if (slots.length !== 0) {
limited = true;
Array.prototype.forEach.call(slots, function (slot) {
setSlot(slot, null);
slot.addEventListener('click', removeSlot, false);
});
} else {
slots = [];
limited = false;
}
if (window.localStorage && localStorage.foodGuideState) {
state = JSON.parse(localStorage.foodGuideState).pickers;
if (state && state[index]) {
state[index].forEach(function (id) {
if (food[id]) {
appendSlot(id);
}
});
}
}
loaded = true;
searchSelector.className = 'searchselector retracted';
searchSelector.appendChild(document.createTextNode('name'));
searchSelectorControls = (function () {
var dropdown = document.createElement('div'),
extended = false,
extendedHeight = null,
searchTypes = [{title: 'name', prefix: '', placeholder: 'Filter ingredients'}, {title: 'tag', prefix: 'tag:', placeholder: 'Meat, veggie, fruit, egg, monster...'}, {title: 'recipe', prefix: 'recipe:', placeholder: 'Find ingredients used in a recipe'}],
selectedType = searchTypes[0],
retractTimer = null,
retract = function () {
extended = false;
dropdown.style.height = '0px';
searchSelector.style.borderBottomLeftRadius = '3px';
dropdown.style.borderTopLeftRadius = '3px';
if (retractTimer !== null) {
clearTimeout(retractTimer);
retractTimer = null;
}
searchSelector.className = 'searchselector retracted';
},
extend = function () {
if (extendedHeight === null) {
dropdown.style.height = 'auto';
dropdown.style.left = searchSelector.offsetLeft;
dropdown.style.top = searchSelector.offsetTop + searchSelector.offsetHeight;
extendedHeight = dropdown.offsetHeight + 'px';
dropdown.style.height = '0px';
}
extended = true;
dropdown.style.height = extendedHeight;
searchSelector.style.borderBottomLeftRadius = '0px';
dropdown.style.borderTopLeftRadius = '0px';
dropdown.style.width = 'auto';
dropdown.style.width = Math.max(dropdown.offsetWidth, searchSelector.offsetWidth + 1) + 'px';
if (retractTimer !== null) {
clearTimeout(retractTimer);
retractTimer = null;
}
searchSelector.className = 'searchselector extended';
},
setSearchType = function (searchType) {
selectedType = searchType;
picker.placeholder = selectedType.placeholder;
searchSelector.firstChild.textContent = selectedType.title;
},
setSearchTypeFromClick = function (e) {
setSearchType(searchTypes[e.target.dataset.typeIndex]);
refreshPicker();
retract();
},
tagsplit = /: */,
controls = {
getTag: function () {
return selectedType.title;
},
setSearchType: function (index) {
setSearchType(searchTypes[index]);
},
getSearch: function () {
return selectedType.prefix + picker.value;
},
splitTag: function () {
var i,
parts = picker.value.split(tagsplit),
tag,
name;
if (parts.length === 2) {
tag = parts[0].toLowerCase() + ':';
name = parts[1];
for (i = 0; i < searchTypes.length; i++) {
if (tag === searchTypes[i].prefix) {
setSearchType(searchTypes[i]);
picker.value = name;
break;
}
}
}
}
};
searchSelector.addEventListener('click', function () {
if (extended) {
retract();
} else {
extend();
}
}, false);
searchSelector.addEventListener('selectstart', function (e) { e.preventDefault(); }, false);
searchSelector.addEventListener('mouseout', function () {
if (retractTimer !== null) {
clearTimeout(retractTimer);
}
retractTimer = setTimeout(retract, 500);
}, false);
searchSelector.addEventListener('mouseover', function () {
if (retractTimer !== null) {
clearTimeout(retractTimer);
retractTimer = null;
}
}, false);
dropdown.addEventListener('mouseout', function () {
if (retractTimer !== null) {
clearTimeout(retractTimer);
}
retractTimer = setTimeout(retract, 500);
}, false);
dropdown.addEventListener('mouseover', function () {
if (retractTimer !== null) {
clearTimeout(retractTimer);
retractTimer = null;
}
}, false);
searchTypes.forEach(function (searchType, index) {
var element = document.createElement('div');
element.appendChild(document.createTextNode(searchType.title));
element.dataset.typeIndex = index;
element.addEventListener('click', setSearchTypeFromClick, false);
searchType.element = element;
dropdown.appendChild(element);
});
picker.parentNode.insertBefore(searchSelector, picker);
dropdown.className = 'searchdropdown';
picker.parentNode.insertBefore(dropdown, picker);
return controls;
}());
dropdown.className = 'ingredientdropdown';
dropdown.appendChild(ul);
dropdown.addEventListener('mousedown', function (e) { e.preventDefault(); }, false);
(function () {
var names = matchingNames(from, searchSelectorControls.getSearch(), allowUncookable);
dropdown.removeChild(ul);
ul = document.createElement('div');
ul.dataset.length = 0;
names.forEach(liIntoPicker, ul);
dropdown.appendChild(ul);
}());
clear.className = 'clearingredients';
clear.appendChild(document.createTextNode('clear'));
clear.addEventListener('click', function () {
if (picker.value === '' && searchSelectorControls.getTag() === 'name') {
while (getSlot(parent.firstChild)) {
removeSlot({ target: parent.firstChild });
}
} else {
picker.value = '';
searchSelectorControls.setSearchType(0);
refreshPicker();
}
}, false);
clear.addEventListener('mouseover', function () {
if (picker.value === '' && searchSelectorControls.getTag() === 'name') {
clear.firstChild.textContent = 'clear chosen ingredients';
}
}, false);
clear.addEventListener('mouseout', function () {
if (clear.firstChild.textContent !== 'clear') {
clear.firstChild.textContent = 'clear';
}
}, false);
parent.parentNode.insertBefore(clear, parent);
parent.parentNode.insertBefore(dropdown, parent);
picker.addEventListener('keydown', function (e) {
var movement = [16, 17, 37, 38, 39, 40, 13],
up = 38, left = 37, down = 40, right = 39, enter = 13, current, items, i, find;
if (movement.indexOf(e.keyCode) !== -1) {
current = selected;
if (e.keyCode === enter) {
if (selected === null) {
selected = ul.firstChild || null;
}
if (selected !== null) {
pickItem({target: selected});
}
} else {
if (selected === null) {
if (e.keyCode === down) {
selected = ul.childNodes[1] || ul.firstChild || null;
if (selected !== null) {
coords = (selected.offsetLeft + selected.offsetWidth / 2);
e.preventDefault();
}
}
} else {
e.preventDefault();
if (e.keyCode === left) {
if (selected.previousSibling && selected.previousSibling.offsetTop === selected.offsetTop) {
selected = selected.previousSibling;
} else {
find = findNextMatching(selected, function (el) {
//separate this out
return el.offsetTop !== selected.offsetTop;
});
if (find) {
selected = find.previousSibling;
} else {
selected = ul.lastChild;
}
}
if (selected !== null) {
coords = (selected.offsetLeft + selected.offsetWidth / 2);
}
} else if (e.keyCode === right) {
if (selected.nextSibling && selected.nextSibling.offsetTop === selected.offsetTop) {
selected = selected.nextSibling;
} else {
find = findPreviousMatching(selected, function (el) {
//separate this out
return el.offsetTop !== selected.offsetTop;
});
if (find) {
selected = find.nextSibling;
} else {
selected = ul.firstChild;
}
}
if (selected !== null) {
coords = (selected.offsetLeft + selected.offsetWidth / 2);
}
} else if (e.keyCode === up) {
find = findPreviousMatching(selected, function (el) {
return coords >= el.offsetLeft - 1 && coords <= el.offsetLeft + el.offsetWidth + 1;
});
if (!find) {
find = findPreviousMatching(ul.lastChild, function (el) {
return coords >= el.offsetLeft - 1 && coords <= el.offsetLeft + el.offsetWidth + 1;
});
}
if (find) {
selected = find;
} else {
selected = ul.firstChild;
}
} else if (e.keyCode === down) {
find = findNextMatching(selected, function (el) {
return coords >= el.offsetLeft - 1 && coords <= el.offsetLeft + el.offsetWidth + 1;
});
if (!find) {
find = findNextMatching(ul.firstChild, function (el) {
return coords >= el.offsetLeft - 1 && coords <= el.offsetLeft + el.offsetWidth + 1;
});
}
if (find) {
selected = find;
} else {
selected = ul.lastChild;
}
}
}
}
if (selected !== current) {
if (current !== null) {
current.className = '';
}
if (selected !== null) {
selected.className = 'selected';
}
}
}
}, false);
picker.addEventListener('keyup', function (e) {
var movement = [16, 17, 37, 38, 39, 40, 13],
up = 38, left = 37, down = 40, right = 39, enter = 13, current, items, i;
current = selected;
if (movement.indexOf(e.keyCode) === -1) {
refreshPicker();
} else if (selected !== null) {
e.preventDefault();
}
/*
using comments as version control is bad
else {
items = ul.getElementsByTagName('li');
for (i = 0; i < items.length; i++) {
if (items[i].className === 'selected') {
current = items[i];
if (e.keyCode === up || e.keyCode === down) {
items[i].className = '';
}
if (e.keyCode === up) {
items[i - 1 < 0 ? items.length - 1 : i - 1].className = 'selected';
} else if (e.keyCode === down) {
items[(i + 1) % items.length].className = 'selected';
} else if (e.keyCode === enter && current) {
pickItem({target: current});
refreshLocation();
}
break;
}
}
if (!current && items.length > 0) {
if (e.keyCode === up) {
items[items.length - 1].className = 'selected';
} else if (e.keyCode === down) {
items[0].className = 'selected';
} else if (e.keyCode === enter) {
pickItem({target: items[0]});
}
}
}*/
}, false);
picker.addEventListener('focus', function () {
if (!displaying) {
displaying = true;
//parent.appendChild(dropdown);
//refreshLocation();
}
}, false);
picker.addEventListener('blur', function () {
if (displaying) {
displaying = false;
//parent.removeChild(dropdown);
}
}, false);
updateRecipes();
window.addEventListener('beforeunload', function () {
var obj, serialized;
if (window.localStorage) {
if (!localStorage.foodGuideState) {
localStorage.foodGuideState = '{}';
}
obj = JSON.parse(localStorage.foodGuideState);
if (!obj.pickers) {
obj.pickers = [];
}
if (limited) {
serialized = [];
serialized = Array.prototype.map.call(slots, function (slot) {
var item = getSlot(slot);
return item ? item.id : null;
});
obj.pickers[index] = serialized;
} else {
obj.pickers[index] = slots;
}
localStorage.foodGuideState = JSON.stringify(obj);
}
});
}());
}
}())
}()); | JavaScript |
(function () {
'use strict';
var tests,
food,
priority,
compileTest = function (testString) {
if (testString[0] === '(') {
//if it's alredy wrapped, don't re-wrap it
return eval(testString);
}
return eval('(' + testString + ')');
},
isFunction = function (test) {
return test instanceof Function;
},
receiveTests = function (e) {
tests = e.data.tests.map(compileTest); //.filter(isFunction);
food = e.data.food;
priority = e.data.priority;
//tests should be sorted by priority; all top-priority recipes for a combination will be returned
self.postMessage({ state: 'ready' });
//if (tests.length !== e.data.tests.length) {
// self.postMessage({ error: 'Not all functions could be processed.' });
//}
self.onmessage = receiveData;
},
receiveData = function (e) {
var data = e.data,
item,
di,
dl = data.length;
i,
l = tests.length,
results = [];
results.length = tests.length;
for (di = 0; di < dl; di++) {
item = data[di];
for (i = 0; i < l; i++) {
tests[i].test
}
}
};
self.onmessage = receiveTests;
}()); | JavaScript |
/*
Makes use of no third-party code (for better or worse)
Copyright (c) 2013
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
(function () {
'use strict';
var calories_per_day = 75,
seg_time = 30,
total_day_time = seg_time * 16,
seg_time = total_day_time / 16,
day_segs = 10,
dusk_segs = 4,
night_segs = 2,
day_time = seg_time * day_segs,
dusk_time = seg_time * dusk_segs,
night_time = seg_time * night_segs,
perish_warp = 1,
stack_size_largeitem = 10,
stack_size_meditem = 20,
stack_size_smallitem = 40,
healing_tiny = 1,
healing_small = 3,
healing_medsmall = 8,
healing_med = 20,
healing_medlarge = 30,
healing_large = 40,
healing_huge = 60,
healing_superhuge = 100,
sanity_supertiny = 1,
sanity_tiny = 5,
sanity_small = 10,
sanity_med = 15,
sanity_medlarge = 20,
sanity_large = 33,
sanity_huge = 50,
perish_superfast = 3*total_day_time*perish_warp,
perish_fast = 6*total_day_time*perish_warp,
perish_med = 10*total_day_time*perish_warp,
perish_slow = 15*total_day_time*perish_warp,
perish_preserved = 20*total_day_time*perish_warp,
perish_superslow = 40*total_day_time*perish_warp,
dry_fast = total_day_time,
dry_med = 2*total_day_time,
calories_tiny = calories_per_day/8, // berries
calories_small = calories_per_day/6, // veggies
calories_medsmall = calories_per_day/4,
calories_med = calories_per_day/3, // meat
calories_large = calories_per_day/2, // cooked meat
calories_huge = calories_per_day, // crockpot foods?
calories_superhuge = calories_per_day*2, // crockpot foods?
spoiled_health = -1,
spoiled_hunger = -10,
perish_fridge_mult = .5,
perish_ground_mult = 1.5,
perish_global_mult = 1,
perish_winter_mult = .75,
stale_food_hunger = .667,
spoiled_food_hunger = .5,
stale_food_health = .333,
spoiled_food_health = 0,
base_cook_time = night_time*.3333,
tips = [
'Cooking meat '
],
Strings = {
'butter': 'Butter',
'butterflywings': 'Butterfly Wings',
'fish': 'Fish'
},
food = {
butter: {
name: Strings.butter,
fat: 1,
dairy: 1,
health: healing_large,
hunger: calories_med,
perish: perish_superslow,
stack: stack_size_smallitem
},
butterflywings: {
name: Strings.butterflywings,
isveggie: true,
decoration: 2,
health: healing_medsmall,
hunger: calories_tiny,
perish: perish_fast,
stack: stack_size_smallitem
},
deerclopseyeball: {
name: 'Deerclops Eyeball',
uncookable: true,
health: healing_huge,
hunger: calories_huge,
sanity: -sanity_med
},
bird_egg: {
name: 'Egg',
egg: 1,
health: 0,
hunger: calories_tiny,
sanity: 0,
perish: perish_med,
stack: stack_size_smallitem,
rot: 'rottenegg'
},
bird_egg_cooked: {
name: 'Cooked Egg',
egg: 1,
precook: 1,
health: 0,
hunger: calories_small,
sanity: 0,
perish: perish_fast,
stack: stack_size_smallitem
},
rottenegg: {
name: 'Rotten Egg',
uncookable: true,
health: spoiled_health,
hunger: spoiled_hunger,
stack: stack_size_smallitem
},
fish: {
name: Strings.fish,
ismeat: true,
meat: 0.5,
fish: 1,
health: healing_tiny,
hunger: calories_small,
perish: perish_superfast,
stack: stack_size_smallitem
},
fish_cooked: {
name: 'Cooked Fish',
ismeat: true,
meat: 0.5,
fish: 1,
precook: 1,
health: healing_tiny,
hunger: calories_small,
perish: perish_fast,
stack: stack_size_smallitem
},
froglegs: {
name: 'Frog Legs',
ismeat: true,
meat: 0.5,
health: 0,
hunger: calories_small,
perish: perish_fast,
sanity: -sanity_small,
stack: stack_size_smallitem
},
froglegs_cooked: {
name: 'Cooked Frog Legs',
ismeat: true,
meat: 0.5,
precook: 1,
health: healing_tiny,
hunger: calories_small,
perish: perish_med,
sanity: 0,
stack: stack_size_smallitem
},
flowerhat: {
name: 'Garland',
health: healing_small,
hunger: 0,
sanity: sanity_small,
perish: perish_fast,
stack: 1,
uncookable: true
},
hambat: {
name: 'Ham Bat',
health: -healing_medsmall,
hunger: calories_med,
sanity: -sanity_med,
perish: perish_med,
stack: 1,
uncookable: true
},
honey: {
name: 'Honey',
sweetener: true,
health: healing_small,
hunger: calories_tiny,
perish: perish_superslow,
stack: stack_size_smallitem
},
honeycomb: {
name: 'Honeycomb',
sweetener: true
},
lightbulb: {
name: 'Light Bulb',
health: healing_tiny,
hunger: 0,
perish: perish_fast,
stack: stack_size_smallitem,
uncookable: true
},
mandrake: {
name: 'Mandrake',
veggie: 1,
magic: 1,
health: healing_huge,
hunger: calories_huge,
stack: stack_size_smallitem
},
mandrake_cooked: {
name: 'Cooked Mandrake',
uncookable: true,
veggie: 1,
magic: 1,
precook: 1,
health: healing_superhuge,
hunger: calories_superhuge,
stack: stack_size_smallitem
},
plantmeat: {
name: 'Leafy Meat',
uncookable: true,
health: 0,
hunger: calories_small,
sanity: -sanity_small,
perish: perish_fast,
stack: stack_size_smallitem
},
plantmeat_cooked: {
name: 'Cooked Leafy Meat',
uncookable: true,
health: healing_tiny,
hunger: calories_medsmall,
sanity: 0,
perish: perish_med,
stack: stack_size_smallitem
},
monstermeat: {
name: 'Monster Meat',
ismeat: true,
meat: 1,
monster: true,
health: -healing_med,
hunger: calories_medsmall,
sanity: -sanity_med,
perish: perish_fast,
stack: stack_size_meditem,
dry: 'monstermeat_dried',
drytime: dry_fast
},
monstermeat_cooked: {
name: 'Cooked Monster Meat',
ismeat: true,
meat: 1,
monster: true,
precook: 1,
health: -healing_small,
hunger: calories_medsmall,
sanity: -sanity_small,
perish: perish_slow,
stack: stack_size_meditem
},
monstermeat_dried: {
name: 'Monster Jerky',
ismeat: true,
meat: 1,
monster: true,
dried: 1,
health: -healing_small,
hunger: calories_medsmall,
sanity: -sanity_tiny,
perish: perish_preserved,
stack: stack_size_meditem
},
meat: {
name: 'Meat',
ismeat: true,
meat: 1,
health: healing_tiny,
hunger: calories_med,
sanity: -sanity_small,
perish: perish_fast,
stack: stack_size_meditem,
dry: 'meat_dried',
drytime: dry_med
},
meat_cooked: {
name: 'Cooked Meat',
ismeat: true,
meat: 1,
precook: 1,
health: healing_small,
hunger: calories_med,
sanity: 0,
perish: perish_med,
stack: stack_size_meditem
},
meat_dried: {
name: 'Jerky',
ismeat: true,
meat: 1,
dried: 1,
health: healing_med,
hunger: calories_med,
sanity: sanity_med,
perish: perish_preserved,
stack: stack_size_meditem
},
morsel: {
name: 'Morsel',
ismeat: true,
meat: 0.5,
health: 0,
hunger: calories_small,
sanity: -sanity_small,
perish: perish_fast,
stack: stack_size_smallitem,
drytime: dry_fast,
dry: 'smallmeat_dried'
},
morsel_cooked: {
name: 'Cooked Morsel',
ismeat: true,
meat: 0.5,
precook: 1,
health: healing_tiny,
hunger: calories_small,
sanity: 0,
perish: perish_med,
stack: stack_size_smallitem
},
smallmeat_dried: {
name: 'Small Jerky',
ismeat: true,
meat: 0.5,
dried: 1,
health: healing_medsmall,
hunger: calories_small,
sanity: sanity_small,
perish: perish_preserved,
stack: stack_size_smallitem
},
drumstick: {
name: 'Drumstick',
ismeat: true,
ideal: true,
meat: 0.5,
health: 0,
hunger: calories_small,
sanity: -sanity_small,
perish: perish_fast,
stack: stack_size_meditem,
drytime: dry_fast,
dry: 'smallmeat_dried'
},
drumstick_cooked: {
name: 'Fried Drumstick',
ismeat: true,
meat: 0.5,
precook: 1,
health: healing_tiny,
hunger: calories_small,
perish: perish_med,
stack: stack_size_meditem
},
batwing: {
name: 'Batilisk Wing',
ismeat: true,
health: healing_small,
hunger: calories_small,
sanity: -sanity_small,
perish: perish_fast,
stack: stack_size_smallitem,
drytime: dry_med,
dry: 'smallmeat_dried',
uncookable: true
},
batwing_cooked: {
name: 'Cooked Batilisk Wing',
ismeat: true,
health: healing_medsmall,
hunger: calories_medsmall,
sanity: 0,
perish: perish_med,
uncookable: true
},
red_mushroom: {
name: 'Red Cap',
veggie: 0.5,
ideal: true,
health: -healing_med,
hunger: calories_small,
sanity: 0,
perish: perish_med,
stack: stack_size_smallitem
},
red_mushroom_cooked: {
name: 'Cooked Red Cap',
veggie: 0.5,
health: healing_tiny,
hunger: 0,
sanity: -sanity_small,
perish: perish_med,
stack: stack_size_smallitem
},
green_mushroom: {
name: 'Green Cap',
veggie: 0.5,
ideal: true,
health: 0,
hunger: calories_small,
sanity: -sanity_huge,
perish: perish_med,
stack: stack_size_smallitem
},
green_mushroom_cooked: {
name: 'Cooked Green Cap',
veggie: 0.5,
health: -healing_tiny,
hunger: 0,
sanity: sanity_med,
perish: perish_med,
stack: stack_size_smallitem
},
blue_mushroom: {
name: 'Blue Cap',
veggie: 0.5,
ideal: true,
health: healing_med,
hunger: calories_small,
sanity: -sanity_med,
perish: perish_med,
stack: stack_size_smallitem
},
blue_mushroom_cooked: {
name: 'Cooked Blue Cap',
veggie: 0.5,
health: -healing_small,
hunger: 0,
sanity: sanity_small,
perish: perish_med,
stack: stack_size_smallitem
},
petals: {
name: 'Petals',
uncookable: true,
health: healing_tiny,
hunger: 0,
sanity: -sanity_tiny / 2,
perish: perish_fast,
stack: stack_size_smallitem
},
petals_evil: {
name: 'Dark Petals',
uncookable: true,
health: 0,
hunger: 0,
sanity: -sanity_tiny,
perish: perish_fast,
stack: stack_size_smallitem
},
seeds: {
name: 'Seeds',
uncookable: true,
health: 0,
hunger: calories_tiny / 2,
perish: perish_superslow,
stack: stack_size_smallitem
},
seeds_cooked: {
name: 'Toasted Seeds',
uncookable: true,
health: healing_tiny,
hunger: calories_tiny / 2,
perish: perish_med,
stack: stack_size_smallitem
},
spoiled_food: {
name: 'Rot',
uncookable: true,
health: spoiled_health,
hunger: spoiled_hunger,
stack: stack_size_smallitem
},
tallbirdegg: {
name: 'Tallbird Egg',
egg: 4,
health: healing_small,
hunger: calories_med
},
tallbirdegg_cooked: {
name: 'Fried Tallbird Egg',
egg: 4,
precook: 1,
health: 0,
hunger: calories_large,
perish: perish_fast
},
trunk_summer: {
name: 'Koalefant Trunk',
uncookable: true,
ismeat: true,
health: healing_medlarge,
hunger: calories_large,
sanity: 0,
perish: perish_fast,
stack: stack_size_meditem
},
trunk_summer_cooked: {
name: 'Koalefant Trunk Steak',
uncookable: true,
ismeat: true,
health: healing_large,
hunger: calories_huge,
sanity: 0,
perish: perish_slow,
stack: stack_size_meditem
},
twigs: {
name: 'Twigs',
inedible: 1
},
cavebanana: {
name: 'Cave Banana',
isfruit: true,
fruit: 1,
health: healing_tiny,
hunger: calories_small,
sanity: 0,
perish: perish_med
},
cavebanana_cooked: {
name: 'Cooked Banana',
isfruit: true,
fruit: 1,
precook: 1,
health: healing_small,
hunger: calories_small,
sanity: 0,
perish: perish_fast
},
carrot: {
name: 'Carrot',
isveggie: true,
veggie: 1,
health: healing_tiny,
hunger: calories_small,
perish: perish_med,
sanity: 0,
stack: stack_size_smallitem
},
carrot_cooked: {
name: 'Roasted Carrot',
isveggie: true,
veggie: 1,
precook: 1,
health: healing_small,
hunger: calories_small,
perish: perish_fast,
sanity: 0,
stack: stack_size_smallitem
},
corn: {
name: 'Corn',
ideal: true,
isveggie: true,
veggie: 1,
health: healing_small,
hunger: calories_med,
perish: perish_med,
sanity: 0,
stack: stack_size_smallitem
},
corn_cooked: {
name: 'Popcorn',
isveggie: true,
veggie: 1,
precook: 1,
health: healing_small,
hunger: calories_small,
perish: perish_slow,
sanity: 0,
stack: stack_size_smallitem
},
pumpkin: {
name: 'Pumpkin',
isveggie: true,
veggie: 1,
health: healing_small,
hunger: calories_large,
perish: perish_med,
sanity: 0,
stack: stack_size_meditem
},
pumpkin_cooked: {
name: 'Hot Pumpkin',
isveggie: true,
veggie: 1,
precook: 1,
health: healing_medsmall,
hunger: calories_large,
perish: perish_fast,
sanity: 0,
stack: stack_size_meditem
},
eggplant: {
name: 'Eggplant',
isveggie: true,
veggie: 1,
health: healing_medsmall,
hunger: calories_med,
perish: perish_med,
sanity: 0,
stack: stack_size_meditem
},
eggplant_cooked: {
name: 'Braised Eggplant',
isveggie: true,
veggie: 1,
precook: 1,
health: healing_med,
hunger: calories_med,
perish: perish_fast,
sanity: 0,
stack: stack_size_meditem
},
durian: {
name: 'Durian',
isfruit: true,
monster: 1,
fruit: 1,
health: -healing_small,
hunger: calories_med,
perish: perish_med,
sanity: -sanity_tiny,
stack: stack_size_meditem
},
durian_cooked: {
name: 'Extra Smelly Durian',
isfruit: true,
monster: 1,
fruit: 1,
precook: 1,
health: 0,
hunger: calories_med,
perish: perish_fast,
sanity: -sanity_tiny,
stack: stack_size_meditem
},
pomegranate: {
name: 'Pomegranate',
isfruit: true,
fruit: 1,
health: healing_small,
hunger: calories_tiny,
perish: perish_fast,
sanity: 0,
stack: stack_size_smallitem
},
pomegranate_cooked: {
name: 'Sliced Pomegranate',
isfruit: true,
fruit: 1,
precook: 1,
health: healing_med,
hunger: calories_small,
perish: perish_superfast,
sanity: 0,
stack: stack_size_smallitem
},
dragonfruit: {
name: 'Dragon Fruit',
isfruit: true,
fruit: 1,
health: healing_small,
hunger: calories_tiny,
perish: perish_fast,
sanity: 0,
stack: stack_size_smallitem
},
dragonfruit_cooked: {
name: 'Prepared Dragon Fruit',
isfruit: true,
fruit: 1,
precook: 1,
health: healing_med,
hunger: calories_small,
perish: perish_superfast,
sanity: 0,
stack: stack_size_smallitem
},
berries: {
name: 'Berries',
isfruit: true,
fruit: 0.5,
health: 0,
hunger: calories_tiny,
perish: perish_fast,
sanity: 0,
stack: stack_size_smallitem
},
berries_cooked: {
name: 'Roasted Berries',
isfruit: true,
fruit: 0.5,
precook: 1,
health: healing_tiny,
hunger: calories_small,
perish: perish_superfast,
sanity: 0,
stack: stack_size_smallitem
}
},
//note: qty not used yet, this is for rapid summation
COMPAREString = function () { return this.op + this.qty; },
COMPARISONS = {
'=': function (qty) { return qty === this.qty; },
'>': function (qty) { return qty > this.qty; },
'<': function (qty) { return qty < this.qty; },
'>=': function (qty) { return qty >= this.qty; },
'<=': function (qty) { return qty <= this.qty; }
},
NOQTY = {test: function (qty) { return !!qty; }, toString: function () { return ''; }},
COMPARE = function (op, qty) { return {op: op, qty: qty, test: COMPARISONS[op], toString: COMPAREString}; },
ORTest = function (cooker, names, tags) { return this.item1.test(cooker, names, tags) || this.item2.test(cooker, names, tags); },
ORString = function () { return this.item1 + ' or ' + this.item2; },
OR = function (item1, item2) { return {item1: item1, item2: item2, test: ORTest, toString: ORString, cancel: item1.cancel || item2.cancel}; },
NOTTest = function (cooker, names, tags) { return !this.item.test(cooker, names, tags); },
NOTString = function () { return this.item.toString().substring(0, this.item.toString().length - 1) + '|strike]'; },
NOT = function (item) { return {item: item, test: NOTTest, toString: NOTString, cancel: true}; },
NAMETest = function (cooker, names, tags) { return (names[this.name] || 0) + (names[this.name + '_cooked'] || 0); },
NAMEString = function () { return '[*' + food[this.name].name + '|' + food[this.name].img + ' ' + food[this.name].name + ']' + (food[this.name].cook ? '[*' + food[this.name].cook.name + '|' + food[this.name].cook.img + ']' : '') + (food[this.name].raw ? '[*' + food[this.name].raw.name + '|' + food[this.name].raw.img + ']' : '') + (this.qty ? this.qty : ''); },
NAME = function (name, qty) { return {name: name, qty: qty || NOQTY, test: NAMETest, toString: NAMEString}; }, //permits cooked variant
SPECIFICTest = function (cooker, names, tags) { return names[this.name]; },
SPECIFICString = function () { return '[*' + food[this.name].name + '|' + food[this.name].img + ' ' + food[this.name].name + ']' + (this.qty ? this.qty : ''); },
SPECIFIC = function (name, qty) { return {name: name, qty: qty || NOQTY, test: SPECIFICTest, toString: SPECIFICString}; }, //disallows cooked/uncooked variant
TAGTest = function (cooker, names, tags) { return tags[this.tag]; },
TAGString = function () { return '[tag:' + this.tag + '|' + this.tag + ']' + (this.qty ? this.qty : ''); },
TAG = function (tag, qty) { return {tag: tag, qty: qty || NOQTY, test: TAGTest, toString: TAGString}; },
recipes = {
butterflymuffin: {
name: 'Butter Muffin',
test: function(cooker, names, tags) {
return names.butterflywings && !tags.meat && tags.veggie;
},
requires: 'Butterfly Wings, veggie',
requirements: [NAME('butterflywings'), NOT(TAG('meat')), TAG('veggie')],
priority: 1,
weight: 1,
foodtype: "veggie",
health: healing_med,
hunger: calories_large,
perish: perish_slow,
sanity: sanity_tiny,
cooktime: 2
},
frogglebunwich: {
name: 'Froggle Bunwich',
test: function(cooker, names, tags) {
return (names.froglegs || names.froglegs_cooked) && tags.veggie;
},
requirements: [NAME('froglegs'), TAG('veggie')],
priority: 1,
foodtype: "meat",
health: healing_med,
hunger: calories_large,
perish: perish_slow,
sanity: sanity_tiny,
cooktime: 2
},
taffy: {
name: "Taffy",
test: function(cooker, names, tags) {
return tags.sweetener && tags.sweetener >= 3 && !tags.meat;
},
requirements: [TAG('sweetener', COMPARE('>=', 3)), NOT(TAG('meat'))],
priority: 10,
foodtype: "veggie",
health: -healing_small,
hunger: calories_small * 2,
perish: perish_slow,
sanity: sanity_med,
cooktime: 2
},
pumpkincookie: {
name: "Pumpkin Cookie",
test: function(cooker, names, tags) {
return (names.pumpkin || names.pumpkin_cooked) && tags.sweetener && tags.sweetener >= 2;
},
requirements: [NAME('pumpkin'), TAG('sweetener', COMPARE('>=', 2))],
priority: 10,
foodtype: "veggie",
health: 0,
hunger: calories_large,
perish: perish_med,
sanity: sanity_med,
cooktime: 2
},
stuffedeggplant: {
name: 'Stuffed Eggplant',
test: function(cooker, names, tags) {
return (names.eggplant || names.eggplant_cooked) && tags.veggie && tags.veggie > 1;
},
requirements: [NAME('eggplant'), TAG('veggie', COMPARE('>', 1))],
priority: 1,
foodtype: "veggie",
health: healing_small,
hunger: calories_large,
perish: perish_slow,
sanity: sanity_tiny,
cooktime: 2
},
fishsticks: {
name: 'Fishsticks',
test: function(cooker, names, tags) {
return tags.fish && names.twigs && (tags.inedible && tags.inedible <= 1);
},
requirements: [TAG('fish'), SPECIFIC('twigs'), TAG('inedible'), TAG('inedible', COMPARE('<=', 1))],
priority: 10,
foodtype: "meat",
health: healing_large,
hunger: calories_large,
perish: perish_med,
sanity: sanity_tiny,
cooktime: 2
},
honeynuggets: {
name: 'Honey Nuggets',
test: function(cooker, names, tags) {
return names.honey && tags.meat && tags.meat <= 1.5 && !tags.inedible;
},
requirements: [SPECIFIC('honey'), TAG('meat', COMPARE('<=', 1.5)), NOT(TAG('inedible'))],
priority: 2,
foodtype: "meat",
health: healing_med,
hunger: calories_large,
perish: perish_slow,
sanity: sanity_tiny,
cooktime: 2
},
honeyham: {
name: 'Honey Ham',
test: function(cooker, names, tags) {
return names.honey && tags.meat && tags.meat > 1.5 && !tags.inedible;
},
requirements: [SPECIFIC('honey'), TAG('meat', COMPARE('>', 1.5)), NOT(TAG('inedible'))],
priority: 2,
foodtype: "meat",
health: healing_medlarge,
hunger: calories_huge,
perish: perish_slow,
sanity: sanity_tiny,
cooktime: 2
},
dragonpie: {
name: 'Dragonpie',
test: function(cooker, names, tags) {
return (names.dragonfruit || names.dragonfruit_cooked) && !tags.meat;
},
requirements: [NAME('dragonfruit'), NOT(TAG('meat'))],
priority: 1,
foodtype: "veggie",
health: healing_large,
hunger: calories_huge,
perish: perish_slow,
sanity: sanity_tiny,
cooktime: 2
},
kabobs: {
name: 'Kabobs',
test: function(cooker, names, tags) {
return tags.meat && names.twigs && (!tags.monster || tags.monster <= 1) && (tags.inedible && tags.inedible <= 1);
},
requirements: [TAG('meat'), SPECIFIC('twigs'), OR(NOT(TAG('monster')), TAG('monster', COMPARE('<=', 1))), TAG('inedible'), TAG('inedible', COMPARE('<=', 1))],
priority: 5,
foodtype: "meat",
health: healing_small,
hunger: calories_large,
perish: perish_slow,
sanity: sanity_tiny,
cooktime: 2
},
mandrakesoup: {
name: 'Mandrake Soup',
test: function(cooker, names, tags) {
return names.mandrake;
},
requirements: [SPECIFIC('mandrake')],
priority: 10,
foodtype: "veggie",
health: healing_superhuge,
hunger: calories_superhuge,
perish: perish_fast,
sanity: sanity_tiny,
cooktime: 3
},
baconeggs: {
name: 'Bacon and Eggs',
test: function(cooker, names, tags) {
return tags.egg && tags.egg > 1 && tags.meat && tags.meat > 1 && !tags.veggie;
},
requirements: [TAG('egg', COMPARE('>', 1)), TAG('meat', COMPARE('>', 1)), NOT(TAG('veggie'))],
priority: 10,
foodtype: "meat",
health: healing_med,
hunger: calories_huge,
perish: perish_preserved,
sanity: sanity_tiny,
cooktime: 2
},
meatballs: {
name: 'Meatballs',
test: function(cooker, names, tags) {
return tags.meat && !tags.inedible;
},
requirements: [TAG('meat'), NOT(TAG('inedible'))],
priority: -1,
foodtype: "meat",
health: healing_small,
hunger: calories_small * 5,
perish: perish_med,
sanity: sanity_tiny,
cooktime: 0.75
},
bonestew: {
name: 'Meaty Stew',
test: function(cooker, names, tags) {
return tags.meat && tags.meat >= 3 && !tags.inedible;
},
requirements: [TAG('meat', COMPARE('>=', 3)), NOT(TAG('inedible'))],
priority: 0,
foodtype: "meat",
health: healing_small * 4,
hunger: calories_large * 4,
perish: perish_med,
sanity: sanity_tiny,
cooktime: 0.75
},
perogies: {
name: 'Pierogi',
test: function(cooker, names, tags) {
return tags.egg && tags.meat && tags.veggie && !tags.inedible;
},
requirements: [TAG('egg'), TAG('meat'), TAG('veggie'), NOT(TAG('inedible'))],
priority: 5,
foodtype: "meat",
health: healing_large,
hunger: calories_large,
perish: perish_preserved,
sanity: sanity_tiny,
cooktime: 1
},
turkeydinner: {
name: 'Turkey Dinner',
test: function(cooker, names, tags) {
return names.drumstick && names.drumstick > 1 && tags.meat && tags.meat > 1 && (tags.veggie || tags.fruit);
},
requirements: [SPECIFIC('drumstick', COMPARE('>', 1)), TAG('meat', COMPARE('>', 1)), OR(TAG('veggie'), TAG('fruit'))],
priority: 10,
foodtype: "meat",
health: healing_med,
hunger: calories_huge,
perish: perish_fast,
sanity: sanity_tiny,
cooktime: 3
},
ratatouille: {
name: 'Ratatouille',
test: function(cooker, names, tags) {
return !tags.meat && tags.veggie && !tags.inedible;
},
requirements: [NOT(TAG('meat')), TAG('veggie'), NOT(TAG('inedible'))],
priority: 0,
foodtype: "veggie",
health: healing_small,
hunger: calories_med,
perish: perish_slow,
sanity: sanity_tiny,
cooktime: 1
},
jammypreserves: {
name: 'Fist Full of Jam',
test: function(cooker, names, tags) {
return tags.fruit && !tags.meat && !tags.veggie && !tags.inedible;
},
requirements: [TAG('fruit'), NOT(TAG('meat')), NOT(TAG('veggie')), NOT(TAG('inedible'))],
priority: 0,
foodtype: "veggie",
health: healing_small,
hunger: calories_small * 3,
perish: perish_slow,
sanity: sanity_tiny,
cooktime: 0.5
},
fruitmedley: {
name: 'Fruit Medley',
test: function(cooker, names, tags) {
return tags.fruit && tags.fruit >= 3 && !tags.meat && !tags.veggie;
},
requirements: [TAG('fruit', COMPARE('>=', 3)), NOT(TAG('meat')), NOT(TAG('veggie'))],
priority: 0,
foodtype: "veggie",
health: healing_med,
hunger: calories_med,
perish: perish_fast,
sanity: sanity_tiny,
cooktime: 0.5
},
fishtacos: {
name: 'Fish Tacos',
test: function(cooker, names, tags) {
return tags.fish && (names.corn || names.corn_cooked);
},
requirements: [TAG('fish'), NAME('corn')],
priority: 10,
foodtype: "meat",
health: healing_med,
hunger: calories_large,
perish: perish_fast,
sanity: sanity_tiny,
cooktime: 0.5
},
waffles: {
name: 'Waffles',
test: function(cooker, names, tags) {
return names.butter && (names.berries || names.berries_cooked) && tags.egg;
},
requirements: [SPECIFIC('butter'), NAME('berries'), TAG('egg')],
priority: 10,
foodtype: "veggie",
health: healing_huge,
hunger: calories_large,
perish: perish_fast,
sanity: sanity_tiny,
cooktime: 0.5
},
monsterlasagna: {
name: 'Monster Lasagna',
test: function(cooker, names, tags) {
return tags.monster && tags.monster >= 2 && !tags.inedible;
},
requirements: [TAG('monster', COMPARE('>=', 2)), NOT(TAG('inedible'))],
priority: 10,
foodtype: "meat",
health: -healing_med,
hunger: calories_large,
perish: perish_fast,
sanity: -sanity_medlarge,
cooktime: 0.5
},
powcake: {
name: 'Powdercake',
test: function(cooker, names, tags) {
return names.twigs && names.honey && (names.corn || names.corn_cooked);
},
requirements: [SPECIFIC('twigs'), SPECIFIC('honey'), NAME('corn')],
priority: 10,
foodtype: "veggie",
health: -healing_small,
hunger: 0,
perishtime: 9000000,
sanity: 0,
cooktime: 0.5
},
wetgoop: {
name: 'Wet Goop',
test: function(cooker, names, tags) {
return true;
},
requirements: [],
trash: true,
priority: -2,
health: 0,
hunger: 0,
perish: perish_fast,
sanity: 0,
cooktime: 0.25
}
},
recipeCrunchData,
recipeCrunchString,
matchingNames = (function () {
var name,
tag,
tagsearch = /^tag[: ]/,
tagsplit = /^tag:? */,
recipe,
recipesearch = /^recipe[: ]/,
recipesplit = /^recipe:? */,
ingredient,
ingredientsearch = /^ingredient[: ]/,
ingredientsplit = /^ingredient:? */,
anywhere,
wordstarts,
allowUncookable = false,
filter = function (element) {
if (!allowUncookable && element.uncookable) {
element.match = 0;
} else if (element.lowerName.indexOf(name) === 0 || (element.raw && element.raw.lowerName.indexOf(name) === 0)) {
element.match = 3;
} else if (wordstarts.test(element.lowerName) === 0) {
element.match = 2;
} else if (anywhere.test(element.lowerName)) {
element.match = 1;
} else {
element.match = 0;
}
return element.match;
},
tagFilter = function (element) {
return element.match = element[tag] + 0 || 0;
},
recipeFilter = function (element) {
var i = 0, result, failed = true;
while (i < recipe.length) {
result = recipe[i].test(null, element.nameObject, element);
if (recipe[i].cancel) {
if (!result) {
failed = true;
break;
}
} else {
if (result) {
failed = false;
}
}
i++;
}
return element.match = failed ? 0 : 1;
},
ingredientFilter = function (recipe) {
var i = 0, result, failed = true;
while (i < recipe.requirements.length) {
result = recipe.requirements[i].test(null, ingredient.nameObject, ingredient);
if (recipe.requirements[i].cancel) {
if (!result) {
failed = true;
break;
}
} else {
if (result) {
failed = false;
}
}
i++;
}
return recipe.match = failed ? 0 : 1;
},
exact = function (element) {
return element.match = (element.lowerName === name) ? 1 : 0;
},
like = function (element) {
return element.match = (element.lowerName === name || (element.raw && element.raw.lowerName === name) || (element.cook && element.cook.lowerName === name)) ? 1 : 0;
},
byMatch = function (a, b) {
var aname, bname;
if (a.match === b.match) {
aname = a.raw ? a.raw.name : a.name;
bname = b.raw ? b.raw.name : b.name;
if (aname !== bname) {
return aname > bname ? 1 : aname < bname ? -1 : 0;
}
return a.name === b.name ? 0 : a.raw === b ? 1 : -1;
}
return b.match - a.match;
};
return function (arr, search, includeUncookable) {
allowUncookable = !!includeUncookable;
name = search.toLowerCase();
if (tagsearch.test(name)) {
tag = name.split(tagsplit)[1];
return arr.filter(tagFilter).sort(byMatch);
} else if (recipesearch.test(name)) {
recipe = recipes.byName(name.split(recipesplit)[1].toLowerCase());
if (recipe) {
recipe = recipe.requirements;
return arr.filter(recipeFilter).sort(byMatch);
} else {
return [];
}
} else if (ingredientsearch.test(name)) {
ingredient = food.byName(name.split(ingredientsplit)[1].toLowerCase());
if (ingredient) {
return arr.filter(ingredientFilter).sort(byMatch);
} else {
return [];
}
} else if (name.indexOf('*') === 0) {
name = name.substring(1);
return arr.filter(exact).sort(byMatch);
} else if (name.indexOf('~') === 0) {
name = name.substring(1);
return arr.filter(like).sort(byMatch);
} else {
wordstarts = new RegExp('\\b' + name + '.*');
anywhere = new RegExp('\\b' + name.split('').join('.*') + '.*');
return arr.filter(filter).sort(byMatch);
}
};
}()),
setIngredientValues = function (items, names, tags) {
var i, k, item;
for (i = 0; i < items.length; i++) {
item = items[i];
if (item !== null) {
names[item.id] = 1 + (names[item.id] || 0);
for (k in item) {
if (item.hasOwnProperty(k) && k !== 'perish' && !isNaN(item[k])) {
tags[k] = item[k] + (tags[k] || 0);
} else if (k === 'perish') {
tags[k] = Math.min(tags[k] || perish_preserved, item[k]);
}
}
}
}
},
getSuggestions = (function () {
var names,
tags;
return function (recipeList, items, exclude, itemComplete) {
var i, ii, valid;
recipeList.length = 0;
names = {};
tags = {};
setIngredientValues(items, names, tags);
for (i = 0; i < recipes.length; i++) {
valid = false;
for (ii = 0; ii < recipes[i].requirements.length; ii++) {
if (recipes[i].requirements[ii].test(null, names, tags)) {
if (!recipes[i].requirements[ii].cancel) {
valid = true;
}
} else if (!itemComplete && recipes[i].requirements[ii].cancel) {
valid = false;
break;
} else if (itemComplete && !recipes[i].requirements[ii].cancel) {
valid = false;
break;
}
}
valid && (!exclude || exclude.indexOf(recipes[i]) === -1) && recipeList.push(recipes[i]);
}
tags.img = '';
tags.name = 'Combined';
return recipeList;
};
}()),
getRecipes = (function () {
var recipeList = [],
names,
tags;
return function (items) {
var i;
recipeList.length = 0;
names = {};
tags = {};
setIngredientValues(items, names, tags);
for (i = 0; i < recipes.length; i++) {
recipes[i].test(null, names, tags) && recipeList.push(recipes[i]);
}
recipeList.sort(function (a, b) {
return b.priority - a.priority;
});
tags.img = '';
tags.name = 'Combined';
recipeList.unshift(tags);
return recipeList;
};
}()),
makeImage = (function () {
var canvas = document.createElement('canvas'),
ctx = canvas.getContext && canvas.toDataURL && canvas.getContext('2d'),
canvas32 = document.createElement('canvas'),
ctx32 = canvas32.getContext && canvas32.getContext('2d'),
images = {},
images32 = {},
canvasSupported = !!ctx,
requests = [],
cacheImage = function (url) {
var renderToCache = function (url, imageElement) {
ctx.clearRect(0, 0, 64, 64);
ctx.drawImage(imageElement, 0, 0, 64, 64);
ctx32.clearRect(0, 0, 32, 32);
ctx32.drawImage(imageElement, 0, 0, 32, 32);
try {
images[url] = canvas.toDataURL();
images32[url] = canvas32.toDataURL();
} catch (ex) {
canvasSupported = false;
}
requests.filter(function (request) { return request.url === url; }).forEach(function (request) {
if (request.url === url) {
delete request.img.dataset.pending;
if (noDataset) {
request.img.removeAttribute('data-pending');
}
if (request.d === 32) {
request.img.src = images32[url] || url;
} else {
request.img.src = images[url] || url;
}
}
});
requests = requests.filter(function (request) { return request.url !== url; });
};
return function (e) {
renderToCache(url, e.target);
}
},
queue = function (img, url, d) {
img.dataset.pending = url;
if (noDataset) {
img.setAttribute('data-pending', url);
}
requests.push({url: url, img: img, d: d});
},
makeImage = function (url, d) {
var img = new Image(), dummy, listener;
if (canvasSupported) {
if (images[url]) {
//image is cached
if (d === 32) {
img.src = images32[url];
} else {
img.src = images[url];
}
} else if (images[url] === null) {
//image is waiting to be loaded
queue(img, url, d);
} else {
//image has not been cached
images[url] = null;
dummy = new Image();
dummy.addEventListener('load', cacheImage(url), false);
dummy.src = url;
queue(img, url, d);
}
} else {
//if we can't cache the images with canvas, just do it normally
img.src = url;
}
return img;
};
canvas.width = 64;
canvas.height = 64;
canvas32.width = 32;
canvas32.height = 32;
makeImage.queue = queue;
return makeImage;
}()),
makeLinkable = (function () {
var linkSearch = /\[([^\|]*)\|([^\|\]]*)\|?([^\|\]]*)\]/,
leftSearch = /([^\|]\]\[[^\|]+\|[^\|\]]+)\|?([^\|\](?:left)]*)(?=\])/g,
rightSearch = /(\[[^\|]+\|[^\|\]]+)\|?([^\|\]]*)(?=\]\[)(?!\]\[\|)/g,
addLeftClass = function (a, b, c) { return b + '|' + (c.length === 0 ? 'left' : c + ' left'); },
addRightClass = function (a, b, c) { return b + '|' + (c.length === 0 ? 'right' : c + ' right'); },
titleCase = /_(\w)/g,
toTitleCase = function (a, b) { return ' ' + b.toUpperCase(); };
return function (str) {
var processed = str && str.replace(leftSearch, addLeftClass).replace(leftSearch, addLeftClass).replace(rightSearch, addRightClass),
results = processed && processed.split(linkSearch),
fragment, i, span, url, image;
if (!results || results.length === 1) {
return processed;
} else {
fragment = document.createDocumentFragment();
fragment.appendChild(document.createTextNode(results[0]));
for (i = 1; i < results.length; i += 4) {
if (results[i] === '' && results[i + 1] === '') {
fragment.appendChild(document.createElement('br'));
} else {
span = document.createElement('span');
span.className = results[i + 2] === '' ? 'link' : 'link ' + results[i + 2]; //IE doesn't support classList, too lazy to come up with a polyfill
span.dataset.link = results[i];
if (noDataset) {
span.setAttribute('data-link', results[i]);
}
if (results[i + 1] && results[i + 1].indexOf('img/') === 0) {
span.appendChild(document.createTextNode(results[i + 1].split(' ').slice(1).join(' ')));
url = results[i + 1].split(' ')[0];
image = makeImage(url, 32);
image.title = (url.substr(4, 1).toUpperCase() + url.substr(5).replace(titleCase, toTitleCase)).split('.')[0];
span.appendChild(image);
} else {
span.appendChild(document.createTextNode(results[i + 1] ? results[i + 1] : results[i]));
}
fragment.appendChild(span);
}
fragment.appendChild(document.createTextNode(results[i + 3]));
}
return fragment;
}
};
}()),
i,
index = 0,
mainElement = document.getElementById('main'),
foodElement = document.getElementById('food'),
recipesElement = document.getElementById('recipes'),
fragment, navbar = document.getElementById('navbar'),
noDataset = false;
if (!document.documentElement.dataset) {
noDataset = true;
Object.defineProperty(Element.prototype, 'dataset', {
get: function () {
if (!this.ds) {
this.ds = {};
Array.prototype.forEach.call(this.attributes, function (item) {
if (item.name.indexOf('data-') === 0) {
this.ds[item.name.substring(5)] = item.value;
}
}, this);
}
return this.ds;
}
});
}
//var info = [];
document.getElementById('stalehealth').appendChild(document.createTextNode(Math.round(stale_food_health * 1000) / 10 + '%'));
document.getElementById('stalehunger').appendChild(document.createTextNode(Math.round(stale_food_hunger * 1000) / 10 + '%'));
document.getElementById('spoiledhunger').appendChild(document.createTextNode(Math.round(spoiled_food_hunger * 1000) / 10 + '%'));
document.getElementById('spoiledsanity').appendChild(document.createTextNode(sanity_small));
document.getElementById('perishground').appendChild(document.createTextNode(Math.round(perish_ground_mult * 1000) / 10 + '%'));
document.getElementById('perishwinter').appendChild(document.createTextNode(Math.round(perish_winter_mult * 1000) / 10 + '%'));
document.getElementById('perishfridge').appendChild(document.createTextNode(Math.round(perish_fridge_mult * 1000) / 10 + '%'));
var info,
taggify = function (tag, name) { return '[tag:' + tag + '|' + (name || tag) + ']'; };
for (i in food) {
if (food.hasOwnProperty(i)) {
var f = food[i];
f.match = 0;
f.lowerName = f.name.toLowerCase();
f.id = i;
f.nameObject = {};
f.nameObject[i] = 1;
f.img = 'img/' + f.name.replace(/ /g, '_').toLowerCase() + '.png';
if (i.indexOf('_cooked') !== -1) {
f.cooked = true;
}
if (food[i + '_cooked']) {
f.cook = food[i + '_cooked'];
food[i + '_cooked'].raw = f;
}
f.info = [];
info = f.info;
f.fruit && info.push(taggify('fruit') + (f.fruit === 1 ? '' : '\xd7' + f.fruit));
f.veggie && info.push(taggify('veggie', 'vegetable') + (f.veggie === 1 ? '' : '\xd7' + f.veggie));
f.meat && info.push(taggify('meat') + (f.meat === 1 ? '' : '\xd7' + f.meat));
f.egg && info.push(taggify('egg') + (f.egg === 1 ? '' : '\xd7' + f.egg));
f.fish && info.push(taggify('fish'));
f.magic && info.push(taggify('magic'));
f.decoration && info.push(taggify('decoration'));
f.inedible && info.push(taggify('inedible'));
f.monster && info.push(taggify('monster', 'monster food'));
f.sweetener && info.push(taggify('sweetener'));
f.fat && info.push(taggify('fat'));
f.dairy && info.push(taggify('dairy'));
f.comment && info.push(f.comment);
food[index++] = f;
}
}
food.length = index;
index = 0;
for (i in recipes) {
if (recipes.hasOwnProperty(i)) {
recipes[i].match = 0;
recipes[i].name = recipes[i].name || i;
recipes[i].id = i;
recipes[i].lowerName = recipes[i].name.toLowerCase();
recipes[i].weight = recipes[i].weight || 1;
recipes[i].priority = recipes[i].priority || 0;
recipes[i].img = 'img/' + recipes[i].name.replace(/ /g, '_').toLowerCase() + '.png';
if (recipes[i].requirements) {
recipes[i].requires = makeLinkable(recipes[i].requirements.join('; '));
}
recipes[index++] = recipes[i];
}
}
recipes.length = index;
recipes.forEach = Array.prototype.forEach;
recipes.filter = Array.prototype.filter;
recipes.sort = Array.prototype.sort;
recipes.byName = function (name) {
var i = this.length;
while (i--) {
if (this[i].lowerName === name) {
return this[i];
}
}
};
var reduceRecipeButton = function (a, b) {
return a + '[recipe:' + b.name + '|' + b.img + ']';
};
var pl = function (str, n, plr) {
return n === 1 ? str : str + (plr || 's');
};
for (i in food) {
if (food.hasOwnProperty(i) && isNaN(i) && isNaN(food[i])) {
var f = food[i];
info = f.info;
f.cooked && info.push('from [*' + f.raw.name + '|' + f.raw.img + ']');
f.cook && info.push('cook: [*' + f.cook.name + '|' + f.cook.img + ']');
if (f.dry) {
if (!(f.dry instanceof Object)) {
f.dry = food[f.dry];
}
info.push('dry in ' + (f.drytime / total_day_time) + ' ' + pl('day', (f.drytime / total_day_time)) + ': [*' + f.dry.name + '|' + f.dry.img + ']');
}
f.info = info.join('; ');
if (!f.uncookable) {
f.recipes = [];
recipes.forEach(function (recipe) {
var qualifies = false, r = recipe.requirements, i = r.length;
while (i--) {
if (r[i].test(null, f.nameObject, f)) {
if (!r[i].cancel && !qualifies) {
qualifies = true;
}
} else {
if (r[i].cancel) {
qualifies = false;
break;
}
}
}
if (qualifies) {
f.recipes.push(recipe);
}
});
if (f.recipes.length > 0) {
f.ingredient = true;
f.info += (f.recipes.reduce(reduceRecipeButton, '[|][ingredient:' + f.name + '|Recipes] '));
}
} else {
f.info += ('[|]cannot be added to crock pot');
}
f.info = makeLinkable(f.info);
}
}
food.forEach = Array.prototype.forEach;
food.filter = Array.prototype.filter;
food.sort = Array.prototype.forEach;
food.byName = function (name) {
var i = this.length;
while (i--) {
if (this[i].lowerName === name) {
return this[i];
}
}
};
var usefulTags = ['id', 'health', 'hunger', 'fruit', 'veggie', 'meat', 'egg', 'fish', 'magic', 'decoration', 'inedible', 'monster', 'sweetener', 'fat', 'dairy'],
combinationGenerator = function (length, callback, startPos) {
var size = 4, index = 1, current = startPos || [0, 0, 0, 0], check, max = 0, iter = 0;
return function (batch) {
var overflow;
while (batch-- && index < length) {
callback(current);
current[0]++;
overflow = 0;
while (current[overflow] >= length) {
overflow++;
current[overflow]++;
}
check = size;
max = 0;
while (check--) {
if (current[check] >= length) {
current[check] = max;
} else if (current[check] > max) {
max = current[check];
}
}
if (overflow === size) {
return false;
break; //in case I copy and paste this for some reason and forget I need to get out of the loop
}
iter++;
}
return true;
};
};
recipeCrunchData = {};
recipeCrunchData.food = food.filter(function (item) {
return !item.uncookable && !item.skip && (item.ideal || (!item.cook && (!item.raw || !item.raw.ideal)));
}).map(function (item) {
var f = {}, t = usefulTags.length;
while (t--) {
if (item.hasOwnProperty(usefulTags[t])) {
f[usefulTags[t]] = item[usefulTags[t]];
}
}
return f;
});
recipeCrunchData.recipes = recipes.filter(function (item) {
return !item.trash;
}).sort(function (a, b) {
return b.priority - a.priority;
});
recipeCrunchData.test = recipeCrunchData.recipes.map(function (a) { return a.test; })
recipeCrunchData.tests = recipeCrunchData.recipes.map(function (a) { return a.test.toString(); })
recipeCrunchData.priority = recipeCrunchData.recipes.map(function (a) { return a.priority; });
var getRealRecipesFromCollection = function (items, mainCallback, chunkCallback, endCallback) {
var l = recipeCrunchData.test.length,
built = [],
renderedTo = 0,
lastTime,
block = 60,
desiredTime = 38,
foodFromIndex = function (index) {
return items[index];
},
callback = function (combination) {
var ingredients = combination.map(foodFromIndex), i, priority = null, names = {}, tags = {};
setIngredientValues(ingredients, names, tags);
for (var i = 0; i < l && (priority === null || recipeCrunchData.recipes[i].priority >= priority); i++) {
if (recipeCrunchData.test[i](null, names, tags)) {
built.push({ recipe: recipeCrunchData.recipes[i], ingredients: ingredients, tags: { health: tags.health, hunger: tags.hunger } });
priority = recipeCrunchData.recipes[i].priority;
}
}
},
getCombinations = combinationGenerator(items.length, callback),
computeNextBlock = function () {
var end = false,
start = Date.now();
if (getCombinations(block)) {
setTimeout(computeNextBlock, 0);
} else {
end = true;
}
for (; renderedTo < built.length && built[renderedTo]; renderedTo++) {
mainCallback(built[renderedTo]);
}
if (lastTime !== Date.now() - start) {
lastTime = Date.now() - start + 1;
block = desiredTime / lastTime * block + 1 | 0;
}
chunkCallback && chunkCallback();
end && endCallback && endCallback();
};
computeNextBlock();
};
//console.log(recipeCrunchData);
//delete recipeCrunchData.recipes;
//recipeCrunchString = JSON.stringify(recipeCrunchData); //recipeCrunch might also be used for multithreading later
//output.push('{| class="wikitable sortable"\n! width=145px |Name\n! width=40px |Health\n! width=50px |Food\n! width=60px |Perish\n|');
var setTab;
(function () {
var navtabs = navbar.getElementsByTagName('li'),
tabs = {},
elements = {},
storage,
activeIndex = 0,
activePage,
activeTab,
showTab = function (e) {
setTab(e.target.dataset.tab);
},
navtab;
setTab = function (tabID) {
activeTab.className = '';
activeTab = tabs[tabID];
activePage.style.display = 'none';
activePage = elements[tabID];
activeTab.className = 'selected';
activePage.style.display = 'block';
};
for (i = 0; i < navtabs.length; i++) {
navtab = navtabs[i];
if (navtab.dataset.tab) {
tabs[navtab.dataset.tab] = navtab;
elements[navtab.dataset.tab] = document.getElementById(navtab.dataset.tab);
elements[navtab.dataset.tab].style.display = 'none';
navtab.addEventListener('selectstart', function (e) { e.preventDefault(); }, false);
navtab.addEventListener('click', showTab, false);
}
}
activeTab = tabs['simulator'];
activePage = elements['simulator'];
if (window.localStorage && localStorage.foodGuideState) {
if (localStorage.foodGuideState[0] === '[') {
//converts from old format which causes errors
storage = {};
storage.pickers = JSON.parse(localStorage.foodGuideState);
localStorage.foodGuideState = JSON.stringify(storage);
} else {
storage = JSON.parse(localStorage.foodGuideState);
}
if (storage.activeTab && tabs[storage.activeTab]) {
activeTab = tabs[storage.activeTab];
activePage = elements[storage.activeTab];
}
}
activeTab.className = 'selected';
activePage.style.display = 'block';
window.addEventListener('beforeunload', function () {
var obj, serialized;
if (window.localStorage) {
if (!localStorage.foodGuideState) {
localStorage.foodGuideState = '{}';
}
obj = JSON.parse(localStorage.foodGuideState);
obj.activeTab = activeTab.dataset.tab;
localStorage.foodGuideState = JSON.stringify(obj);
}
});
}());
var queue = function (img) {
if (img.dataset.pending) {
makeImage.queue(img, img.dataset.pending, 32);
}
},
cells = function (cellType) {
var i, td, image, tr = document.createElement('tr'), cell, celltext;
for (i = 1; i < arguments.length; i++) {
td = document.createElement(cellType);
cell = arguments[i],
celltext = cell && cell.indexOf ? cell : cell.toString();
if (cell instanceof DocumentFragment) {
td.appendChild(cell.cloneNode(true));
Array.prototype.forEach.call(td.getElementsByTagName('img'), queue);
} else if (celltext.indexOf('img/') === 0) {
image = makeImage(celltext);
td.appendChild(image);
} else {
td.appendChild(document.createTextNode(celltext));
}
tr.appendChild(td);
}
return tr;
};
var makeSortableTable = function (headers, dataset, rowGenerator, defaultSort, hasSummary, linkCallback, highlightCallback, filterCallback, startRow, maxRows) {
var table, header, sorting, invertSort = false, firstHighlight, lastHighlight, rows,
generateAndHighlight = function (item, index, array) {
var row;
if ((!maxRows || rows < maxRows) && (!filterCallback || filterCallback(item))) {
row = rowGenerator(item);
if (highlightCallback && highlightCallback(item, array)) {
row.className = 'highlighted';
if (!firstHighlight) {
firstHighlight = row;
}
lastHighlight = row;
}
table.appendChild(row);
rows++;
}
},
create = function (e, sort, scrollHighlight) {
var tr, th, oldTable, sortBy, summary, links, i;
if (sort || (e && e.target.dataset.sort !== '') || sorting) {
sortBy = sort || (e && e.target.dataset.sort) || sorting;
if (hasSummary) {
summary = dataset.shift();
}
if (sortBy === 'name') {
dataset.sort(function (a, b) {
var aname = a.raw ? a.raw.name : a.name,
bname = b.raw ? b.raw.name : b.name;
if (aname !== bname) {
return aname > bname ? 1 : aname < bname ? -1 : 0;
}
return a.name === b.name ? 0 : a.raw === b ? 1 : -1;
});
} else {
dataset.sort(function (a, b) {
var sa = a[sortBy], sb = b[sortBy];
return !isNaN(sa) && !isNaN(sb) ? sb - sa : isNaN(sa) && isNaN(sb) ? 0 : isNaN(sa) ? 1 : -1;
});
}
if (sort || e) {
if (sorting === sortBy) {
invertSort = !invertSort;
} else {
sorting = sortBy;
invertSort = false;
}
}
if (invertSort) {
dataset.reverse();
}
if (hasSummary) {
dataset.unshift(summary);
}
}
tr = document.createElement('tr');
for (header in headers) {
th = document.createElement('th');
if (header.indexOf(':') === -1) {
th.appendChild(document.createTextNode(header));
} else {
th.appendChild(document.createTextNode(header.split(':')[0]));
th.title = header.split(':')[1];
}
if (headers[header]) {
if (headers[header] === sorting) {
th.style.background = invertSort ? '#555' : '#ccc';
th.style.color = invertSort ? '#ccc' : '#555';
th.style.borderRadius = '4px';
}
th.style.cursor = 'pointer';
th.dataset.sort = headers[header];
th.addEventListener('click', create, false);
}
tr.appendChild(th);
}
oldTable = table;
table = document.createElement('table');
table.appendChild(tr);
firstHighlight = null;
lastHighlight = null;
rows = 0;
dataset.forEach(generateAndHighlight);
if (linkCallback) {
table.className = 'links';
Array.prototype.forEach.call(table.getElementsByClassName('link'), function (element) {
element.addEventListener('click', linkCallback, false);
});
}
if (oldTable) {
oldTable.parentNode.replaceChild(table, oldTable);
}
if (scrollHighlight) {
if (firstHighlight && firstHighlight.offsetTop + table.offsetTop + mainElement.offsetTop + firstHighlight.offsetHeight > window.scrollY + window.innerHeight) {
firstHighlight.scrollIntoView(true);
} else if (lastHighlight && lastHighlight.offsetTop + table.offsetTop + mainElement.offsetTop < window.scrollY) {
lastHighlight.scrollIntoView(false);
}
}
};
if (defaultSort) {
create(null, defaultSort);
} else {
create();
}
table.update = function (scrollHighlight) {
create(null, null, scrollHighlight);
};
table.setMaxRows = function (max) {
maxRows = max;
this.update();
};
return table;
};
var sign = function (n) { return isNaN(n) ? '' : n > 0 ? '+' + n : n },
rawpct = function (base, val) {
return base < val ? (val - base) / Math.abs(base) : base > val ? -(base - val) / Math.abs(base) : 0;
},
pct = function (base, val) {
return !isNaN(base) && base !== val ? ' (' + sign(((base < val ? (val - base) / Math.abs(base) : base > val ? -(base - val) / Math.abs(base) : 0)*100).toFixed(0)) + '%)' : '';
};
var makeFoodRow = function (item) {
return cells('td', item.img ? item.img : '', item.name, sign(item.health), sign(item.hunger), isNaN(item.sanity) ? '' : sign(item.sanity), isNaN(item.perish) ? 'Never' : item.perish / total_day_time + ' ' + pl('day', item.perish / total_day_time), item.info || '');
};
var makeRecipeRow = function (item, health, hunger) {
return cells('td', item.img ? item.img : '', item.name, sign(item.health) + pct(health, item.health), sign(item.hunger) + pct(hunger, item.hunger), isNaN(item.sanity) ? '' : sign(item.sanity), isNaN(item.perish) ? 'Never' : item.perish / total_day_time + ' ' + pl('day', item.perish / total_day_time), (item.cooktime * base_cook_time + 0.5 | 0) + ' secs', item.priority || '0', item.requires || '');
};
(function () {
var foodHighlight,
foodHighlighted = [],
recipeHighlighted = [],
setFoodHighlight = function (e) {
var name = !e.target ? e : e.target.tagName === 'IMG' ? e.target.parentNode.dataset.link : e.target.dataset.link;
if (name.substring(0, 7) === 'recipe:' || name.substring(0, 11) === 'ingredient:') {
setTab('crockpot');
if (name.substring(0, 7) === 'recipe:') {
name = '*' + name.substring(7);
}
recipeHighlighted = matchingNames(recipes, name);
recipeTable.update(true);
} else {
if (foodHighlight !== name) {
foodHighlight = name;
foodHighlighted = matchingNames(food, name);
} else {
foodHighlight = '';
foodHighlighted.length = 0;
}
foodTable.update(true);
}
},
setRecipeHighlight = function (e) {
var name = !e.target ? e : e.target.tagName === 'IMG' ? e.target.parentNode.dataset.link : e.target.dataset.link;
setTab('foodlist');
foodHighlight = name;
foodHighlighted = matchingNames(food, name);
foodTable.update(true);
},
testFoodHighlight = function (item) {
return foodHighlighted.indexOf(item) !== -1;
},
testRecipeHighlight = function (item) {
return recipeHighlighted.indexOf(item) !== -1;
},
foodTable = makeSortableTable(
{'': '', 'Name': 'name', 'Health': 'health', 'Hunger': 'hunger', 'Sanity': 'sanity', 'Perish:Time to turn to rot': 'perish', 'Info': ''},
Array.prototype.slice.call(food),
makeFoodRow,
'name',
false,
setFoodHighlight,
testFoodHighlight
),
recipeTable = makeSortableTable(
{'': '', 'Name': 'name', 'Health': 'health', 'Hunger': 'hunger', 'Sanity': 'sanity', 'Perish:Time to turn to rot': 'perish', 'Cook Time': 'cooktime', 'Priority:One of the highest priority recipes for a combination will be made': 'priority', 'Requires:Dim, struck items cannot be used': ''},
Array.prototype.slice.call(recipes),
makeRecipeRow,
'name',
false,
setRecipeHighlight,
testRecipeHighlight
);
foodElement.appendChild(foodTable);
recipesElement.appendChild(recipeTable);
}());
var ingredientToIcon = function (a, b) {
return a + '[ingredient:' + food[b.id].name + '|' + food[b.id].img + ']';
},
makeRecipeGrinder = function (ingredients) {
var makableButton = document.createElement('button');
makableButton.appendChild(document.createTextNode('Calculate efficient recipes (may take some time)'));
makableButton.className = 'makablebutton';
makableButton.addEventListener('click', function () {
var idealIngredients = [],
i = ingredients ? ingredients.length : null,
selectedRecipe,
selectedRecipeElement,
addedRecipes = 0,
makableRecipes = [],
makableRecipe,
makableSummary,
splitCommaSpace = /, */,
makableFilter,
customFilter = null,
customFilterHolder,
customFilterInput,
usesIngredients = [],
excludesIngredients = [],
makableApply,
option,
made,
makableDiv,
makableTable,
checkExcludes = function (item) {
return excludesIngredients.indexOf(item.id) !== -1;
},
checkIngredient = function (item) {
return this.indexOf(food[item]) !== -1;
//return usesIngredients.indexOf(item.id) !== -1;
},
toggleFilter = function (e) {
if (excludesIngredients.indexOf(e.target.dataset.id) !== -1) {
excludesIngredients.splice(excludesIngredients.indexOf(e.target.dataset.id), 1);
}
if (usesIngredients.indexOf(e.target.dataset.id) !== -1) {
usesIngredients.splice(usesIngredients.indexOf(e.target.dataset.id), 1);
e.target.className = '';
} else {
usesIngredients.push(e.target.dataset.id);
e.target.className = 'selected';
}
makableTable.update();
},
toggleExclude = function (e) {
if (usesIngredients.indexOf(e.target.dataset.id) !== -1) {
usesIngredients.splice(usesIngredients.indexOf(e.target.dataset.id), 1);
}
if (excludesIngredients.indexOf(e.target.dataset.id) !== -1) {
excludesIngredients.splice(excludesIngredients.indexOf(e.target.dataset.id), 1);
e.target.className = '';
} else {
excludesIngredients.push(e.target.dataset.id);
e.target.className = 'excluded';
}
makableTable.update();
e.preventDefault();
},
setRecipe = function (e) {
if (selectedRecipeElement) {
selectedRecipeElement.className = '';
}
if (selectedRecipe === e.target.dataset.recipe) {
selectedRecipeElement = null;
selectedRecipe = null;
} else {
selectedRecipe = e.target.dataset.recipe;
selectedRecipeElement = e.target;
e.target.className = 'selected';
}
makableTable.update();
};
//TODO: optimize so much around this
if (i === null) {
i = food.length;
ingredients = food;
}
while (i--) {
if (ingredients[i].cook && idealIngredients.indexOf(ingredients[i].cook) === -1 && !ingredients[i].cook.uncookable) {
idealIngredients.push(ingredients[i].cook);
}
if (!ingredients[i].uncookable && (ingredients[i].ideal || !ingredients[i].cook || ingredients[i].cook.uncookable) && idealIngredients.indexOf(ingredients[i]) === -1) {
idealIngredients.push(ingredients[i]);
}
}
made = [];
makableTable = makeSortableTable(
{'': '', 'Name': 'name', 'Health': 'health', 'Health+:Health gained compared to ingredients': 'healthpls', 'Hunger': 'hunger', 'Hunger+:Hunger gained compared to ingredients': 'hungerpls', 'Ingredients': ''},
made,
function (data) {
var item = data.recipe,
health = data.tags.health,
hunger = data.tags.hunger;
return cells('td', item.img ? item.img : '', item.name, sign(item.health), sign(data.healthpls) + ' (' + sign((data.healthpct * 100) | 0) + '%)', sign(item.hunger), sign(data.hungerpls) + ' (' + sign((data.hungerpct * 100) | 0) + '%)',
makeLinkable(data.ingredients.reduce(ingredientToIcon, '')));
},
'hungerpls',
false,
null,
null,
function (data) {
return (!selectedRecipe || data.recipe.name === selectedRecipe) && (!excludesIngredients.length || !data.ingredients.some(checkExcludes)) && (!usesIngredients.length || usesIngredients.every(checkIngredient, data.ingredients));
},
0,
15
);
makableDiv = document.createElement('div');
makableSummary = document.createElement('div');
makableSummary.appendChild(document.createTextNode('Computing combinations..'));
makableDiv.appendChild(makableSummary);
makableRecipe = document.createElement('div');
makableRecipe.className = 'recipeFilter';
makableDiv.appendChild(makableRecipe);
makableFilter = document.createElement('div');
makableFilter.className = 'foodFilter';
idealIngredients.forEach(function (item) {
var img = makeImage(item.img, 32);
img.dataset.id = item.id;
img.addEventListener('click', toggleFilter, false);
img.addEventListener('contextmenu', toggleExclude, false);
img.title = item.name;
makableFilter.appendChild(img);
});
makableDiv.appendChild(makableFilter);
customFilterHolder = document.createElement('div');
customFilterInput = document.createElement('input');
customFilterInput.type = 'text';
customFilterInput.placeholder = 'use custom filter';
customFilterInput.className = 'customFilterInput';
customFilterHolder.appendChild(customFilterInput);
makableDiv.appendChild(makableTable);
makableButton.parentNode.replaceChild(makableDiv, makableButton);
getRealRecipesFromCollection(idealIngredients, function (data) { //row update
var i, img;
if (makableRecipes.indexOf(data.recipe.name) === -1) {
for (i = 0; i < makableRecipes.length; i++) {
if (data.recipe.name < makableRecipes[i]) {
break;
}
}
makableRecipes.splice(i, 0, data.recipe.name);
img = makeImage(recipes.byName(makableRecipes[i].toLowerCase()).img);
//TODO: optimize
img.dataset.recipe = makableRecipes[i];
img.addEventListener('click', setRecipe, false);
img.title = data.recipe.name;
if (i < makableRecipe.childNodes.length) {
makableRecipe.insertBefore(img, makableRecipe.childNodes[i]);
} else {
makableRecipe.appendChild(img);
}
}
if (!data.name) {
data.name = data.recipe.name;
data.health = data.recipe.health;
data.ihealth = data.tags.health;
data.healthpls = data.recipe.health - data.tags.health;
data.hunger = data.recipe.hunger;
data.ihunger = data.tags.hunger;
data.hungerpls = data.recipe.hunger - data.tags.hunger;
data.healthpct = rawpct(data.tags.health, data.recipe.health);
data.hungerpct = rawpct(data.tags.hunger, data.recipe.hunger);
data.sanity = data.recipe.sanity;
data.perish = data.recipe.perish;
}
made.push(data);
}, function () { //chunk update
/* this code provided updates to the table while the data was being crunched
var l = makableRecipes.length, img;
while (addedRecipes < l) {
img = makeImage(recipes.byName(makableRecipes[addedRecipes].toLowerCase()).img);
//TODO: optimize
img.dataset.recipe = makableRecipes[addedRecipes];
img.addEventListener('click', setRecipe, false);
makableRecipe.appendChild(img);
addedRecipes++;
makableRecipes.sort();
if (selectedRecipe !== makableRecipes[0]) {
selectedRecipe = makableRecipes[0];
selectedRecipeElement = makableRecipe.firstChild;
makableRecipe.firstChild.className = 'selected';
}
makableSummary.firstChild.textContent = 'Found ' + made.length + ' valid recipes..';
makableTable.update();
}*/
makableSummary.firstChild.textContent = 'Found ' + made.length + ' valid recipes..';
//makableTable.update();
}, function () { //computation finished
makableTable.setMaxRows(30);
makableSummary.firstChild.textContent = 'Found ' + made.length + ' valid recipes. Showing top 30 for selected recipe using all selected ingredients. Right-click to exclude ingredients.';
});
}, false);
return makableButton;
};
document.getElementById('statistics').appendChild(makeRecipeGrinder());
var highest = function (array, property) {
return array.reduce(function (previous, current) {
return Math.max(previous, current[property] || 0);
}, -100000);
};
window.food = food;
window.recipes = recipes;
window.matchingNames = matchingNames;
var setSlot = function (slotElement, item) {
var end = false;
if (item !== null) {
slotElement.dataset.id = item.id;
} else {
if (slotElement.nextSibling && getSlot(slotElement.nextSibling) !== null) {
setSlot(slotElement, getSlot(slotElement.nextSibling));
setSlot(slotElement.nextSibling, null);
end = true;
} else {
slotElement.dataset.id = null;
}
}
if (!end) {
if (item !== null) {
if (slotElement.firstChild) {
slotElement.replaceChild(makeImage(item.img), slotElement.firstChild);
} else {
slotElement.appendChild(makeImage(item.img));
}
} else {
if (slotElement.firstChild) {
slotElement.removeChild(slotElement.firstChild);
}
}
slotElement.title = item ? item.name : '';
}
},
getSlot = function (slotElement) {
return food[slotElement.dataset.id] || recipes[slotElement.dataset.id] || null;
};
(function () {
var pickers = document.getElementsByClassName('ingredientpicker'),
i = pickers.length;
while (i--) {
(function () {
var searchSelector = document.createElement('span'),
searchSelectorControls,
dropdown = document.createElement('div'),
ul = document.createElement('ul'),
picker = pickers[i],
index = i,
state,
from = picker.dataset.type === 'recipes' ? recipes : food,
allowUncookable = !picker.dataset.cookable,
parent = picker.nextSibling,
slots = parent.getElementsByClassName('ingredient'),
limited,
ingredients = [],
updateRecipes,
suggestions = [],
inventoryrecipes = [],
selected = null,
loaded = false,
results = document.getElementById('results'),
discoverfood = document.getElementById('discoverfood'),
discover = document.getElementById('discover'),
makable = document.getElementById('makable'),
clear = document.createElement('span'),
findPreviousMatching = function (el, test) {
var previous = el;
while (previous.previousSibling) {
previous = previous.previousSibling;
if (test(previous)) {
return previous;
}
}
return null;
},
findNextMatching = function (el, test) {
var next = el;
while (next.nextSibling) {
next = next.nextSibling;
if (test(next)) {
return next;
}
}
return null;
},
displaying = false,
appendSlot = function (id) {
var i, item = food[id] || recipes[id] || null;
if (limited) {
for (i = 0; i < slots.length; i++) {
if (getSlot(slots[i]) === null) {
setSlot(slots[i], item);
loaded && updateRecipes();
return i;
}
}
return -1;
} else {
if (slots.indexOf(id) === -1) {
slots.push(id);
i = document.createElement('span');
i.className = 'ingredient';
setSlot(i, item);
i.addEventListener('click', removeSlot, false);
parent.appendChild(i);
loaded && updateRecipes();
return 1;
}
return 1;
}
},
pickItem = function (e) {
var names,
target = e.target.tagName === 'IMG' ? e.target.parentNode : e.target,
result = appendSlot(target.dataset.id);
if (result !== -1) {
/*dropdown.removeChild(ul);
ul = document.createElement('div');
names = matchingNames(from, '', allowUncookable);
ul.dataset.length = 0;
names.forEach(liIntoPicker, ul);
dropdown.appendChild(ul);
if (ul.firstChild) {
ul.firstChild.className = 'selected';
}
picker.value = '';*/
/*if (result < slots.length - 1 || !limited) {
//picker.focus();
} else {
//picker.blur();
}*/
e && e.preventDefault && e.preventDefault();
//refreshLocation();
}
},
liIntoPicker = function (item) {
var img = makeImage(item.img, 32),
li = document.createElement('span');
li.appendChild(img);
li.appendChild(document.createTextNode(item.name));
li.dataset.id = item.id;
//li.dataset.tooltip = item.name;
if (ingredients.indexOf(item) !== -1) {
li.style.opacity = 0.5;
}
li.addEventListener('mousedown', pickItem, false);
this.appendChild(li);
this.dataset.length++;
/*if (this.dataset.length % 10 === 0) {
this.appendChild(document.createElement('br'));
}*/
},
updateFaded = function (el) {
if (ingredients.indexOf(food[el.dataset.id]) !== -1) {
if (!el.style.opacity) {
el.style.opacity = 0.5;
}
} else {
if (el.style.opacity) {
el.style.removeProperty('opacity');
}
}
},
removeSlot = function (e) {
var i, target = e.target.tagName === 'IMG' ? e.target.parentNode : e.target;
if (limited) {
if (getSlot(target) !== null) {
setSlot(target, null);
updateRecipes();
return target.dataset.id;
} else {
//picker.focus();
}
} else {
i = slots.indexOf(target.dataset.id);
slots.splice(i, 1);
parent.removeChild(target);
updateRecipes();
return slots[i] || null;
}
},
refreshLocation = function () {
/*if (mainElement.offsetLeft - dropdown.offsetWidth > 0) {
//to the left
dropdown.style.left = -dropdown.offsetWidth + 'px';
dropdown.style.top = picker.offsetTop + 'px';
} else if (mainElement.offsetLeft + picker.offsetLeft + picker.offsetWidth + dropdown.offsetWidth > window.innerWidth) {
//below
dropdown.style.left = picker.offsetLeft + 'px';
dropdown.style.top = picker.offsetTop + picker.offsetHeight + 'px';
} else {
//to the right
dropdown.style.left = picker.offsetLeft + picker.offsetWidth + 'px';
dropdown.style.top = picker.offsetTop + 'px';
}*/
},
refreshPicker = function () {
var names;
searchSelectorControls.splitTag();
names = matchingNames(from, searchSelectorControls.getSearch(), allowUncookable);
dropdown.removeChild(ul);
ul = document.createElement('div');
ul.dataset.length = 0;
names.forEach(liIntoPicker, ul);
dropdown.appendChild(ul);
//refreshLocation();
selected = null;
},
searchFor = function (e) {
var name = e.target.tagName === 'IMG' ? e.target.parentNode.dataset.link : e.target.dataset.link,
matches = matchingNames(from, name, allowUncookable);
if (matches.length === 1) {
appendSlot(matches[0].id);
} else {
picker.value = name;
refreshPicker();
//picker.focus();
}
},
coords;
if (parent.id === 'ingredients') {
//simulator
updateRecipes = function () {
var cooking,
health, hunger,
table;
ingredients = Array.prototype.map.call(slots, function (slot) {
return getSlot(slot);
});
cooking = getRecipes(ingredients);
health = cooking[0].health;
hunger = cooking[0].hunger;
table = makeSortableTable(
{'': '', 'Name': 'name', 'Health': 'health', 'Hunger': 'hunger', 'Sanity': 'sanity', 'Perish:Time to turn to rot': 'perish', 'Cook Time': 'cooktime', 'Priority:One of the highest priority recipes for a combination will be made': 'priority', 'Requires:Dim, struck items cannot be used': ''},
cooking,
function (item) {
return makeRecipeRow(item, health, hunger);
},
'priority',
true,
searchFor,
function (item, array) {
console.log(highest(array, 'priority'));
return array.length > 0 && item.priority === highest(array, 'priority');
}
);
if (results.firstChild) {
results.removeChild(results.firstChild);
}
if (results.firstChild) {
results.removeChild(results.firstChild);
results.removeChild(results.firstChild);
}
results.appendChild(table);
if (ingredients[0] !== null) {
getSuggestions(suggestions, ingredients, cooking);
if (suggestions.length > 0) {
results.appendChild(document.createTextNode('Add more ingredients to make:'));
table = makeSortableTable(
{'': '', 'Name': 'name', 'Health:(% more than ingredients)': 'health', 'Hunger:(% more than ingredients)': 'hunger', 'Sanity': 'sanity', 'Perish:Time to turn to rot': 'perish', 'Cook Time': 'cooktime', 'Priority:One of the highest priority recipes for a combination will be made': 'priority', 'Requires:Dim, struck items cannot be used': ''},
suggestions,
function (item) {
return makeRecipeRow(item, health, hunger);
},
'priority',
false,
searchFor
);
results.appendChild(table);
}
}
ul && ul.firstChild && Array.prototype.forEach.call(ul.getElementsByTagName('span'), updateFaded);
};
} else if (parent.id === 'inventory') {
//discovery
updateRecipes = function () {
var foodTable,
table;
ingredients = Array.prototype.map.call(parent.getElementsByClassName('ingredient'), function (slot) {
return getSlot(slot);
});
if (discoverfood.firstChild) {
discoverfood.removeChild(discoverfood.firstChild);
}
if (discover.firstChild) {
discover.removeChild(discover.firstChild);
}
if (makable.firstChild) {
makable.removeChild(makable.firstChild);
}
if (ingredients.length > 0) {
foodTable = makeSortableTable(
{'': '', 'Name': 'name', 'Health': 'health', 'Hunger': 'hunger', 'Sanity': 'sanity', 'Perish:Time to turn to rot': 'perish', 'Info': ''},
ingredients,
makeFoodRow,
'name'
);
discoverfood.appendChild(foodTable);
getSuggestions(inventoryrecipes, ingredients, null, true);
if (inventoryrecipes.length > 0) {
table = makeSortableTable(
{'': '', 'Name': 'name', 'Health': 'health', 'Hunger': 'hunger', 'Sanity': 'sanity', 'Perish:Time to turn to rot': 'perish', 'Cook Time': 'cooktime', 'Priority:One of the highest priority recipes for a combination will be made': 'priority', 'Requires:Dim, struck items cannot be used': ''},
inventoryrecipes,
makeRecipeRow,
'name'
)
discover.appendChild(table);
makable.appendChild(makeRecipeGrinder(ingredients));
}
}
ul && ul.firstChild && Array.prototype.forEach.call(ul.getElementsByTagName('span'), updateFaded);
};
}
if (slots.length !== 0) {
limited = true;
Array.prototype.forEach.call(slots, function (slot) {
setSlot(slot, null);
slot.addEventListener('click', removeSlot, false);
});
} else {
slots = [];
limited = false;
}
if (window.localStorage && localStorage.foodGuideState) {
state = JSON.parse(localStorage.foodGuideState).pickers;
if (state && state[index]) {
state[index].forEach(function (id) {
if (food[id]) {
appendSlot(id);
}
});
}
}
loaded = true;
searchSelector.className = 'searchselector retracted';
searchSelector.appendChild(document.createTextNode('name'));
searchSelectorControls = (function () {
var dropdown = document.createElement('div'),
extended = false,
extendedHeight = null,
searchTypes = [{title: 'name', prefix: '', placeholder: 'Filter ingredients'}, {title: 'tag', prefix: 'tag:', placeholder: 'Meat, veggie, fruit, egg, monster...'}, {title: 'recipe', prefix: 'recipe:', placeholder: 'Find ingredients used in a recipe'}],
selectedType = searchTypes[0],
retractTimer = null,
retract = function () {
extended = false;
dropdown.style.height = '0px';
searchSelector.style.borderBottomLeftRadius = '3px';
dropdown.style.borderTopLeftRadius = '3px';
if (retractTimer !== null) {
clearTimeout(retractTimer);
retractTimer = null;
}
searchSelector.className = 'searchselector retracted';
},
extend = function () {
if (extendedHeight === null) {
dropdown.style.height = 'auto';
dropdown.style.left = searchSelector.offsetLeft;
dropdown.style.top = searchSelector.offsetTop + searchSelector.offsetHeight;
extendedHeight = dropdown.offsetHeight + 'px';
dropdown.style.height = '0px';
}
extended = true;
dropdown.style.height = extendedHeight;
searchSelector.style.borderBottomLeftRadius = '0px';
dropdown.style.borderTopLeftRadius = '0px';
dropdown.style.width = 'auto';
dropdown.style.width = Math.max(dropdown.offsetWidth, searchSelector.offsetWidth + 1) + 'px';
if (retractTimer !== null) {
clearTimeout(retractTimer);
retractTimer = null;
}
searchSelector.className = 'searchselector extended';
},
setSearchType = function (searchType) {
selectedType = searchType;
picker.placeholder = selectedType.placeholder;
searchSelector.firstChild.textContent = selectedType.title;
},
setSearchTypeFromClick = function (e) {
setSearchType(searchTypes[e.target.dataset.typeIndex]);
refreshPicker();
retract();
},
tagsplit = /: */,
controls = {
getTag: function () {
return selectedType.title;
},
setSearchType: function (index) {
setSearchType(searchTypes[index]);
},
getSearch: function () {
return selectedType.prefix + picker.value;
},
splitTag: function () {
var i,
parts = picker.value.split(tagsplit),
tag,
name;
if (parts.length === 2) {
tag = parts[0].toLowerCase() + ':';
name = parts[1];
for (i = 0; i < searchTypes.length; i++) {
if (tag === searchTypes[i].prefix) {
setSearchType(searchTypes[i]);
picker.value = name;
break;
}
}
}
}
};
searchSelector.addEventListener('click', function () {
if (extended) {
retract();
} else {
extend();
}
}, false);
searchSelector.addEventListener('selectstart', function (e) { e.preventDefault(); }, false);
searchSelector.addEventListener('mouseout', function () {
if (retractTimer !== null) {
clearTimeout(retractTimer);
}
retractTimer = setTimeout(retract, 500);
}, false);
searchSelector.addEventListener('mouseover', function () {
if (retractTimer !== null) {
clearTimeout(retractTimer);
retractTimer = null;
}
}, false);
dropdown.addEventListener('mouseout', function () {
if (retractTimer !== null) {
clearTimeout(retractTimer);
}
retractTimer = setTimeout(retract, 500);
}, false);
dropdown.addEventListener('mouseover', function () {
if (retractTimer !== null) {
clearTimeout(retractTimer);
retractTimer = null;
}
}, false);
searchTypes.forEach(function (searchType, index) {
var element = document.createElement('div');
element.appendChild(document.createTextNode(searchType.title));
element.dataset.typeIndex = index;
element.addEventListener('click', setSearchTypeFromClick, false);
searchType.element = element;
dropdown.appendChild(element);
});
picker.parentNode.insertBefore(searchSelector, picker);
dropdown.className = 'searchdropdown';
picker.parentNode.insertBefore(dropdown, picker);
return controls;
}());
dropdown.className = 'ingredientdropdown';
dropdown.appendChild(ul);
dropdown.addEventListener('mousedown', function (e) { e.preventDefault(); }, false);
(function () {
var names = matchingNames(from, searchSelectorControls.getSearch(), allowUncookable);
dropdown.removeChild(ul);
ul = document.createElement('div');
ul.dataset.length = 0;
names.forEach(liIntoPicker, ul);
dropdown.appendChild(ul);
}());
clear.className = 'clearingredients';
clear.appendChild(document.createTextNode('clear'));
clear.addEventListener('click', function () {
if (picker.value === '' && searchSelectorControls.getTag() === 'name') {
while (getSlot(parent.firstChild)) {
removeSlot({ target: parent.firstChild });
}
} else {
picker.value = '';
searchSelectorControls.setSearchType(0);
refreshPicker();
}
}, false);
clear.addEventListener('mouseover', function () {
if (picker.value === '' && searchSelectorControls.getTag() === 'name') {
clear.firstChild.textContent = 'clear chosen ingredients';
}
}, false);
clear.addEventListener('mouseout', function () {
if (clear.firstChild.textContent !== 'clear') {
clear.firstChild.textContent = 'clear';
}
}, false);
parent.parentNode.insertBefore(clear, parent);
parent.parentNode.insertBefore(dropdown, parent);
picker.addEventListener('keydown', function (e) {
var movement = [16, 17, 37, 38, 39, 40, 13],
up = 38, left = 37, down = 40, right = 39, enter = 13, current, items, i, find;
if (movement.indexOf(e.keyCode) !== -1) {
current = selected;
if (e.keyCode === enter) {
if (selected === null) {
selected = ul.firstChild || null;
}
if (selected !== null) {
pickItem({target: selected});
}
} else {
if (selected === null) {
if (e.keyCode === down) {
selected = ul.childNodes[1] || ul.firstChild || null;
if (selected !== null) {
coords = (selected.offsetLeft + selected.offsetWidth / 2);
e.preventDefault();
}
}
} else {
e.preventDefault();
if (e.keyCode === left) {
if (selected.previousSibling && selected.previousSibling.offsetTop === selected.offsetTop) {
selected = selected.previousSibling;
} else {
find = findNextMatching(selected, function (el) {
//separate this out
return el.offsetTop !== selected.offsetTop;
});
if (find) {
selected = find.previousSibling;
} else {
selected = ul.lastChild;
}
}
if (selected !== null) {
coords = (selected.offsetLeft + selected.offsetWidth / 2);
}
} else if (e.keyCode === right) {
if (selected.nextSibling && selected.nextSibling.offsetTop === selected.offsetTop) {
selected = selected.nextSibling;
} else {
find = findPreviousMatching(selected, function (el) {
//separate this out
return el.offsetTop !== selected.offsetTop;
});
if (find) {
selected = find.nextSibling;
} else {
selected = ul.firstChild;
}
}
if (selected !== null) {
coords = (selected.offsetLeft + selected.offsetWidth / 2);
}
} else if (e.keyCode === up) {
find = findPreviousMatching(selected, function (el) {
return coords >= el.offsetLeft - 1 && coords <= el.offsetLeft + el.offsetWidth + 1;
});
if (!find) {
find = findPreviousMatching(ul.lastChild, function (el) {
return coords >= el.offsetLeft - 1 && coords <= el.offsetLeft + el.offsetWidth + 1;
});
}
if (find) {
selected = find;
} else {
selected = ul.firstChild;
}
} else if (e.keyCode === down) {
find = findNextMatching(selected, function (el) {
return coords >= el.offsetLeft - 1 && coords <= el.offsetLeft + el.offsetWidth + 1;
});
if (!find) {
find = findNextMatching(ul.firstChild, function (el) {
return coords >= el.offsetLeft - 1 && coords <= el.offsetLeft + el.offsetWidth + 1;
});
}
if (find) {
selected = find;
} else {
selected = ul.lastChild;
}
}
}
}
if (selected !== current) {
if (current !== null) {
current.className = '';
}
if (selected !== null) {
selected.className = 'selected';
}
}
}
}, false);
picker.addEventListener('keyup', function (e) {
var movement = [16, 17, 37, 38, 39, 40, 13],
up = 38, left = 37, down = 40, right = 39, enter = 13, current, items, i;
current = selected;
if (movement.indexOf(e.keyCode) === -1) {
refreshPicker();
} else if (selected !== null) {
e.preventDefault();
}
/*
using comments as version control is bad
else {
items = ul.getElementsByTagName('li');
for (i = 0; i < items.length; i++) {
if (items[i].className === 'selected') {
current = items[i];
if (e.keyCode === up || e.keyCode === down) {
items[i].className = '';
}
if (e.keyCode === up) {
items[i - 1 < 0 ? items.length - 1 : i - 1].className = 'selected';
} else if (e.keyCode === down) {
items[(i + 1) % items.length].className = 'selected';
} else if (e.keyCode === enter && current) {
pickItem({target: current});
refreshLocation();
}
break;
}
}
if (!current && items.length > 0) {
if (e.keyCode === up) {
items[items.length - 1].className = 'selected';
} else if (e.keyCode === down) {
items[0].className = 'selected';
} else if (e.keyCode === enter) {
pickItem({target: items[0]});
}
}
}*/
}, false);
picker.addEventListener('focus', function () {
if (!displaying) {
displaying = true;
//parent.appendChild(dropdown);
//refreshLocation();
}
}, false);
picker.addEventListener('blur', function () {
if (displaying) {
displaying = false;
//parent.removeChild(dropdown);
}
}, false);
updateRecipes();
window.addEventListener('beforeunload', function () {
var obj, serialized;
if (window.localStorage) {
if (!localStorage.foodGuideState) {
localStorage.foodGuideState = '{}';
}
obj = JSON.parse(localStorage.foodGuideState);
if (!obj.pickers) {
obj.pickers = [];
}
if (limited) {
serialized = [];
serialized = Array.prototype.map.call(slots, function (slot) {
var item = getSlot(slot);
return item ? item.id : null;
});
obj.pickers[index] = serialized;
} else {
obj.pickers[index] = slots;
}
localStorage.foodGuideState = JSON.stringify(obj);
}
});
}());
}
}())
}()); | JavaScript |
function showGallery(){
var dict = '';
var photo_list = [
'pic_2.JPG',
'pic_3.JPG',
'pic_4.JPG',
'pic_5.JPG',
'pic_6.JPG',
'pic_7.JPG',
'pic_8.JPG',
'pic_9.JPG',
'pic_10.JPG',
'pic_11.JPG',
'pic_12.JPG',
'pic_13.JPG',
'pic_14.JPG',
'pic_15.JPG',
'pic_16.JPG',
'pic_17.JPG',
'pic_18.JPG',
'pic_19.JPG',
'pic_20.JPG',
'pic_21.JPG',
'pic_22.JPG',
'pic_23.JPG',
'pic_24.JPG',
'pic_25.JPG',
'pic_26.JPG',
'pic_27.JPG',
'pic_28.JPG',
'pic_29.JPG',
'pic_30.JPG',
'pic_31.JPG',
'pic_32.JPG',
'pic_33.JPG',
'pic_34.JPG',
'pic_35.JPG',
'pic_36.JPG',
'pic_37.JPG',
'pic_38.JPG',
'pic_39.JPG',
'pic_40.JPG',
'pic_41.JPG',
'pic_42.JPG',
'pic_43.JPG',
'pic_44.JPG',
'pic_45.JPG',
'pic_46.JPG',
'pic_47.JPG',
'wall1_bf.jpg',
'wall1_af.jpg',
'wall2_bf.jpg',
'wall2_af.jpg',
'driveway1_bf.jpg',
'driveway1_af.jpg',
'pit1_bf.jpg',
'pit1_af.jpg',
'walkway.jpg',
'fence1_bf.jpg',
'fence1_af.jpg',
'tonywall1.jpg',
'trees1.jpg',
'tree_front_house2.jpg',
'tree_front_house1.jpg',
'tree_front_house3.jpg',
'bulldozer1.jpg',
'tony_front_house.jpg'
]
var rows = "<tbody><tr><td>";
$.each(photo_list, function(i, n){
rows = rows + "<span>" ;
rows = rows + "<a href='/photos/" + n + "'>";
rows = rows + "<img src='/photos/" + n.split(".")[0] + "t." +
n.split(".")[1] + "' width='122' height='80' /></a>";
if ( (i+1) % 3 == 0){
rows = rows + "</span> <br />";
}else{
rows = rows + "</span> ";
}
});
rows = rows + "</td></tr></tbody>";
$(".gallery").append(rows);
}
$(function(){
showGallery();
$('.gallery a').lightBox();
}); | JavaScript |
/* =========================================================
// jquery.innerfade.js
// Datum: 2008-02-14
// Firma: Medienfreunde Hofmann & Baldes GbR
// Author: Torsten Baldes
// Mail: t.baldes@medienfreunde.com
// Web: http://medienfreunde.com
// based on the work of Matt Oakes http://portfolio.gizone.co.uk/applications/slideshow/
// and Ralf S. Engelschall http://trainofthoughts.org/
*
* <ul id="news">
* <li>content 1</li>
* <li>content 2</li>
* <li>content 3</li>
* </ul>
*
* $('#news').innerfade({
* animationtype: Type of animation 'fade' or 'slide' (Default: 'fade'),
* speed: Fading-/Sliding-Speed in milliseconds or keywords (slow, normal or fast) (Default: 'normal'),
* timeout: Time between the fades in milliseconds (Default: '2000'),
* type: Type of slideshow: 'sequence', 'random' or 'random_start' (Default: 'sequence'),
* containerheight: Height of the containing element in any css-height-value (Default: 'auto'),
* runningclass: CSS-Class which the container get’s applied (Default: 'innerfade'),
* children: optional children selector (Default: null)
* });
*
// ========================================================= */
(function($) {
$.fn.innerfade = function(options) {
return this.each(function() {
$.innerfade(this, options);
});
};
$.innerfade = function(container, options) {
var settings = {
'animationtype': 'fade',
'speed': 'normal',
'type': 'sequence',
'timeout': 2000,
'containerheight': 'auto',
'runningclass': 'innerfade',
'children': null
};
if (options)
$.extend(settings, options);
if (settings.children === null)
var elements = $(container).children();
else
var elements = $(container).children(settings.children);
if (elements.length > 1) {
$(container).css('position', 'relative').css('height', settings.containerheight).addClass(settings.runningclass);
for (var i = 0; i < elements.length; i++) {
$(elements[i]).css('z-index', String(elements.length-i)).css('position', 'absolute').hide();
};
if (settings.type == "sequence") {
setTimeout(function() {
$.innerfade.next(elements, settings, 1, 0);
}, settings.timeout);
$(elements[0]).show();
} else if (settings.type == "random") {
var last = Math.floor ( Math.random () * ( elements.length ) );
setTimeout(function() {
do {
current = Math.floor ( Math.random ( ) * ( elements.length ) );
} while (last == current );
$.innerfade.next(elements, settings, current, last);
}, settings.timeout);
$(elements[last]).show();
} else if ( settings.type == 'random_start' ) {
settings.type = 'sequence';
var current = Math.floor ( Math.random () * ( elements.length ) );
setTimeout(function(){
$.innerfade.next(elements, settings, (current + 1) % elements.length, current);
}, settings.timeout);
$(elements[current]).show();
} else {
alert('Innerfade-Type must either be \'sequence\', \'random\' or \'random_start\'');
}
}
};
$.innerfade.next = function(elements, settings, current, last) {
if (settings.animationtype == 'slide') {
$(elements[last]).slideUp(settings.speed);
$(elements[current]).slideDown(settings.speed);
} else if (settings.animationtype == 'fade') {
$(elements[last]).fadeOut(settings.speed);
$(elements[current]).fadeIn(settings.speed, function() {
removeFilter($(this)[0]);
});
} else
alert('Innerfade-animationtype must either be \'slide\' or \'fade\'');
if (settings.type == "sequence") {
if ((current + 1) < elements.length) {
current = current + 1;
last = current - 1;
} else {
current = 0;
last = elements.length - 1;
}
} else if (settings.type == "random") {
last = current;
while (current == last)
current = Math.floor(Math.random() * elements.length);
} else
alert('Innerfade-Type must either be \'sequence\', \'random\' or \'random_start\'');
setTimeout((function() {
$.innerfade.next(elements, settings, current, last);
}), settings.timeout);
};
})(jQuery);
// **** remove Opacity-Filter in ie ****
function removeFilter(element) {
if(element.style.removeAttribute){
element.style.removeAttribute('filter');
}
}
| JavaScript |
/*
* Translated default messages for the jQuery validation plugin.
* Locale: FA
*/
jQuery.extend(jQuery.validator.messages, {
required: "تکمیل این فیلد اجباری است.",
remote: "لطفا این فیلد را تصحیح کنید.",
email: ".لطفا یک ایمیل صحیح وارد کنید",
url: "لطفا آدرس صحیح وارد کنید.",
date: "لطفا یک تاریخ صحیح وارد کنید",
dateISO: "لطفا تاریخ صحیح وارد کنید (ISO).",
number: "لطفا عدد صحیح وارد کنید.",
digits: "لطفا تنها رقم وارد کنید",
creditcard: "لطفا کریدیت کارت صحیح وارد کنید.",
equalTo: "لطفا مقدار برابری وارد کنید",
accept: "لطفا مقداری وارد کنید که ",
maxlength: jQuery.validator.format("لطفا بیشتر از {0} حرف وارد نکنید."),
minlength: jQuery.validator.format("لطفا کمتر از {0} حرف وارد نکنید."),
rangelength: jQuery.validator.format("لطفا مقداری بین {0} تا {1} حرف وارد کنید."),
range: jQuery.validator.format("لطفا مقداری بین {0} تا {1} حرف وارد کنید."),
max: jQuery.validator.format("لطفا مقداری کمتر از {0} حرف وارد کنید."),
min: jQuery.validator.format("لطفا مقداری بیشتر از {0} حرف وارد کنید.")
});
| JavaScript |
/*
* Translated default messages for the jQuery validation plugin.
* Locale: IT
*/
jQuery.extend(jQuery.validator.messages, {
required: "Campo obbligatorio.",
remote: "Controlla questo campo.",
email: "Inserisci un indirizzo email valido.",
url: "Inserisci un indirizzo web valido.",
date: "Inserisci una data valida.",
dateISO: "Inserisci una data valida (ISO).",
number: "Inserisci un numero valido.",
digits: "Inserisci solo numeri.",
creditcard: "Inserisci un numero di carta di credito valido.",
equalTo: "Il valore non corrisponde.",
accept: "Inserisci un valore con un'estensione valida.",
maxlength: jQuery.validator.format("Non inserire più di {0} caratteri."),
minlength: jQuery.validator.format("Inserisci almeno {0} caratteri."),
rangelength: jQuery.validator.format("Inserisci un valore compreso tra {0} e {1} caratteri."),
range: jQuery.validator.format("Inserisci un valore compreso tra {0} e {1}."),
max: jQuery.validator.format("Inserisci un valore minore o uguale a {0}."),
min: jQuery.validator.format("Inserisci un valore maggiore o uguale a {0}.")
}); | JavaScript |
/*
* Translated default messages for the jQuery validation plugin in lithuanian.
* Locale: LT
*/
jQuery.extend(jQuery.validator.messages, {
required: "Šis laukas yra privalomas.",
remote: "Prašau pataisyti šį lauką.",
email: "Prašau įvesti teisingą elektroninio pašto adresą.",
url: "Prašau įvesti teisingą URL.",
date: "Prašau įvesti teisingą datą.",
dateISO: "Prašau įvesti teisingą datą (ISO).",
number: "Prašau įvesti teisingą skaičių.",
digits: "Prašau naudoti tik skaitmenis.",
creditcard: "Prašau įvesti teisingą kreditinės kortelės numerį.",
equalTo: "Prašau įvestį tą pačią reikšmę dar kartą.",
accept: "Prašau įvesti reikšmę su teisingu plėtiniu.",
maxlength: $.format("Prašau įvesti ne daugiau kaip {0} simbolių."),
minlength: $.format("Prašau įvesti bent {0} simbolius."),
rangelength: $.format("Prašau įvesti reikšmes, kurių ilgis nuo {0} iki {1} simbolių."),
range: $.format("Prašau įvesti reikšmę intervale nuo {0} iki {1}."),
max: $.format("Prašau įvesti reikšmę mažesnę arba lygią {0}."),
min: $.format("Prašau įvesti reikšmę didesnę arba lygią {0}.")
}); | JavaScript |
/*
* Translated default messages for the jQuery validation plugin.
* Locale: SI (Slovenian)
*/
jQuery.extend(jQuery.validator.messages, {
required: "To polje je obvezno.",
remote: "Vpis v tem polju ni v pravi obliki.",
email: "Prosimo, vnesite pravi email naslov.",
url: "Prosimo, vnesite pravi URL.",
date: "Prosimo, vnesite pravi datum.",
dateISO: "Prosimo, vnesite pravi datum (ISO).",
number: "Prosimo, vnesite pravo številko.",
digits: "Prosimo, vnesite samo številke.",
creditcard: "Prosimo, vnesite pravo številko kreditne kartice.",
equalTo: "Prosimo, ponovno vnesite enako vsebino.",
accept: "Prosimo, vnesite vsebino z pravo končnico.",
maxlength: $.validator.format("Prosimo, da ne vnašate več kot {0} znakov."),
minlength: $.validator.format("Prosimo, vnesite vsaj {0} znakov."),
rangelength: $.validator.format("Prosimo, vnesite od {0} do {1} znakov."),
range: $.validator.format("Prosimo, vnesite vrednost med {0} in {1}."),
max: $.validator.format("Prosimo, vnesite vrednost manjšo ali enako {0}."),
min: $.validator.format("Prosimo, vnesite vrednost večjo ali enako {0}.")
});
| JavaScript |
/*
* Translated default messages for the jQuery validation plugin.
* Locale: JA (Japanese)
*/
jQuery.extend(jQuery.validator.messages, {
required: "このフィールドは必須です。",
remote: "このフィールドを修正してください。",
email: "有効なEメールアドレスを入力してください。",
url: "有効なURLを入力してください。",
date: "有効な日付を入力してください。",
dateISO: "有効な日付(ISO)を入力してください。",
number: "有効な数字を入力してください。",
digits: "数字のみを入力してください。",
creditcard: "有効なクレジットカード番号を入力してください。",
equalTo: "同じ値をもう一度入力してください。",
accept: "有効な拡張子を含む値を入力してください。",
maxlength: jQuery.format("{0} 文字以内で入力してください。"),
minlength: jQuery.format("{0} 文字以上で入力してください。"),
rangelength: jQuery.format("{0} 文字から {1} 文字までの値を入力してください。"),
range: jQuery.format("{0} から {1} までの値を入力してください。"),
max: jQuery.format("{0} 以下の値を入力してください。"),
min: jQuery.format("{1} 以上の値を入力してください。")
}); | JavaScript |
/*
* Localized default methods for the jQuery validation plugin.
* Locale: PT_BR
*/
jQuery.extend(jQuery.validator.methods, {
date: function(value, element) {
return this.optional(element) || /^\d\d?\/\d\d?\/\d\d\d?\d?$/.test(value);
}
}); | JavaScript |
/*
* Translated default messages for the jQuery validation plugin.
* Locale: SK
*/
jQuery.extend(jQuery.validator.messages, {
required: "Povinné zadať.",
maxlength: jQuery.validator.format("Maximálne {0} znakov."),
minlength: jQuery.validator.format("Minimálne {0} znakov."),
rangelength: jQuery.validator.format("Minimálne {0} a Maximálne {0} znakov."),
email: "E-mailová adresa musí byť platná.",
url: "URL musí byť platný.",
date: "Musí byť dátum.",
number: "Musí byť číslo.",
digits: "Môže obsahovať iba číslice.",
equalTo: "Dva hodnoty sa musia rovnať.",
range: jQuery.validator.format("Musí byť medzi {0} a {1}."),
max: jQuery.validator.format("Nemôže byť viac ako{0}."),
min: jQuery.validator.format("Nemôže byť menej ako{0}."),
creditcard: "Číslo platobnej karty musí byť platné."
});
| JavaScript |
/**
* Translated default messages for the jQuery validation plugin.
* Locale: PT_PT
*/
jQuery.extend(jQuery.validator.messages, {
required: "Campo de preenchimento obrigatório.",
remote: "Por favor, corrija este campo.",
email: "Por favor, introduza um endereço eletrónico válido.",
url: "Por favor, introduza um URL válido.",
date: "Por favor, introduza uma data válida.",
dateISO: "Por favor, introduza uma data válida (ISO).",
number: "Por favor, introduza um número válido.",
digits: "Por favor, introduza apenas dígitos.",
creditcard: "Por favor, introduza um número de cartão de crédito válido.",
equalTo: "Por favor, introduza de novo o mesmo valor.",
accept: "Por favor, introduza um ficheiro com uma extensão válida.",
maxlength: jQuery.validator.format("Por favor, não introduza mais do que {0} caracteres."),
minlength: jQuery.validator.format("Por favor, introduza pelo menos {0} caracteres."),
rangelength: jQuery.validator.format("Por favor, introduza entre {0} e {1} caracteres."),
range: jQuery.validator.format("Por favor, introduza um valor entre {0} e {1}."),
max: jQuery.validator.format("Por favor, introduza um valor menor ou igual a {0}."),
min: jQuery.validator.format("Por favor, introduza um valor maior ou igual a {0}.")
});
| JavaScript |
/*
* Translated default messages for the jQuery validation plugin.
* Locale: SE
*/
jQuery.extend(jQuery.validator.messages, {
required: "Detta fält är obligatoriskt.",
maxlength: jQuery.validator.format("Du får ange högst {0} tecken."),
minlength: jQuery.validator.format("Du måste ange minst {0} tecken."),
rangelength: jQuery.validator.format("Ange minst {0} och max {1} tecken."),
email: "Ange en korrekt e-postadress.",
url: "Ange en korrekt URL.",
date: "Ange ett korrekt datum.",
dateISO: "Ange ett korrekt datum (&ARING;&ARING;&ARING;&ARING;-MM-DD).",
number: "Ange ett korrekt nummer.",
digits: "Ange endast siffror.",
equalTo: "Ange samma värde igen.",
range: jQuery.validator.format("Ange ett värde mellan {0} och {1}."),
max: jQuery.validator.format("Ange ett värde som är mindre eller lika med {0}."),
min: jQuery.validator.format("Ange ett värde som är större eller lika med {0}."),
creditcard: "Ange ett korrekt kreditkortsnummer."
}); | JavaScript |
/*
* Translated default messages for the jQuery validation plugin.
* Locale: TW (Taiwan - Traditional Chinese)
*/
jQuery.extend(jQuery.validator.messages, {
required: "必填",
remote: "請修正此欄位",
email: "請輸入正確的電子信箱",
url: "請輸入合法的URL",
date: "請輸入合法的日期",
dateISO: "請輸入合法的日期 (ISO).",
number: "請輸入數字",
digits: "請輸入整數",
creditcard: "請輸入合法的信用卡號碼",
equalTo: "請重複輸入一次",
accept: "請輸入有效的後缀字串",
maxlength: jQuery.validator.format("請輸入長度不大於{0} 的字串"),
minlength: jQuery.validator.format("請輸入長度不小於 {0} 的字串"),
rangelength: jQuery.validator.format("請輸入長度介於 {0} 和 {1} 之間的字串"),
range: jQuery.validator.format("請輸入介於 {0} 和 {1} 之間的數值"),
max: jQuery.validator.format("請輸入不大於 {0} 的數值"),
min: jQuery.validator.format("請輸入不小於 {0} 的數值")
}); | JavaScript |
/*
* Localized default methods for the jQuery validation plugin.
* Locale: DE
*/
jQuery.extend(jQuery.validator.methods, {
date: function(value, element) {
return this.optional(element) || /^\d\d?\.\d\d?\.\d\d\d?\d?$/.test(value);
},
number: function(value, element) {
return this.optional(element) || /^-?(?:\d+|\d{1,3}(?:\.\d{3})+)(?:,\d+)?$/.test(value);
}
}); | JavaScript |
/*
* Translated default messages for the jQuery validation plugin.
* Locale: CN
*/
jQuery.extend(jQuery.validator.messages, {
required: "必选字段",
remote: "请修正该字段",
email: "请输入正确格式的电子邮件",
url: "请输入合法的网址",
date: "请输入合法的日期",
dateISO: "请输入合法的日期 (ISO).",
number: "请输入合法的数字",
digits: "只能输入整数",
creditcard: "请输入合法的信用卡号",
equalTo: "请再次输入相同的值",
accept: "请输入拥有合法后缀名的字符串",
maxlength: jQuery.validator.format("请输入一个长度最多是 {0} 的字符串"),
minlength: jQuery.validator.format("请输入一个长度最少是 {0} 的字符串"),
rangelength: jQuery.validator.format("请输入一个长度介于 {0} 和 {1} 之间的字符串"),
range: jQuery.validator.format("请输入一个介于 {0} 和 {1} 之间的值"),
max: jQuery.validator.format("请输入一个最大为 {0} 的值"),
min: jQuery.validator.format("请输入一个最小为 {0} 的值")
}); | JavaScript |
/*
* Translated default messages for the jQuery validation plugin.
* Locale: EL
*/
jQuery.extend(jQuery.validator.messages, {
required: "Αυτό το πεδίο είναι υποχρεωτικό.",
remote: "Παρακαλώ διορθώστε αυτό το πεδίο.",
email: "Παρακαλώ εισάγετε μια έγκυρη διεύθυνση email.",
url: "Παρακαλώ εισάγετε ένα έγκυρο URL.",
date: "Παρακαλώ εισάγετε μια έγκυρη ημερομηνία.",
dateISO: "Παρακαλώ εισάγετε μια έγκυρη ημερομηνία (ISO).",
number: "Παρακαλώ εισάγετε έναν έγκυρο αριθμό.",
digits: "Παρακαλώ εισάγετε μόνο αριθμητικά ψηφία.",
creditcard: "Παρακαλώ εισάγετε έναν έγκυρο αριθμό πιστωτικής κάρτας.",
equalTo: "Παρακαλώ εισάγετε την ίδια τιμή ξανά.",
accept: "Παρακαλώ εισάγετε μια τιμή με έγκυρη επέκταση αρχείου.",
maxlength: $.validator.format("Παρακαλώ εισάγετε μέχρι και {0} χαρακτήρες."),
minlength: $.validator.format("Παρακαλώ εισάγετε τουλάχιστον {0} χαρακτήρες."),
rangelength: $.validator.format("Παρακαλώ εισάγετε μια τιμή με μήκος μεταξύ {0} και {1} χαρακτήρων."),
range: $.validator.format("Παρακαλώ εισάγετε μια τιμή μεταξύ {0} και {1}."),
max: $.validator.format("Παρακαλώ εισάγετε μια τιμή μικρότερη ή ίση του {0}."),
min: $.validator.format("Παρακαλώ εισάγετε μια τιμή μεγαλύτερη ή ίση του {0}.")
});
| JavaScript |
/*
* Translated default messages for the jQuery validation plugin.
* Locale: BG
*/
jQuery.extend(jQuery.validator.messages, {
required: "Полето е задължително.",
remote: "Моля, въведете правилната стойност.",
email: "Моля, въведете валиден email.",
url: "Моля, въведете валидно URL.",
date: "Моля, въведете валидна дата.",
dateISO: "Моля, въведете валидна дата (ISO).",
number: "Моля, въведете валиден номер.",
digits: "Моля, въведете само цифри",
creditcard: "Моля, въведете валиден номер на кредитна карта.",
equalTo: "Моля, въведете същата стойност отново.",
accept: "Моля, въведете стойност с валидно разширение.",
maxlength: $.validator.format("Моля, въведете повече от {0} символа."),
minlength: $.validator.format("Моля, въведете поне {0} символа."),
rangelength: $.validator.format("Моля, въведете стойност с дължина между {0} и {1} символа."),
range: $.validator.format("Моля, въведете стойност между {0} и {1}."),
max: $.validator.format("Моля, въведете стойност по-малка или равна на {0}."),
min: $.validator.format("Моля, въведете стойност по-голяма или равна на {0}.")
}); | JavaScript |
/*
* Translated default messages for the jQuery validation plugin.
* Locale: ES
*/
jQuery.extend(jQuery.validator.messages, {
required: "Este campo es obligatorio.",
remote: "Por favor, rellena este campo.",
email: "Por favor, escribe una dirección de correo válida",
url: "Por favor, escribe una URL válida.",
date: "Por favor, escribe una fecha válida.",
dateISO: "Por favor, escribe una fecha (ISO) válida.",
number: "Por favor, escribe un número entero válido.",
digits: "Por favor, escribe sólo dígitos.",
creditcard: "Por favor, escribe un número de tarjeta válido.",
equalTo: "Por favor, escribe el mismo valor de nuevo.",
accept: "Por favor, escribe un valor con una extensión aceptada.",
maxlength: jQuery.validator.format("Por favor, no escribas más de {0} caracteres."),
minlength: jQuery.validator.format("Por favor, no escribas menos de {0} caracteres."),
rangelength: jQuery.validator.format("Por favor, escribe un valor entre {0} y {1} caracteres."),
range: jQuery.validator.format("Por favor, escribe un valor entre {0} y {1}."),
max: jQuery.validator.format("Por favor, escribe un valor menor o igual a {0}."),
min: jQuery.validator.format("Por favor, escribe un valor mayor o igual a {0}.")
}); | JavaScript |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.