select default timezone in moments.js - timezone

I include moments.js in the following way
<script src="../static/js/moment-timezone-full.js"></script>
<script>
$('.select_timezone').timezones();
</script>
I then give the timezone selection to my user in the html as
<div class="row">
<div class="col-lg-4">
<select class="select_timezone" name="select_timezone"></select>
</div>
</div>
My question is how can I select a default timezone? I saw that one can do that with
moment.tz.setDefault(String);
but I don't understand how this would work in my setup?
EDIT: My implementation is just following this example...
http://www.jqueryscript.net/time-clock/Easy-Timezone-Picker-with-jQuery-Moment-js-Timezones.html
does really nobody know a solution to this?
carl
EDIT: I should clarify why moment.tz.setDefault does not work. When I add the line
moment.tz.setDefault('America/Los_Angeles');
I get the javascript error
Uncaught TypeError: Cannot read property 'setDefault' of undefined
I include moments as explained in the flask mega-tutorial meaning I do
from flask.ext.moment import Moment
...
moment = Moment()
...
moment.init_app(app)
and in my html template I do
{% block scripts %}
{{ moment.include_moment() }}
{% endblock %}
moment-timezones is included with the js file as shown above. Have I forgotten anything?
I am just trying to set the default timezone for the selection

After looking at what you have posted, it looks like you are using a jquery plugin from https://github.com/firstandthird/timezones which when I take a look at the code, it using an older version of moment.js (version 2.8.3) as seen at https://github.com/firstandthird/timezones/blob/master/dist/timezones.full.js
It is also using old versions of moment-timezone ( which it is pulling in at that bottom of the timezones.full.js file, version 0.2.4) and the moment.tz.setDefault() wasn't added until a later version. The most recent as of now is 0.4.0. So, I would recommend mashing up your own files with the most recent versions, and try it all again on your system to see if it works.
UPDATE:
So, I looked at your fiddle, and updated it at your fiddle allowing for
moment.tz.setDefault("America/New_York");
$('.select_timezone').timezones();
with my own mashed up moment.js, moment-timezone.js, and jquery plugin code, and it works just fine. Basically all that moment-timezone-full.js file is doing is mashing up the moment.js and moment-timezone.js with the jquery plugin code. (it is listed as one of the external libraries, you can find it at https://gist.github.com/iron-man/deedd9efe988318d842a as well. I did notice that it will only pick up the first timezone in the list for that offset, not the actual one you specify, but that is a bigger issue with the moment-timezone.js library and outside of the scope of this question.

By default it displays the timezone of the person looking at it, but you can override that by specifically defining it.
In your example you could do something like:
<script src="../static/js/moment-timezone-full.js"></script>
<script>
moment.tz.setDefault("America/New_York");
$('.select_timezone').timezones();
</script>

Related

In Dart how to setInnerHtml elements with <template> tag?

For example, I have a piece of code like this:
String_test="
<template>
<label> {{count2}} SSSSSSSSSSSSSSSSSSSSSSSSS </label>
<input id="input1" type='text' value='{{count2}}'>
</template>"
and I want to assign String_test to another element, like:
DivElement span2 = new Element.tag("div");
span2.setInnerHtml(String_test);
_content.nodes.add(span2);
However, the "< template >' tag is not recognized, nothing will show up.
NOTE: My purpose is to use setInnerHtml to dynamically add contents to the webpage with data-binding still OK.
Any ideas?
Thanks!
It appears that you are including raw html in your Dart program files. This is not how Dart works. Dart has code (kept in .dart files) that is referenced to via a tag in the HTML file. This very quick tutorial will show you how to do that: https://www.dartlang.org/docs/tutorials/connect-dart-html/
Templating is found in the Dart Polymer library. It is too long of a process to go into here but you can find a short tutorial at: https://www.dartlang.org/docs/tutorials/polymer-intro/
I would also mention that Angular comes in a Dart flavor and I find it more accessible than the Polymer libraries. The tutorials and documentation are also much better. Angular is a more comprehensive suite of libraries and it's tutorials can be found here: https://github.com/angular/angular.dart.tutorial/wiki

Struts2 datetimepicker size

I want to increase the size of the Calendar view because the default size is too small for my web application. I've tried to add a cssClass to the datetimepicker tag but it doesn't work, even if I change the width or height the only thing it changes is the field, not the calendar itself.
I'll put an image so you can understand better the problem that I have:
The thing is that the text from the field is correctly viewed, but when I click the calendar button, it shows that tiny view and it's extremelly difficult to pick one date.
The code for the datetimepicker is this:
<sx:datetimepicker name="start_date" displayFormat="dd-MMM-yyyy" value="%{'today'}" />
Any guess?
Ok, It's finally solved:
First I tried to find the file named datefilepicker.ftl inside the struts2-core.jar but I didn't find anything similar.
So after a few hours trying to find which was the correct template of datetimepicker without any luck, I tried to solve my problem using JQuery because when I was searching for the answer I found out a datepicker tutorial using this library.
There's a plugin called Struts2-JQuery that provides you with ajax functionality and therefore with multiple customizations in different widgets.
It's quite easy to install, I just had to download the correct .jar which for me it was Version 3.5.1 ( jQuery 1.8.3, jQuery UI 1.9.2 ). Once I'd downloaded the file, I just had to paste it in the lib folder inside my project. After doing that, I added this line at the beginning of the .jsp file:
<%# taglib prefix="sj" uri="/struts-jquery-tags"%>
With these steps I had jquery functionality inside my .jsp file, so the only thing left to do is to add the datepicker widget:
First I chose the jquerytheme I wanted for my widget, just like this:
<head>
<sj:head jquerytheme="flick"/>
...
</head>
And then, I added my datepicker widget:
<sj:datepicker name="start_date" displayFormat="dd-MM-yy" value="today"/>
And that's it.
If you want to resize the datepicker calendar see the answer of this post:
How to resize the jQuery DatePicker control
<sx:datetimepicker name="start_date" displayFormat="dd-MMM-yyyy" value="%{'today'}" />
It is a dojo tag, so you should be changing the template file corresponding to this tag
Freemarker changes
check for something like datetimepicker.ftl in your workspace. That would be the file rendering your calendar. Any presentation related changes will be done in that file only.
debug using firebug
Another approach can be using firebug in Mozilla firefox and manually try to change the html rendered by the tag. There might lie some CSS solution to your problem

jQueryMobile data-dismissible in version 1.2

jqm's data-dismissible attribute will be released in version 1.3 as stated here, although it's already implemented.
The thing is I need to have this feature in my project now, so can someone please explain how do I incorporate only this attribute support? Can I still link to the CDN and somehow "add" this piece of code or their is no other way but to download the whole "master" branch and then link the files from my server?
This is how I did it in the end:
I found the code that needs to be changed:
So, I downloaded the uncompressed version from the jQuery CDN, then I edited the lines as shown in the image, compressed the js file and uploaded it to my site. Now, I can use the popups like this:
<div data-role="popup"
id="popupLogin"
data-theme="a"
class="ui-corner-all"
data-dismissible="false">
All happy!
I used Nikola's answer, but changed the if-statement to check the data's dismissible attribute value:
if ( this.element.data('dismissible') ) {
this.close();
}

jQuery Mobile Losing Style After Updating DOM

A question similar to this has been posted several time, but I cannot find a solution that works. Hopefully, someone can help!
I am using jQuery Mobile 1.1 and jQuery 1.7.2, so I'm on the most recent stable releases. I want to create a dynamic page header. Using this HTML code, it works fine:
<div data-role="page" id="levela">
<div data-role="header" id="hdr_levela">
<h1>Title</h1>
</div>
</div>
So I then go to dynamically create the title. I change the HTML to this:
<div data-role="page" id="levela">
<div data-role="header" id="hdr_levela">
</div>
</div>
And added the following jQuery code:
// Set the header
var dirHeader = $('#hdr_levela');
dirHeader.append('<h1>' + title+ '</h1>');
The title appears, but is not styled. I have found several posts about this. In the jQuery Mobile Documentation, it says:
"However, if you generate new markup client-side or load in content via Ajax and inject it into a page, you can trigger the create event to handle the auto-initialization for all the plugins contained within the new markup. This can be triggered on any element (even the page div itself), saving you the task of manually initializing each plugin (listview button, select, etc.).
For example, if a block of HTML markup (say a login form) was loaded in through Ajax, trigger the create event to automatically transform all the widgets it contains (inputs and buttons in this case) into the enhanced versions. The code for this scenario would be:
$( ...new markup that contains widgets... ).appendTo( ".ui-page" ).trigger( "create" );
So I tried several things. After the above code, I added the following:
dirHeader.trigger("create");
This had no effect. So I tried to put it on the actual append itself:
dirHeader.append('<h1>' + folderName + '</h1>').trigger("create");
This had no effect. I then tried the process on the parent element (in this case, the id of the parent div is "levela"). So I tried this:
$('#levela').trigger("create");
This also had no effect. At this point, I am completely lost. Every solution involves doing one of the things I have tried and is just not working. I must be missing something incredibly basic but I just can't seem to find it.
Thanks in advance for your help!
You can update the content by calling .page:
See this working Fiddle Example!
// Set the header
var title = 'super hyper BuBu',
$dirHeader = $('#hdr_levela');
$dirHeader.append('<h1>' + title+ '</h1>').page();
I just solved a similar problem -- it appears that jQM headers and footers do not have the "create" method, so as far as I can tell, the css classes and roles need to be added manually.
For reference, I posted an example fix on this (old) question: JQuery Mobile trigger('create') command not working

Emberjs and jQuery UI integration questions

I am trying to understand how the integration between jQueryUI and Emberjs should be done. I am new to both libs and to javascript so this might be a newbie question.
I have this jsfiddle set up: http://jsfiddle.net/pSKgV/1/ and it renders this resulting document:
<body class="ember-application">
<div id="ember129" class="ember-view">
<div id="ember163" class="ember-view ui-draggable"></div>
</div>
</body>
The code is mostly taken from this blog post: http://www.lukemelia.com/blog/archives/2012/03/10/using-ember-js-with-jquery-ui/
Questions: How do I put something inside the inner div? I want to put some content that i can bind to something.
I have tried the following:
{{view App.Draggable}}Drag Me{{/view}} but that gives an error. I’ve also tried
adding this to the App.Draggable object:
didInsertElement: function() {
this.$().html(“Drag Me”)
}
but that did not give the expected results. How is the best way to use/access the jquery/jqueryui functions such as .html() in this situation?
Also, is the outer div necessary or can I make this view only render one div element?
regards
Oskar
http://jsfiddle.net/ud3323/XMgwV/
You forget the # symbol {{#view App.Draggable}}Drag me{{/view}}. You should also create namespaces in Ember using Ember.Namespace.create() instead of just using an empty {}

Resources