How to trigger javascript functions in the resourcesFolder on a special day


(Olof Pock) #1

I’d like to trigger functions on various days.
How can i get the date and call then a javascript snippet in the resourcesFolder for that day?

Any help would be greatly appreciated

Olof


(Hans-Gerd Claßen) #2
    setDateString()//2015_6_25


function setDateString() {
var now = new Date();
var day = now.getDate();
var month = now.getMonth() +1;
var year = now.getFullYear();
var dateString = year.toString() + '_' + month.toString() +  '_' + day.toString();
return dateString;
}

this’ll return a datestring

so if you’ve got a list

var myDates = ['2015_6_25', '2015_6_29', '2015_6_31', ...]

you can check against it and run a function


(Olof Pock) #3

Hi Hans,

thanks for your quick response. This datestring is very helpful.
But whats is the right notation to run a function from the resourcesFolder?

For example 2015_6_25 is true then run my function e3 within my resourcesFolder.

Olof


(Olof Pock) #4

Hi Hans,

i was a little bit confused and tired yesterday.
So now I came up with this:

	setDateString()//2015_6_25


function setDateString() {
var now = new Date();
var day = now.getDate();
var month = now.getMonth() +1;
var year = now.getFullYear();
var dateString = year.toString() + '_' + month.toString() +  '_' + day.toString();
return dateString;
}

var myDates = ['2015_6_26', '2015_7_4', '2015_7_5', '2015_7_6', '2015_7_7','2015_7_8','2015_7_9','2015_7_10','2015_7_11','2015_7_12','2015_7_13','2015_7_14','2015_7_15','2015_7_16','2015_7_17','2015_7_18','2015_7_19','2015_7_20','2015_7_21']
	{

if (myDates == '2015_6_23');

hypeDocument.functions().d1(hypeDocument, element, event);

};
	{

if (myDates == '2015_6_26');

hypeDocument.functions().d2(hypeDocument, element, event);

}

Code can be written maybe more clean. But for the moment it worked for me.

Thanks for helping me with that.

Olof


#5

Moment.js is a great way to work with dates. Here’s a quick example:

Run this in the of your document:

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.3/moment.min.js"></script>

