TiddlyWiki5/editions/classicparserdemo/tiddlers/$__plugins_bj_Calendar.tid

31 wiersze
6.2 KiB
Plaintext

created: 20140322080900815
dependents:
description: ckeditor adapter plugin
modified: 20140322080900815
plugin-type: plugin
title: $:/plugins/bj/Calendar
type: application/json
version: 0.0.1
{
"tiddlers": {
"$:/macros/buggyj/Calendar/entry.js": {
"text": "/*\\\ntitle: $:/macros/buggyj/Calendar/entry.js\ntype: application/javascript\nmodule-type: macro\n\n<<diary year month>>\n<<diary year>> - year calendar\n<<diary>> - this month\n\nOptions:$:/macros/diary/options.json\n\\*/\n(function(){\n\n/*jslint node: true, browser: true */\n/*global $tw: false */\n\"use strict\";\n\n/*\nInformation about this macro\nCAL demo\n*/\n\nexports.name = \"calendar\";\n\nexports.params = [\n\t{ name: \"year\" },{ name: \"month\" },{ name: \"opts\" }\n];\n/*\nRun the macro\n*/\n\nexports.run = function(year, month,opts) {\nif (!opts) opts=\"default\";\nvar options = $tw.wiki.getTiddlerData(\"$:/plugins/bj/Calendar/json/config.json\")[opts]||\n\t\t\t\t{lastDayOfWeek:\"6\",formatter:\"\",titlebold:\"\",highlightThisDay:\"\",highlightThisDate:\"\"};\nvar createMonth;\ntry {\n\tcreateMonth = require(options.formatter).createMonth;\n} catch (e) {\n\tcreateMonth= function(mnth,year){\n\t\tvar month=[];\n\t\tfor (var i=1;i < 1+daysInMonth(mnth,year);i++) month[i] = i;\n\t\treturn month;\n\t}\n} \nvar boldtitle=(options.titlebold=='yes')?'!':'';\nvar day_of_week = $tw.config.dateFormats.shortDays;\nvar month_of_year = $tw.config.dateFormats.months; \nvar Calendar = new Date();\nvar thisyear = Calendar.getFullYear(); // year (xxxx)\nvar thismonth = Calendar.getMonth();\t// month (0-11)\nvar thisday = Calendar.getDay(); // day (0-6)\nvar WEEKFIN = parseInt(options.lastDayOfWeek); \nvar MONTHS_IN_YEAR=12;\t\t\t\t\t\n \nvar lf ='\\n';\nvar cal='<div>'+lf+lf; \nvar ayear=thisyear;\nif (!!month) {\n\tif (!!year) {\n\t\tcal+=calendar (month-1,year,options);\n\t} else {\n\t\tcal+=calendar (month-1,thisyear,options);\n\t}\n} else {\n\toptions.seperateYearHeading = 'yes';\n\tcal+=titleOfYear(year); \n\tif (!!year) ayear=year; \n\tfor(var i=0; i<MONTHS_IN_YEAR; i+=2)\n\t\tcal+=splicetable(calendar (i,ayear,options),calendar (i+1,ayear,options));\n}\nreturn cal+lf+lf+'</div>';\n\nfunction calendar (mnth,year,options){\n var month =\tcreateMonth(mnth,year,options);\n var blankdays = (firstDayInMonth(mnth,year)+13-WEEKFIN)%7;\n\treturn titleOfMonth(mnth,year)+createWeekHeading()+\n\t formatAsMonth(month,blankdays);\n}\nfunction titleOfMonth(mth,year) {\n\tif (!!options.seperateYearHeading ) {\n\t\treturn '|>|>|>|'+ centre(boldtitle+ month_of_year[mth]) +'|<|<|<|'+lf;\n\t} else {\n\t\treturn '|>|>|>|'+ centre(boldtitle+ month_of_year[mth] + ' ' + year) +'|<|<|<|'+lf;\n\t}\n}\n\nfunction titleOfYear(year) {\n\t\treturn '|>|>|>|>|>|>|>|'+ centre('!'+year) +'|<|<|<|<|<|<|<|'+lf;\n}\nfunction centre (x){ return ' '+x+' ';}\n\nfunction formatAsMonth(month,blankdays){\t\n\tvar theday,blank=['','|','||','|||','||||','|||||','||||||','|||||||'];\t\n\tvar cal=blank[blankdays];//pad out before first day of month\n\tfor(var i=1; i < month.length;i++){//first '0' month element is not used\n\t\tcal+='|'+month[i];\n\t\ttheday=(i+blankdays-1)%7;\n\t\tif (theday== 6) cal +='|'+lf; \n\t}\n\tcal+=blank[7-theday]+(7-theday>1?lf:'');//pad out rest of week, if no blanks then lf was added in loop\n\treturn cal ;\n}\nfunction createWeekHeading(){\n\t\tvar daystitle=[],weekdays= day_of_week.slice(0);\n\t\t// highlight today's day of week\n\t\tif (options.highlightThisDay=='yes')weekdays[thisday] ='!'+weekdays[thisday];\n\t\tfor (var i=0;i < weekdays.length; i++) daystitle[i] =centre(weekdays[(i+1+WEEKFIN)%7]);\n\t\treturn '|'+daystitle.join('|')+'|'+lf; \n}\nfunction daysInMonth(iMonth, iYear){\n\t\treturn 32 - new Date(iYear, iMonth, 32).getDate();\n\t}\nfunction firstDayInMonth(iMonth, iYear){\n\t\treturn new Date(iYear, iMonth, 1).getDay();\n\t} \nfunction splicetable (a,b) {\n\tvar i,cal='',taba =a.split('\\n'),tabb=b.split('|\\n');\n\tvar limit=(taba.length<tabb.length)?taba.length:tabb.length;//shortest\n\tfor (i=0;i<limit-1;i++) \t\tcal+=taba[i]+tabb[i]+'|'+lf;\t \n\tfor (;i < taba.length-1;i++) \tcal+=taba[i]+\"||||||||\"+lf;\n\tfor (;i < tabb.length-1;i++) \tcal+=\"||||||||\"+tabb[i]+lf;\n\treturn cal;\n}\t\t \n} \n\n})();\n",
"title": "$:/macros/buggyj/Calendar/entry.js",
"type": "application/javascript",
"module-type": "macro"
},
"$:/macros/bj/Calendar/journalfmt.js": {
"text": "/*\\\ntitle: $:/macros/bj/Calendar/journalfmt.js\ntype: application/javascript\nmodule-type: global\n\\*/\n(function(){\n\n/*jslint node: true, browser: true */\n/*global $tw: false */\n\"use strict\";\n\n/*\nInformation about this macro\ncalendar demo\n*/\nvar Calendar=new Date();\nvar createMonth= function(mnth,year,options){\n\tvar month=[];\n\tfor (var i=1;i < 1+daysInMonth(mnth,year);i++) month[i] = createDate(i,mnth,year,options);\n\treturn month;\n}\nfunction createDate(i,mnth,year,options){\n\tvar strong='';\n\tvar date=(new Date(year, mnth, i));\n\tif (date.toDateString()===Calendar.toDateString()&&options.highlightThisDate==\"yes\") strong ='!';\n\treturn centre(strong+'[['+i+'|'+date.getDate()+\n\t ' '+$tw.config.dateFormats.months[date.getMonth()]+' '+date.getFullYear()+']]');\n}\nfunction daysInMonth(iMonth, iYear){\n\t\treturn 32 - new Date(iYear, iMonth, 32).getDate();\n\t}\nfunction centre (x){ return ' '+x+' ';}\nexports.createMonth = createMonth;\n})();\n",
"title": "$:/macros/bj/Calendar/journalfmt.js",
"type": "application/javascript",
"module-type": "global"
},
"$:/plugins/bj/Calendar/json/config.json": {
"type": "application/json",
"title": "$:/plugins/bj/Calendar/json/config.json",
"module-type": "library",
"text": "\n{\n\t\"journals\":{\n\t\t\"lastDayOfWeek\":\"1\",\n\t\t\"formatter\":\"$:/macros/bj/Calendar/journalfmt.js\",\n\t\t\"titlebold\":\"no\",\n\t\t\"highlightThisDay\":\"no\",\n\t\t\"highlightThisDate\":\"yes\"\n\t},\n\t\"default\":{\n\t\t\"lastDayOfWeek\":\"2\",\n\t\t\"formatter\":\"\",\n\t\t\"titlebold\":\"yes\",\n\t\t\"highlightThisDay\":\"yes\",\n\t\t\"highlightThisDate\":\"no\"\n\t}\n}\n"
}
}
}