(The latest can be found here: http://cdnjs.com/libraries/moment.js/ )

Then, run this as an ‘on scene load’ for the scene where you running this calculation:

var month = moment().format("M");
var day = moment().date();
var year = moment().format("YYYY");

if (day == 04 && month == 7 && year == 2015 )
 {
 hypeDocument.functions().e01(hypeDocument, element, event);
   }
 if (day == 05 && month == 6 && year == 2015)
 {
 hypeDocument.functions().e02(hypeDocument, element, event);
 }
 
 else
 {
hypeDocument.functions().setup(hypeDocument, element, event);
 }

dateexample.zip (24.4 KB)

More info about this library: http://momentjs.com/docs/#/parsing/

If you wanted to determine if a time is between certain hours, you would detect the time, set a range, and run a conditional based on that range:

var format = 'hh:mm:ss'
var time = moment();
  beforeTime = moment('08:34:00', format);
  afterTime = moment('10:34:00', format);

if (time.isBetween(beforeTime, afterTime)) {

  console.log('is between 8:34 am and 10:34 am')

} else {

  console.log('is not between 8:34am and 10:34 am')

}

Knowledge base: Guides from the Tumult Team
Variable in Hype
Limit Time For Visits On My Page
Automated calendar kiosk
(Olof Pock) #6

very cool. thank you…


(Olof Pock) #7

Hi Daniel,
I got an error when i try your example.
console says on line 5:
Left hand side of operator ‘=’ must be a reference.

and
TypeError: undefined is not an object (evaluating ‘a.defineLocale’)
(anonyme Funktion)locales.min.js:75
index_hype_generated_script.js:5:58161

Any ideas?


#8

My mistake – It should have been ‘==’ and not just ‘=’.

Here’s an example doc: dateexample.zip (24.4 KB)


(Olof Pock) #9

Thanks Daniel,

i get it working.

#yeah

Olof

var month = moment().format("M");
var day = moment().date();
var year = moment().format("YYYY");

if (day == 04 && month == 7 && year == 2015 )
 {
 hypeDocument.functions().e01(hypeDocument, element, event);
   }
 if (day == 05 && month == 6 && year == 2015)
 {
 hypeDocument.functions().e02(hypeDocument, element, event);
 }
 
 else
 {
hypeDocument.functions().setup(hypeDocument, element, event);
 }

(Olli) #10

Hello,
i try to do this with Scenes, but it doesnt work .
I have 5 scenes wich will be displayed on special dates.

I 've tried several things (commented out in the following code) with timeline and Scenes.
Where are my fault?
The first Scene should shown ever at start and again after the end.
The Second only the first 3 days in the month,
The third only the first 18 days and so on.

Here are my Code and what i tried.

 if (month == 3 && year == 2017 )
 {
  //hypeDocument.showSceneNamed('sc1', hypeDocument.kSceneTransitionCrossfade, 1.1)
  //hypeDocument.pauseTimelineNamed('Hauptzeitsachse')
  //hypeDocument.showNextScene(hypeDocument.kSceneTransitionCrossfade, 1.1)
  //hypeDocument.startTimelineNamed('Hauptzeitsachse');
  //hypeDocument.showNextScene(hypeDocument.kSceneTransitionCrossfade, 1.1)
 }
 
 if (day <=3  && month == 3 && year == 2017 )
 {
  //hypeDocument.continueTimelineNamed('Hauptzeitsachse', hypeDocument.kDirectionForward, false)
  
  //hypeDocument.showSceneNamed('sc2', hypeDocument.kSceneTransitionCrossfade, 1.1)
  //hypeDocument.startTimelineNamed('sc2');
  //hypeDocument.showNextScene(hypeDocument.kSceneTransitionCrossfade, 1.1)
  //hypeDocument.pauseTimelineNamed('Hauptzeitsachse')
 }
 
 if (day <= 18 && month == 3 && year == 2017 )
 {
  
  //hypeDocument.showSceneNamed('sc2', hypeDocument.kSceneTransitionCrossfade, 1.1)

  //hypeDocument.startTimelineNamed('sc3');
  //hypeDocument.showNextScene(hypeDocument.kSceneTransitionCrossfade, 1.1)

 }
 
 if (day <= 25 && month == 3 && year == 2017 )
 {
  //hypeDocument.startTimelineNamed('sc4');
 }
 
 if ((month == 3 && year == 2017 ) || (day <= 8 && month == 4 && year == 2017 ))
 {
  //hypeDocument.startTimelineNamed('sc5');

 }

Thanks a lot or help.
Best regards
Olli


(Mark Hunte) #11

Off the bat I see a problem with

if (day <= 18 && month == 3 && year == 2017 )
 {
  
  //hypeDocument.showSceneNamed('sc2', hypeDocument.kSceneTransitionCrossfade, 1.1)

  //hypeDocument.startTimelineNamed('sc3');
  //hypeDocument.showNextScene(hypeDocument.kSceneTransitionCrossfade, 1.1)

 }
 
 if (day <= 25 && month == 3 && year == 2017 )
 {
  //hypeDocument.startTimelineNamed('sc4');
 }

This is always going to fall through the code down to the 25th code. The 18th code is breifly going to fire but will be superseeded by the next IF block.

There are fixes to this like using return statments but to be honest it will be easier for people to help you if you post the project with your code.


(Olli) #12

Thanks a lot.
I ve solved the problem in an other way. I write the same in PHP and include depends on date other complete Hype Documents.
It is not the best solution for me but in works.

I try to solve it in Hype 3 too.

Best Regards
Olli


(Olof Pock) #13

Hey Oli,

was to busy last week to provide you with a proper example.
In my example a specific
scene will loaded on a specific day… hope it helps.

dateToSceneWithMomentJS.zip (61.1 KB)

Olof


(Olli) #14

Many Thanks, i try it in the next few days