WD Google Analytics - Version 1.0.6

Version Description

Fixed: User guide links
Fixed: Bug on datepicker
Fixed: Error when deleting the web property
Added: Validation on the form for adding goals

Download this release

Release Info

Developer webdorado
Plugin Icon 128x128 WD Google Analytics
Version 1.0.6
Comparing to
See all releases

Code changes from version 1.0.5 to 1.0.6

admin/gawd_google_class.php CHANGED
@@ -30,7 +30,7 @@ class GAWD_google_client {
30
  */
31
  private function set_google_client() {
32
 
33
- $access_token = $this->gawd_user_data['access_token'];
34
  $this->google_client->setAccessToken($access_token);
35
 
36
  if ($this->google_client->isAccessTokenExpired()) {
30
  */
31
  private function set_google_client() {
32
 
33
+ $access_token = isset($this->gawd_user_data['access_token']) ? $this->gawd_user_data['access_token'] : '' ;
34
  $this->google_client->setAccessToken($access_token);
35
 
36
  if ($this->google_client->isAccessTokenExpired()) {
admin/pages/custom_reports.php CHANGED
@@ -1,6 +1,6 @@
1
  <div style="font-size: 14px; font-weight: bold; margin:15px 0">
2
- This section lets add and manage custom reports. Read more in User Guide.
3
- <a style="color: #00A0D2; text-decoration: none;" target="_blank" href="https://web-dorado.com/wordpress-google-analytics/custom-reports.html">Read More in User Manual.</a>
4
  </div>
5
  <img style="margin-top:10px" src="<?php echo GAWD_URL . '/assets/freePages/custom_reports.png';?>"/>
6
 
1
  <div style="font-size: 14px; font-weight: bold; margin:15px 0">
2
+ This section lets add and manage custom reports.
3
+ <a style="color: #00A0D2; text-decoration: none;" target="_blank" href="https://web-dorado.com/wordpress-google-analytics/custom-reports.html">Read more in User Guide.</a>
4
  </div>
5
  <img style="margin-top:10px" src="<?php echo GAWD_URL . '/assets/freePages/custom_reports.png';?>"/>
6
 
admin/pages/dashboard.php CHANGED
@@ -16,8 +16,8 @@ if($current_user != 1 && isset($saved_user_menues[$current_user])){
16
  }
17
  ?>
18
  <div style="font-size: 14px; font-weight: bold; margin:15px 0">
19
- Keep track of all Google Analytics reports on this page. Read more in User Guide.
20
- <a style="color: #00A0D2; text-decoration: none;" target="_blank" href="https://web-dorado.com/wordpress-google-analytics/reports.html">Read More in User Manual.</a>
21
  </div>
22
  <form method="post" id="gawd_view">
23
 
@@ -542,8 +542,8 @@ if($current_user != 1 && isset($saved_user_menues[$current_user])){
542
  <div id="gawd_buttons">
543
  <span id="country_filter_reset" class="button_gawd">Back</span>
544
  <span class='clear'></span>
545
- <input class="button_gawd" type="button" id="gawd_export_buttons" value="EXPORT"/>
546
- <input class="button_gawd load_tooltip" type="button" id="gawd_email_button" data-hint="Click to forward this report to selected email recipients, or schedule emails to be sent out periodically." value="EMAIL"/>
547
  <div class="gawd_exports">
548
  <a class='button gawd_export_button_csv' href="">CSV</a>
549
  <a class='button gawd_export_button_pdf' href="#">PDF</a>
16
  }
17
  ?>
18
  <div style="font-size: 14px; font-weight: bold; margin:15px 0">
19
+ Keep track of all Google Analytics reports on this page.
20
+ <a style="color: #00A0D2; text-decoration: none;" target="_blank" href="https://web-dorado.com/wordpress-google-analytics/reports.html">Read more in User Guide.</a>
21
  </div>
22
  <form method="post" id="gawd_view">
23
 
542
  <div id="gawd_buttons">
543
  <span id="country_filter_reset" class="button_gawd">Back</span>
544
  <span class='clear'></span>
545
+ <input class="button_gawd" type="button" id="gawd_export_buttons" value="Export"/>
546
+ <input class="button_gawd load_tooltip" type="button" id="gawd_email_button" data-hint="Click to forward this report to selected email recipients, or schedule emails to be sent out periodically." value="Email"/>
547
  <div class="gawd_exports">
548
  <a class='button gawd_export_button_csv' href="">CSV</a>
549
  <a class='button gawd_export_button_pdf' href="#">PDF</a>
admin/pages/goals.php CHANGED
@@ -17,8 +17,8 @@ if (!is_array($goals)) {
17
  ?>
18
  <div class="goal_wrap">
19
  <div style="font-size: 14px; font-weight: bold; margin:15px 0">
20
- This section allows you to add Google Analytics goals for current domain. Read more in User Guide.
21
- <a style="color: #00A0D2; text-decoration: none;" target="_blank" href="https://web-dorado.com/wordpress-google-analytics/goal-management.html">Read More in User Manual.</a>
22
  </div>
23
  <h3 class="gawd_page_titles">Goal Management</h3>
24
 
@@ -260,12 +260,42 @@ if (!is_array($goals)) {
260
  }
261
  });
262
  jQuery('.button_gawd').on('click',function(){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
263
  if(jQuery('.gawd_table tr').length -1 >= 20){
264
  alert('You have reached the maximum number of goals.')
265
  return;
266
  }
267
  jQuery('#goal_max_id').val(jQuery('.gawd_rows').length);
268
- jQuery('#gawd_goal_form').submit();
 
 
 
269
  });
270
  jQuery('.gawd_goal_profile').on('change', function(){
271
  jQuery('.gawd_table').each(function(){
17
  ?>
18
  <div class="goal_wrap">
19
  <div style="font-size: 14px; font-weight: bold; margin:15px 0">
20
+ This section allows you to add Google Analytics goals for current domain.
21
+ <a style="color: #00A0D2; text-decoration: none;" target="_blank" href="https://web-dorado.com/wordpress-google-analytics/goal-management.html">Read more in User Guide.</a>
22
  </div>
23
  <h3 class="gawd_page_titles">Goal Management</h3>
24
 
260
  }
261
  });
262
  jQuery('.button_gawd').on('click',function(){
263
+ var submit_form = true;
264
+ var gawd_goal_name = jQuery("#gawd_goal_name");
265
+ var gawd_goal_name = jQuery("#gawd_goal_name");
266
+ if(gawd_goal_name.val()=== ""){
267
+ gawd_goal_name.addClass('gawd_invalid');
268
+ submit_form = false;
269
+ }
270
+ else if(
271
+ (jQuery('input[name="gawd_page_sessions"]').val() === '' && jQuery('.gawd_goal_type :selected').val() == 'VISIT_NUM_PAGES') ||
272
+ (jQuery('input[name="gawd_page_url"]').val() === '' && jQuery('.gawd_goal_type :selected').val() == 'URL_DESTINATION') ||
273
+ ((jQuery('input[name="gawd_visit_hour"]').val() === '' || jQuery('input[name="gawd_visit_minute"]').val() === '' || jQuery('input[name="gawd_visit_second"]').val() === '') && jQuery('.gawd_goal_type :selected').val() == 'VISIT_TIME_ON_SITE')){
274
+ jQuery('input[name="gawd_page_url"]').addClass('gawd_invalid');
275
+ jQuery('input[name="gawd_page_sessions"]').addClass('gawd_invalid');
276
+ jQuery('input[name="gawd_visit_hour"]').addClass('gawd_invalid');
277
+ jQuery('input[name="gawd_visit_minute"]').addClass('gawd_invalid');
278
+ jQuery('input[name="gawd_visit_second"]').addClass('gawd_invalid');
279
+ submit_form = false;
280
+ }
281
+ else{
282
+ gawd_goal_name.removeClass('gawd_invalid');
283
+ jQuery('input[name="gawd_page_url"]').removeClass('gawd_invalid');
284
+ jQuery('input[name="gawd_page_sessions"]').removeClass('gawd_invalid');
285
+ jQuery('input[name="gawd_visit_hour"]').removeClass('gawd_invalid');
286
+ jQuery('input[name="gawd_visit_minute"]').removeClass('gawd_invalid');
287
+ jQuery('input[name="gawd_visit_second"]').removeClass('gawd_invalid');
288
+ }
289
+
290
  if(jQuery('.gawd_table tr').length -1 >= 20){
291
  alert('You have reached the maximum number of goals.')
292
  return;
293
  }
294
  jQuery('#goal_max_id').val(jQuery('.gawd_rows').length);
295
+ if(submit_form){
296
+ jQuery('#gawd_goal_form').submit();
297
+ return false;
298
+ }
299
  });
300
  jQuery('.gawd_goal_profile').on('change', function(){
301
  jQuery('.gawd_table').each(function(){
admin/pages/overview.php CHANGED
@@ -13,8 +13,8 @@ $new_buttons_full = '<button data-hint="Click to navigate to Real Time report on
13
 
14
  <?php screen_icon('options-general'); ?>
15
  <div style="font-size: 14px; font-weight: bold; margin:15px 0">
16
- This section lets you check the audience overview of your website. Read more in User Guide.
17
- <a style="color: #00A0D2; text-decoration: none;" target="_blank" href="https://web-dorado.com/wordpress-google-analytics/quick-start/overview.html">Read More in User Manual.</a>
18
  </div>
19
  <h2 style="margin-top:10px" class="gawd_page_titles"><?php echo get_admin_page_title(); ?></h2>
20
  <div class="gawd_wrap">
13
 
14
  <?php screen_icon('options-general'); ?>
15
  <div style="font-size: 14px; font-weight: bold; margin:15px 0">
16
+ This section lets you check the audience overview of your website.
17
+ <a style="color: #00A0D2; text-decoration: none;" target="_blank" href="https://web-dorado.com/wordpress-google-analytics/quick-start/overview.html">Read more in User Guide.</a>
18
  </div>
19
  <h2 style="margin-top:10px" class="gawd_page_titles"><?php echo get_admin_page_title(); ?></h2>
20
  <div class="gawd_wrap">
admin/pages/settings.php CHANGED
@@ -43,8 +43,8 @@ $post_page_chart = isset($gawd_settings['post_page_chart']) ? $gawd_settings['po
43
 
44
  <div id="gawd_body">
45
  <div style="font-size: 14px; font-weight: bold; margin:15px 0">
46
- Authenticate your Google account and customize Google Analytics settings in this section. Read more in User Guide.
47
- <a style="color: #00A0D2; text-decoration: none;" target="_blank" href="https://web-dorado.com/wordpress-google-analytics/settings.html">Read More in User Manual.</a>
48
  </div>
49
  <div class="resp_menu"><div class="menu_img"></div><div class="button_label">SETTINGS</div><div class="clear"></div></div>
50
  <div class="gawd_menu_coteiner gawd_settings_menu_coteiner">
@@ -103,7 +103,7 @@ $post_page_chart = isset($gawd_settings['post_page_chart']) ? $gawd_settings['po
103
  <div class="gawd_goal_input">
104
  <input type="text" value="<?php echo isset($own_cliend_id) ? $own_cliend_id : '';?>" name="gawd_own_client_id"/>
105
  </div>
106
- <div class="gawd_info" title="Paste Client ID key. For more information about getting project keys please check the plugin documentation."></div>
107
  <div class='clear'></div>
108
  </div>
109
  <div class="gawd_goal_row">
@@ -111,7 +111,7 @@ $post_page_chart = isset($gawd_settings['post_page_chart']) ? $gawd_settings['po
111
  <div class="gawd_goal_input">
112
  <input type="text" value="<?php echo isset($own_cliend_secret) ? $own_cliend_secret : '';?>" name="gawd_own_client_secret"/>
113
  </div>
114
- <div class="gawd_info" title="Paste Client Secret key. For more information about getting project keys please check the plugin documentation."></div>
115
  <div class='clear'></div>
116
  </div>
117
  </div>
@@ -322,7 +322,7 @@ $post_page_chart = isset($gawd_settings['post_page_chart']) ? $gawd_settings['po
322
  <span class="onoffswitch-switch"></span>
323
  </label>
324
  </div>
325
- <div class="gawd_info" title="Turn this option on to get AdSense tracking reports. Make sure to link your Google AdSense to Google Analytics first (find out more in plugin documentation)"></div>
326
  <div class="onoffswitch_text">
327
  Enable AdSense link tracking <a target="_blank" href="https://web-dorado.com/products/wordpress-google-analytics-plugin.html" class="gawd_pro"> ( This feature is available in Google Analytics WD Pro. )</a>
328
  </div>
@@ -533,7 +533,7 @@ $post_page_chart = isset($gawd_settings['post_page_chart']) ? $gawd_settings['po
533
  </div>
534
  </div>
535
  <div class="gawd_submit">
536
- <input type="button" class="button_gawd" id="gawd_settings_button"value="SAVE"/>
537
  <input type="button" style="display:none;" class="button_gawd" id="gawd_settings_logout"value="Logout"/>
538
  </div>
539
  <input type='hidden' name="gawd_alert_remove" id="gawd_alert_remove"/>
43
 
44
  <div id="gawd_body">
45
  <div style="font-size: 14px; font-weight: bold; margin:15px 0">
46
+ Authenticate your Google account and customize Google Analytics settings in this section.
47
+ <a style="color: #00A0D2; text-decoration: none;" target="_blank" href="https://web-dorado.com/wordpress-google-analytics/settings.html">Read more in User Guide.</a>
48
  </div>
49
  <div class="resp_menu"><div class="menu_img"></div><div class="button_label">SETTINGS</div><div class="clear"></div></div>
50
  <div class="gawd_menu_coteiner gawd_settings_menu_coteiner">
103
  <div class="gawd_goal_input">
104
  <input type="text" value="<?php echo isset($own_cliend_id) ? $own_cliend_id : '';?>" name="gawd_own_client_id"/>
105
  </div>
106
+ <div class="gawd_info" title="Paste Client ID key. For more information about getting project keys please check the plugin User Guide."></div>
107
  <div class='clear'></div>
108
  </div>
109
  <div class="gawd_goal_row">
111
  <div class="gawd_goal_input">
112
  <input type="text" value="<?php echo isset($own_cliend_secret) ? $own_cliend_secret : '';?>" name="gawd_own_client_secret"/>
113
  </div>
114
+ <div class="gawd_info" title="Paste Client Secret key. For more information about getting project keys please check the plugin User Guide."></div>
115
  <div class='clear'></div>
116
  </div>
117
  </div>
322
  <span class="onoffswitch-switch"></span>
323
  </label>
324
  </div>
325
+ <div class="gawd_info" title="Turn this option on to get AdSense tracking reports. Make sure to link your Google AdSense to Google Analytics first (find out more in plugin User Guide)"></div>
326
  <div class="onoffswitch_text">
327
  Enable AdSense link tracking <a target="_blank" href="https://web-dorado.com/products/wordpress-google-analytics-plugin.html" class="gawd_pro"> ( This feature is available in Google Analytics WD Pro. )</a>
328
  </div>
533
  </div>
534
  </div>
535
  <div class="gawd_submit">
536
+ <input type="button" class="button_gawd" id="gawd_settings_button"value="Save"/>
537
  <input type="button" style="display:none;" class="button_gawd" id="gawd_settings_logout"value="Logout"/>
538
  </div>
539
  <input type='hidden' name="gawd_alert_remove" id="gawd_alert_remove"/>
admin/pages/tracking.php CHANGED
@@ -28,8 +28,8 @@ $domain = GAWD::get_domain(esc_html(get_option('siteurl')));
28
 
29
  <div id="gawd_body">
30
  <div style="font-size: 14px; font-weight: bold; margin:15px 0">
31
- Create a web property and manage tracking settings in this section. Read more in User Guide.
32
- <a style="color: #00A0D2; text-decoration: none;" target="_blank" href="https://web-dorado.com/wordpress-google-analytics/tracking.html">Read More in User Manual.</a>
33
  </div>
34
  <div class="resp_menu"><div class="menu_img"></div><div class="button_label">TRACKING</div><div class="clear"></div></div>
35
  <div class="gawd_menu_coteiner gawd_settings_menu_coteiner">
@@ -85,7 +85,7 @@ $domain = GAWD::get_domain(esc_html(get_option('siteurl')));
85
  <span class="onoffswitch-switch"></span>
86
  </label>
87
  </div>
88
- <div class="gawd_info" title="Enable this option to track multiple links with the same destination. Get information for buttons, menus, as well as elements with multiple destinations, e.g. search boxes. You can find out more about Enhanced Link Attribution in the plugin documentation."></div>
89
  <div class="onoffswitch_text">
90
  Enhanced Link Attribution
91
  </div>
28
 
29
  <div id="gawd_body">
30
  <div style="font-size: 14px; font-weight: bold; margin:15px 0">
31
+ Create a web property and manage tracking settings in this section.
32
+ <a style="color: #00A0D2; text-decoration: none;" target="_blank" href="https://web-dorado.com/wordpress-google-analytics/tracking.html">Read more in User Guide.</a>
33
  </div>
34
  <div class="resp_menu"><div class="menu_img"></div><div class="button_label">TRACKING</div><div class="clear"></div></div>
35
  <div class="gawd_menu_coteiner gawd_settings_menu_coteiner">
85
  <span class="onoffswitch-switch"></span>
86
  </label>
87
  </div>
88
+ <div class="gawd_info" title="Enable this option to track multiple links with the same destination. Get information for buttons, menus, as well as elements with multiple destinations, e.g. search boxes. You can find out more about Enhanced Link Attribution in the plugin User Guide."></div>
89
  <div class="onoffswitch_text">
90
  Enhanced Link Attribution
91
  </div>
assets/freePages/alerts.png CHANGED
Binary file
assets/freePages/custom_dimensions.png CHANGED
Binary file
assets/freePages/custom_reports.png CHANGED
Binary file
assets/freePages/exclude_tracking.png CHANGED
Binary file
assets/freePages/pushovers.png CHANGED
Binary file
gawd_class.php CHANGED
@@ -51,6 +51,10 @@ class GAWD {
51
  add_action( 'gawd_email_gawd_monthly', array( $this, 'gawd_monthly_email' ) );
52
  //add_action('init', array($this, 'gawd_daily_email'));
53
  add_action( 'wp_head', array( $this, 'gawd_tracking_code' ), 99 );
 
 
 
 
54
  $gawd_settings = get_option( 'gawd_settings' );
55
  $gawd_post_page_roles = isset( $gawd_settings['gawd_post_page_roles'] ) ? $gawd_settings['gawd_post_page_roles'] : array();
56
  $roles = $this->get_current_user_role();
@@ -1200,7 +1204,8 @@ class GAWD {
1200
  global $gawd_user_data;
1201
  if ( isset( $gawd_user_data['default_webPropertyId'] ) && $gawd_user_data['default_webPropertyId'] ) {
1202
  return 'done';
1203
- } else {
 
1204
  $gawd_client = GAWD_google_client::get_instance();
1205
  $property = $gawd_client->property_exists();
1206
  if ( $property == 'no_matches' ) {
@@ -1233,7 +1238,7 @@ class GAWD {
1233
  </div>
1234
  <div class='gawd_add_prop gawd_submit'>
1235
  <a href='" . admin_url() . "admin.php?page=gawd_analytics' class='gawd_later button_gawd'>Later</a>
1236
- <input type='button' id='gawd_add_property' class='button_gawd' value='ADD'/>
1237
  <input type='hidden' id='add_property' name='add_property'/>
1238
  </div>
1239
  </form>";
@@ -1629,6 +1634,7 @@ class GAWD {
1629
  //echo '<script>window.location.href="'.$redirect_url.'";</script>';
1630
  return;
1631
  }
 
1632
 
1633
  if ( $add_dimension_value == 'add_dimension_Logged_in' ) {
1634
  $id = isset( $_POST['gawd_custom_dimension_id'] ) ? ( $_POST['gawd_custom_dimension_id'] + 1 ) : 1;
@@ -1718,7 +1724,6 @@ class GAWD {
1718
  }
1719
  $gawd_excluded_roles = isset( $_POST['gawd_excluded_roles'] ) ? $_POST['gawd_excluded_roles'] : array();
1720
  $gawd_excluded_users = isset( $_POST['gawd_excluded_users'] ) ? $_POST['gawd_excluded_users'] : array();
1721
- $gawd_settings = get_option( 'gawd_settings' );
1722
  $gawd_settings['gawd_file_formats'] = $gawd_file_formats;
1723
  $gawd_settings['gawd_anonymize'] = $gawd_anonymize;
1724
  $gawd_settings['gawd_file_formats'] = $gawd_file_formats;
@@ -1734,7 +1739,6 @@ class GAWD {
1734
  $this->gawd_admin_notice( 'Your changes have been saved successfully.', 'success is-dismissible' );
1735
  }
1736
  delete_option( 'gawd_save_tracking' );
1737
- $gawd_settings = get_option( 'gawd_settings' );
1738
  if ( $add_dimension_value != '' ) {
1739
  $redirect_url = admin_url() . 'admin.php?page=gawd_tracking';
1740
  echo '<script>window.location.href="' . $redirect_url . '";</script>';
@@ -2237,6 +2241,7 @@ class GAWD {
2237
  update_option( 'gawd_menu_items', $tabs );
2238
  }
2239
 
 
2240
  public function remove_zoom_message() {
2241
  check_ajax_referer( 'gawd_admin_page_nonce', 'security' );
2242
  $got_it = isset( $_REQUEST["got_it"] ) ? sanitize_text_field( $_REQUEST["got_it"] ) : '';
@@ -2244,6 +2249,25 @@ class GAWD {
2244
  add_option( 'gawd_zoom_message', $got_it );
2245
  }
2246
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2247
  /**
2248
  * Checks if the protocol is secure.
2249
  *
51
  add_action( 'gawd_email_gawd_monthly', array( $this, 'gawd_monthly_email' ) );
52
  //add_action('init', array($this, 'gawd_daily_email'));
53
  add_action( 'wp_head', array( $this, 'gawd_tracking_code' ), 99 );
54
+ include_once(GAWD_DIR . '/include/gawd-notices-class.php');
55
+
56
+ add_action( 'admin_notices', array( $this, 'check_property_delete' ));
57
+
58
  $gawd_settings = get_option( 'gawd_settings' );
59
  $gawd_post_page_roles = isset( $gawd_settings['gawd_post_page_roles'] ) ? $gawd_settings['gawd_post_page_roles'] : array();
60
  $roles = $this->get_current_user_role();
1204
  global $gawd_user_data;
1205
  if ( isset( $gawd_user_data['default_webPropertyId'] ) && $gawd_user_data['default_webPropertyId'] ) {
1206
  return 'done';
1207
+ }
1208
+ else {
1209
  $gawd_client = GAWD_google_client::get_instance();
1210
  $property = $gawd_client->property_exists();
1211
  if ( $property == 'no_matches' ) {
1238
  </div>
1239
  <div class='gawd_add_prop gawd_submit'>
1240
  <a href='" . admin_url() . "admin.php?page=gawd_analytics' class='gawd_later button_gawd'>Later</a>
1241
+ <input type='button' id='gawd_add_property' class='button_gawd' value='Add'/>
1242
  <input type='hidden' id='add_property' name='add_property'/>
1243
  </div>
1244
  </form>";
1634
  //echo '<script>window.location.href="'.$redirect_url.'";</script>';
1635
  return;
1636
  }
1637
+ $gawd_settings = get_option( 'gawd_settings' );
1638
 
1639
  if ( $add_dimension_value == 'add_dimension_Logged_in' ) {
1640
  $id = isset( $_POST['gawd_custom_dimension_id'] ) ? ( $_POST['gawd_custom_dimension_id'] + 1 ) : 1;
1724
  }
1725
  $gawd_excluded_roles = isset( $_POST['gawd_excluded_roles'] ) ? $_POST['gawd_excluded_roles'] : array();
1726
  $gawd_excluded_users = isset( $_POST['gawd_excluded_users'] ) ? $_POST['gawd_excluded_users'] : array();
 
1727
  $gawd_settings['gawd_file_formats'] = $gawd_file_formats;
1728
  $gawd_settings['gawd_anonymize'] = $gawd_anonymize;
1729
  $gawd_settings['gawd_file_formats'] = $gawd_file_formats;
1739
  $this->gawd_admin_notice( 'Your changes have been saved successfully.', 'success is-dismissible' );
1740
  }
1741
  delete_option( 'gawd_save_tracking' );
 
1742
  if ( $add_dimension_value != '' ) {
1743
  $redirect_url = admin_url() . 'admin.php?page=gawd_tracking';
1744
  echo '<script>window.location.href="' . $redirect_url . '";</script>';
2241
  update_option( 'gawd_menu_items', $tabs );
2242
  }
2243
 
2244
+
2245
  public function remove_zoom_message() {
2246
  check_ajax_referer( 'gawd_admin_page_nonce', 'security' );
2247
  $got_it = isset( $_REQUEST["got_it"] ) ? sanitize_text_field( $_REQUEST["got_it"] ) : '';
2249
  add_option( 'gawd_zoom_message', $got_it );
2250
  }
2251
  }
2252
+
2253
+ public function check_property_delete(){
2254
+ global $gawd_client;
2255
+ $gawd_client = GAWD_google_client::get_instance();
2256
+ $accountId = $gawd_client->get_default_accountId();
2257
+ $webPropertyId = $gawd_client->get_default_webPropertyId();
2258
+ $screen = get_current_screen();
2259
+ if ( strpos( $screen->base, 'gawd' ) !== false && $accountId != null && $webPropertyId != null) {
2260
+ try{
2261
+ $deleted = $gawd_client->analytics_member->management_webproperties->get($accountId, $webPropertyId);
2262
+ }
2263
+ catch (Exception $e){
2264
+ if(strpos($e->getMessage(), 'not found.') !==false){
2265
+ echo '<div class="notice notice-error"><p>You have deleted your web-properties with current site url, please <a href="'.admin_url() . 'admin.php?page=gawd_settings">reauthenticate</a>. </p></div>';
2266
+ }
2267
+ }
2268
+ }
2269
+ }
2270
+
2271
  /**
2272
  * Checks if the protocol is secure.
2273
  *
google-analytics-wd.php CHANGED
@@ -1,10 +1,10 @@
1
  <?php
2
 
3
  /**
4
- * Plugin Name: WD Google Analytics
5
  * Plugin URI: https://web-dorado.com/products/wordpress-google-analytics-plugin.html
6
- * Description: WD Google Analytics is a user-friendly all in one plugin, which allows to manage and monitor your website analytics from WordPress dashboard.
7
- * Version: 1.0.5
8
  * Author: WebDorado
9
  * Author URI: https://web-dorado.com
10
  * License: GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
1
  <?php
2
 
3
  /**
4
+ * Plugin Name: Google Analytics
5
  * Plugin URI: https://web-dorado.com/products/wordpress-google-analytics-plugin.html
6
+ * Description: Google Analytics WD is a user-friendly all in one plugin, which allows to manage and monitor your website analytics from WordPress dashboard.
7
+ * Version: 1.0.6
8
  * Author: WebDorado
9
  * Author URI: https://web-dorado.com
10
  * License: GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
inc/css/bootstrap.css CHANGED
@@ -6491,7 +6491,7 @@ button.close {
6491
  border: 0;
6492
  }
6493
  .hidden {
6494
- display: none !important;
6495
  }
6496
  .affix {
6497
  position: fixed;
6491
  border: 0;
6492
  }
6493
  .hidden {
6494
+ //display: none !important;
6495
  }
6496
  .affix {
6497
  position: fixed;
inc/css/gawd_admin.css CHANGED
@@ -429,18 +429,20 @@
429
  background-color:#7DB5D8;
430
  color:#fff;
431
  font-size: 13px;
432
- line-height: 26px;
433
- height: 28px;
 
434
  margin: 0;
435
  padding: 0 10px 1px;
436
  cursor: pointer;
437
- border-width: 1px;
438
  border-style: solid;
439
  -webkit-appearance: none;
440
  white-space: nowrap;
441
  -webkit-box-sizing: border-box;
442
  -moz-box-sizing: border-box;
443
  box-sizing: border-box;
 
444
  }
445
  .button_gawd_add{
446
  background-color:#7DB5D8;
@@ -1799,7 +1801,8 @@ Original highlight.js style (c) Ivan Sagalaev <maniac@softwaremaniacs.org>
1799
  .page_chart_div .gawd_btn{
1800
  right: -21px;
1801
  top: -21px;
1802
- position:absolute
 
1803
  }
1804
  .gawd_btn:hover {
1805
  background: #caced1;
@@ -2390,7 +2393,7 @@ th.ui-th-column div{
2390
  display: inline-block;
2391
  width: 19px !important;
2392
  height: 15px !important;
2393
- z-index: 45555;
2394
  line-height: 16px;
2395
  top: 8px;
2396
  right: 35px;
@@ -2423,4 +2426,24 @@ th.ui-th-column div{
2423
 
2424
  .gawd_auth_button:hover{
2425
  background-color:rgba(125,181,216,0.7)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2426
  }
429
  background-color:#7DB5D8;
430
  color:#fff;
431
  font-size: 13px;
432
+ line-height: 24px;
433
+ width:60px;
434
+ height: 26px;
435
  margin: 0;
436
  padding: 0 10px 1px;
437
  cursor: pointer;
438
+ border-width: 0px;
439
  border-style: solid;
440
  -webkit-appearance: none;
441
  white-space: nowrap;
442
  -webkit-box-sizing: border-box;
443
  -moz-box-sizing: border-box;
444
  box-sizing: border-box;
445
+ border-radius:2px
446
  }
447
  .button_gawd_add{
448
  background-color:#7DB5D8;
1801
  .page_chart_div .gawd_btn{
1802
  right: -21px;
1803
  top: -21px;
1804
+ position:absolute;
1805
+ border:0;
1806
  }
1807
  .gawd_btn:hover {
1808
  background: #caced1;
2393
  display: inline-block;
2394
  width: 19px !important;
2395
  height: 15px !important;
2396
+ z-index: 100;
2397
  line-height: 16px;
2398
  top: 8px;
2399
  right: 35px;
2426
 
2427
  .gawd_auth_button:hover{
2428
  background-color:rgba(125,181,216,0.7)
2429
+ }
2430
+
2431
+ #gbox_griddiv{
2432
+ border-radius:2px
2433
+ }
2434
+
2435
+ .button_gawd:hover{
2436
+ background-color:rgba(125,181,216,0.7)
2437
+ }
2438
+
2439
+ #gawd_export_buttons{
2440
+ margin-right:3px
2441
+ }
2442
+
2443
+ #gawd_got_it{
2444
+ width:initial
2445
+ }
2446
+
2447
+ #gawd_settings_logout:hover{
2448
+ background-color:#c9cdd0
2449
  }
inc/css/notices.css ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .wd-admin-notice {
2
+ background: #fff;
3
+ border: 4px;
4
+ display: block;
5
+ min-height: 68px;
6
+ padding: 10px 40px 10px 125px;
7
+ position: relative;
8
+ }
9
+ .wd-admin-notice a {
10
+ color: #10738B;
11
+ }
12
+ .gawd-notice-logo {
13
+ clear: both;
14
+ content: "";
15
+ display: block;
16
+ background-image: url("https://d27sb3x2z8tu4g.cloudfront.net/images/productlogos/google_analytics.png?1463122703");
17
+ background-size: 108px auto;
18
+ background-repeat: no-repeat;
19
+ background-position: 0 45%;
20
+ width: 125px;
21
+ position: absolute;
22
+ top: 0;
23
+ bottom: 0;
24
+ left: 5px;
25
+ }
26
+ .wd-admin-notice > .dashicons {
27
+ color: #424242;
28
+ position: absolute;
29
+ right: 20px;
30
+ top: 40%;
31
+ }
32
+ .wd-notice-title {
33
+ font-size: 24px;
34
+ margin: 0;
35
+ }
36
+ .wd-notice-body {
37
+ font-weight: normal;
38
+ margin: 5px 0;
39
+ }
40
+ .wd-notice-body:after {
41
+ clear: both;
42
+ content: "";
43
+ display: block;
44
+ }
45
+ .wd-notice-body li {
46
+ float: left;
47
+ margin-right: 20px;
48
+ }
49
+ .wd-notice-body .dashicons {
50
+ font-size: 17px;
51
+ }
52
+ .wd-blue {
53
+ color: #10738B;
54
+ }
55
+
56
+ .admin-notice-promo {
57
+ background: #fff;
58
+ border-top: 4px;
59
+ display: block;
60
+ min-height: 68px;
61
+ padding: 10px 40px 0px 10px;
62
+ margin: 10px 0;
63
+ position: relative;
64
+ }
65
+
66
+ .admin-notice-promo:after {
67
+ content: '';
68
+ display: table;
69
+ clear: both;
70
+ }
71
+
72
+ .close-promo {
73
+ position: absolute;
74
+ top: 5px;
75
+ right: 5px;
76
+ }
77
+
78
+ .promo {
79
+ background-position: center;
80
+ background-repeat: no-repeat;
81
+ background-size: 972px 200px;
82
+ height: 200px;
83
+ max-width: 100%;
84
+ }
85
+
86
+ .promo a {
87
+ display: block;
88
+ height: 100%;
89
+ }
inc/js/daterangepicker.js CHANGED
@@ -1,1545 +1,1561 @@
1
- /**
2
- * @version: 2.1.19
3
- * @author: Dan Grossman http://www.dangrossman.info/
4
- * @copyright: Copyright (c) 2012-2015 Dan Grossman. All rights reserved.
5
- * @license: Licensed under the MIT license. See http://www.opensource.org/licenses/mit-license.php
6
- * @website: https://www.improvely.com/
7
- */
8
-
9
- (function(root, factory) {
10
-
11
- if (typeof define === 'function' && define.amd) {
12
- define(['moment', 'jquery', 'exports'], function(momentjs, $, exports) {
13
- root.daterangepicker = factory(root, exports, momentjs, $);
14
- });
15
-
16
- } else if (typeof exports !== 'undefined') {
17
- var momentjs = require('moment');
18
- var jQuery = (typeof window != 'undefined') ? window.jQuery : undefined; //isomorphic issue
19
- if (!jQuery) {
20
- try {
21
- jQuery = require('jquery');
22
- if (!jQuery.fn) jQuery.fn = {}; //isomorphic issue
23
- } catch (err) {
24
- if (!jQuery) throw new Error('jQuery dependency not found');
25
- }
26
- }
27
-
28
- factory(root, exports, momentjs, jQuery);
29
-
30
- // Finally, as a browser global.
31
- } else {
32
- root.daterangepicker = factory(root, {}, root.moment || moment, (root.jQuery || root.Zepto || root.ender || root.$));
33
- }
34
-
35
- }(this || {}, function(root, daterangepicker, moment, $) { // 'this' doesn't exist on a server
36
-
37
- var DateRangePicker = function(element, options, cb) {
38
-
39
- //default settings for options
40
- this.parentEl = 'body';
41
- this.element = $(element);
42
- this.startDate = moment().startOf('day');
43
- this.endDate = moment().endOf('day');
44
- this.minDate = false;
45
- this.maxDate = false;
46
- this.dateLimit = false;
47
- this.autoApply = false;
48
- this.singleDatePicker = false;
49
- this.showDropdowns = false;
50
- this.showWeekNumbers = false;
51
- this.showISOWeekNumbers = false;
52
- this.timePicker = false;
53
- this.timePicker24Hour = false;
54
- this.timePickerIncrement = 1;
55
- this.timePickerSeconds = false;
56
- this.linkedCalendars = true;
57
- this.autoUpdateInput = true;
58
- this.alwaysShowCalendars = false;
59
- this.ranges = {};
60
-
61
- this.opens = 'right';
62
- if (this.element.hasClass('pull-right'))
63
- this.opens = 'left';
64
-
65
- this.drops = 'down';
66
- if (this.element.hasClass('dropup'))
67
- this.drops = 'up';
68
-
69
- this.buttonClasses = 'btn btn-sm';
70
- this.applyClass = 'btn-success';
71
- this.cancelClass = 'btn-default';
72
-
73
- this.locale = {
74
- format: 'MM/DD/YYYY',
75
- separator: ' - ',
76
- applyLabel: 'Apply',
77
- cancelLabel: 'Cancel',
78
- weekLabel: 'W',
79
- customRangeLabel: 'Custom Range',
80
- daysOfWeek: moment.weekdaysMin(),
81
- monthNames: moment.monthsShort(),
82
- firstDay: moment.localeData().firstDayOfWeek()
83
- };
84
-
85
- this.callback = function() { };
86
-
87
- //some state information
88
- this.isShowing = false;
89
- this.leftCalendar = {};
90
- this.rightCalendar = {};
91
-
92
- //custom options from user
93
- if (typeof options !== 'object' || options === null)
94
- options = {};
95
-
96
- //allow setting options with data attributes
97
- //data-api options will be overwritten with custom javascript options
98
- options = $.extend(this.element.data(), options);
99
-
100
- //html template for the picker UI
101
- if (typeof options.template !== 'string' && !(options.template instanceof $))
102
- options.template = '<div class="daterangepicker dropdown-menu">' +
103
- '<div class="calendar left">' +
104
- '<div class="daterangepicker_input">' +
105
- '<input class="input-mini" type="text" name="daterangepicker_start" value="" />' +
106
- '<i class="fa fa-calendar glyphicon glyphicon-calendar"></i>' +
107
- '<div class="calendar-time">' +
108
- '<div></div>' +
109
- '<i class="fa fa-clock-o glyphicon glyphicon-time"></i>' +
110
- '</div>' +
111
- '</div>' +
112
- '<div class="calendar-table"></div>' +
113
- '</div>' +
114
- '<div class="calendar right">' +
115
- '<div class="daterangepicker_input">' +
116
- '<input class="input-mini" type="text" name="daterangepicker_end" value="" />' +
117
- '<i class="fa fa-calendar glyphicon glyphicon-calendar"></i>' +
118
- '<div class="calendar-time">' +
119
- '<div></div>' +
120
- '<i class="fa fa-clock-o glyphicon glyphicon-time"></i>' +
121
- '</div>' +
122
- '</div>' +
123
- '<div class="calendar-table"></div>' +
124
- '</div>' +
125
- '<div class="ranges">' +
126
- '<div class="range_inputs">' +
127
- '<button class="applyBtn" disabled="disabled" type="button"></button> ' +
128
- '<button class="cancelBtn" type="button"></button>' +
129
- '</div>' +
130
- '</div>' +
131
- '</div>';
132
-
133
- this.parentEl = (options.parentEl && $(options.parentEl).length) ? $(options.parentEl) : $(this.parentEl);
134
- this.container = $(options.template).appendTo(this.parentEl);
135
-
136
- //
137
- // handle all the possible options overriding defaults
138
- //
139
-
140
- if (typeof options.locale === 'object') {
141
-
142
- if (typeof options.locale.format === 'string')
143
- this.locale.format = options.locale.format;
144
-
145
- if (typeof options.locale.separator === 'string')
146
- this.locale.separator = options.locale.separator;
147
-
148
- if (typeof options.locale.daysOfWeek === 'object')
149
- this.locale.daysOfWeek = options.locale.daysOfWeek.slice();
150
-
151
- if (typeof options.locale.monthNames === 'object')
152
- this.locale.monthNames = options.locale.monthNames.slice();
153
-
154
- if (typeof options.locale.firstDay === 'number')
155
- this.locale.firstDay = options.locale.firstDay;
156
-
157
- if (typeof options.locale.applyLabel === 'string')
158
- this.locale.applyLabel = options.locale.applyLabel;
159
-
160
- if (typeof options.locale.cancelLabel === 'string')
161
- this.locale.cancelLabel = options.locale.cancelLabel;
162
-
163
- if (typeof options.locale.weekLabel === 'string')
164
- this.locale.weekLabel = options.locale.weekLabel;
165
-
166
- if (typeof options.locale.customRangeLabel === 'string')
167
- this.locale.customRangeLabel = options.locale.customRangeLabel;
168
-
169
- }
170
-
171
- if (typeof options.startDate === 'string')
172
- this.startDate = moment(options.startDate, this.locale.format);
173
-
174
- if (typeof options.endDate === 'string')
175
- this.endDate = moment(options.endDate, this.locale.format);
176
-
177
- if (typeof options.minDate === 'string')
178
- this.minDate = moment(options.minDate, this.locale.format);
179
-
180
- if (typeof options.maxDate === 'string')
181
- this.maxDate = moment(options.maxDate, this.locale.format);
182
-
183
- if (typeof options.startDate === 'object')
184
- this.startDate = moment(options.startDate);
185
-
186
- if (typeof options.endDate === 'object')
187
- this.endDate = moment(options.endDate);
188
-
189
- if (typeof options.minDate === 'object')
190
- this.minDate = moment(options.minDate);
191
-
192
- if (typeof options.maxDate === 'object')
193
- this.maxDate = moment(options.maxDate);
194
-
195
- // sanity check for bad options
196
- if (this.minDate && this.startDate.isBefore(this.minDate))
197
- this.startDate = this.minDate.clone();
198
-
199
- // sanity check for bad options
200
- if (this.maxDate && this.endDate.isAfter(this.maxDate))
201
- this.endDate = this.maxDate.clone();
202
-
203
- if (typeof options.applyClass === 'string')
204
- this.applyClass = options.applyClass;
205
-
206
- if (typeof options.cancelClass === 'string')
207
- this.cancelClass = options.cancelClass;
208
-
209
- if (typeof options.dateLimit === 'object')
210
- this.dateLimit = options.dateLimit;
211
-
212
- if (typeof options.opens === 'string')
213
- this.opens = options.opens;
214
-
215
- if (typeof options.drops === 'string')
216
- this.drops = options.drops;
217
-
218
- if (typeof options.showWeekNumbers === 'boolean')
219
- this.showWeekNumbers = options.showWeekNumbers;
220
-
221
- if (typeof options.showISOWeekNumbers === 'boolean')
222
- this.showISOWeekNumbers = options.showISOWeekNumbers;
223
-
224
- if (typeof options.buttonClasses === 'string')
225
- this.buttonClasses = options.buttonClasses;
226
-
227
- if (typeof options.buttonClasses === 'object')
228
- this.buttonClasses = options.buttonClasses.join(' ');
229
-
230
- if (typeof options.showDropdowns === 'boolean')
231
- this.showDropdowns = options.showDropdowns;
232
-
233
- if (typeof options.singleDatePicker === 'boolean') {
234
- this.singleDatePicker = options.singleDatePicker;
235
- if (this.singleDatePicker)
236
- this.endDate = this.startDate.clone();
237
- }
238
-
239
- if (typeof options.timePicker === 'boolean')
240
- this.timePicker = options.timePicker;
241
-
242
- if (typeof options.timePickerSeconds === 'boolean')
243
- this.timePickerSeconds = options.timePickerSeconds;
244
-
245
- if (typeof options.timePickerIncrement === 'number')
246
- this.timePickerIncrement = options.timePickerIncrement;
247
-
248
- if (typeof options.timePicker24Hour === 'boolean')
249
- this.timePicker24Hour = options.timePicker24Hour;
250
-
251
- if (typeof options.autoApply === 'boolean')
252
- this.autoApply = options.autoApply;
253
-
254
- if (typeof options.autoUpdateInput === 'boolean')
255
- this.autoUpdateInput = options.autoUpdateInput;
256
-
257
- if (typeof options.linkedCalendars === 'boolean')
258
- this.linkedCalendars = options.linkedCalendars;
259
-
260
- if (typeof options.isInvalidDate === 'function')
261
- this.isInvalidDate = options.isInvalidDate;
262
-
263
- if (typeof options.alwaysShowCalendars === 'boolean')
264
- this.alwaysShowCalendars = options.alwaysShowCalendars;
265
-
266
- // update day names order to firstDay
267
- if (this.locale.firstDay != 0) {
268
- var iterator = this.locale.firstDay;
269
- while (iterator > 0) {
270
- this.locale.daysOfWeek.push(this.locale.daysOfWeek.shift());
271
- iterator--;
272
- }
273
- }
274
-
275
- var start, end, range;
276
-
277
- //if no start/end dates set, check if an input element contains initial values
278
- if (typeof options.startDate === 'undefined' && typeof options.endDate === 'undefined') {
279
- if ($(this.element).is('input[type=text]')) {
280
- var val = $(this.element).val(),
281
- split = val.split(this.locale.separator);
282
-
283
- start = end = null;
284
-
285
- if (split.length == 2) {
286
- start = moment(split[0], this.locale.format);
287
- end = moment(split[1], this.locale.format);
288
- } else if (this.singleDatePicker && val !== "") {
289
- start = moment(val, this.locale.format);
290
- end = moment(val, this.locale.format);
291
- }
292
- if (start !== null && end !== null) {
293
- this.setStartDate(start);
294
- this.setEndDate(end);
295
- }
296
- }
297
- }
298
-
299
- if (typeof options.ranges === 'object') {
300
- for (range in options.ranges) {
301
-
302
- if (typeof options.ranges[range][0] === 'string')
303
- start = moment(options.ranges[range][0], this.locale.format);
304
- else
305
- start = moment(options.ranges[range][0]);
306
-
307
- if (typeof options.ranges[range][1] === 'string')
308
- end = moment(options.ranges[range][1], this.locale.format);
309
- else
310
- end = moment(options.ranges[range][1]);
311
-
312
- // If the start or end date exceed those allowed by the minDate or dateLimit
313
- // options, shorten the range to the allowable period.
314
- if (this.minDate && start.isBefore(this.minDate))
315
- start = this.minDate.clone();
316
-
317
- var maxDate = this.maxDate;
318
- if (this.dateLimit && start.clone().add(this.dateLimit).isAfter(maxDate))
319
- maxDate = start.clone().add(this.dateLimit);
320
- if (maxDate && end.isAfter(maxDate))
321
- end = maxDate.clone();
322
-
323
- // If the end of the range is before the minimum or the start of the range is
324
- // after the maximum, don't display this range option at all.
325
- if ((this.minDate && end.isBefore(this.minDate)) || (maxDate && start.isAfter(maxDate)))
326
- continue;
327
-
328
- //Support unicode chars in the range names.
329
- var elem = document.createElement('textarea');
330
- elem.innerHTML = range;
331
- var rangeHtml = elem.value;
332
-
333
- this.ranges[rangeHtml] = [start, end];
334
- }
335
-
336
- var list = '<ul>';
337
- for (range in this.ranges) {
338
- list += '<li>' + range + '</li>';
339
- }
340
- list += '<li>' + this.locale.customRangeLabel + '</li>';
341
- list += '</ul>';
342
- this.container.find('.ranges').prepend(list);
343
- }
344
-
345
- if (typeof cb === 'function') {
346
- this.callback = cb;
347
- }
348
-
349
- if (!this.timePicker) {
350
- this.startDate = this.startDate.startOf('day');
351
- this.endDate = this.endDate.endOf('day');
352
- this.container.find('.calendar-time').hide();
353
- }
354
-
355
- //can't be used together for now
356
- if (this.timePicker && this.autoApply)
357
- this.autoApply = false;
358
-
359
- if (this.autoApply && typeof options.ranges !== 'object') {
360
- this.container.find('.ranges').hide();
361
- } else if (this.autoApply) {
362
- this.container.find('.applyBtn, .cancelBtn').addClass('hide');
363
- }
364
-
365
- if (this.singleDatePicker) {
366
- this.container.addClass('single');
367
- this.container.find('.calendar.left').addClass('single');
368
- this.container.find('.calendar.left').show();
369
- this.container.find('.calendar.right').hide();
370
- this.container.find('.daterangepicker_input input, .daterangepicker_input i').hide();
371
- if (!this.timePicker) {
372
- this.container.find('.ranges').hide();
373
- }
374
- }
375
-
376
- if ((typeof options.ranges === 'undefined' && !this.singleDatePicker) || this.alwaysShowCalendars) {
377
- this.container.addClass('show-calendar');
378
- }
379
-
380
- this.container.addClass('opens' + this.opens);
381
-
382
- //swap the position of the predefined ranges if opens right
383
- if (typeof options.ranges !== 'undefined' && this.opens == 'right') {
384
- var ranges = this.container.find('.ranges');
385
- var html = ranges.clone();
386
- ranges.remove();
387
- this.container.find('.calendar.left').parent().prepend(html);
388
- }
389
-
390
- //apply CSS classes and labels to buttons
391
- this.container.find('.applyBtn, .cancelBtn').addClass(this.buttonClasses);
392
- if (this.applyClass.length)
393
- this.container.find('.applyBtn').addClass(this.applyClass);
394
- if (this.cancelClass.length)
395
- this.container.find('.cancelBtn').addClass(this.cancelClass);
396
- this.container.find('.applyBtn').html(this.locale.applyLabel);
397
- this.container.find('.cancelBtn').html(this.locale.cancelLabel);
398
-
399
- //
400
- // event listeners
401
- //
402
-
403
- this.container.find('.calendar')
404
- .on('click.daterangepicker', '.prev', $.proxy(this.clickPrev, this))
405
- .on('click.daterangepicker', '.next', $.proxy(this.clickNext, this))
406
- .on('click.daterangepicker', 'td.available', $.proxy(this.clickDate, this))
407
- .on('mouseenter.daterangepicker', 'td.available', $.proxy(this.hoverDate, this))
408
- .on('mouseleave.daterangepicker', 'td.available', $.proxy(this.updateFormInputs, this))
409
- .on('change.daterangepicker', 'select.yearselect', $.proxy(this.monthOrYearChanged, this))
410
- .on('change.daterangepicker', 'select.monthselect', $.proxy(this.monthOrYearChanged, this))
411
- .on('change.daterangepicker', 'select.hourselect,select.minuteselect,select.secondselect,select.ampmselect', $.proxy(this.timeChanged, this))
412
- .on('click.daterangepicker', '.daterangepicker_input input', $.proxy(this.showCalendars, this))
413
- //.on('keyup.daterangepicker', '.daterangepicker_input input', $.proxy(this.formInputsChanged, this))
414
- .on('change.daterangepicker', '.daterangepicker_input input', $.proxy(this.formInputsChanged, this));
415
-
416
- this.container.find('.ranges')
417
- .on('click.daterangepicker', 'button.applyBtn', $.proxy(this.clickApply, this))
418
- .on('click.daterangepicker', 'button.cancelBtn', $.proxy(this.clickCancel, this))
419
- .on('click.daterangepicker', 'li', $.proxy(this.clickRange, this))
420
- .on('mouseenter.daterangepicker', 'li', $.proxy(this.hoverRange, this))
421
- .on('mouseleave.daterangepicker', 'li', $.proxy(this.updateFormInputs, this));
422
-
423
- if (this.element.is('input')) {
424
- this.element.on({
425
- 'click.daterangepicker': $.proxy(this.show, this),
426
- 'focus.daterangepicker': $.proxy(this.show, this),
427
- 'keyup.daterangepicker': $.proxy(this.elementChanged, this),
428
- 'keydown.daterangepicker': $.proxy(this.keydown, this)
429
- });
430
- } else {
431
- this.element.on('click.daterangepicker', $.proxy(this.toggle, this));
432
- }
433
-
434
- //
435
- // if attached to a text input, set the initial value
436
- //
437
-
438
- if (this.element.is('input') && !this.singleDatePicker && this.autoUpdateInput) {
439
- this.element.val(this.startDate.format(this.locale.format) + this.locale.separator + this.endDate.format(this.locale.format));
440
- this.element.trigger('change');
441
- } else if (this.element.is('input') && this.autoUpdateInput) {
442
- this.element.val(this.startDate.format(this.locale.format));
443
- this.element.trigger('change');
444
- }
445
-
446
- };
447
-
448
- DateRangePicker.prototype = {
449
-
450
- constructor: DateRangePicker,
451
-
452
- setStartDate: function(startDate) {
453
- if (typeof startDate === 'string')
454
- this.startDate = moment(startDate, this.locale.format);
455
-
456
- if (typeof startDate === 'object')
457
- this.startDate = moment(startDate);
458
-
459
- if (!this.timePicker)
460
- this.startDate = this.startDate.startOf('day');
461
-
462
- if (this.timePicker && this.timePickerIncrement)
463
- this.startDate.minute(Math.round(this.startDate.minute() / this.timePickerIncrement) * this.timePickerIncrement);
464
-
465
- if (this.minDate && this.startDate.isBefore(this.minDate))
466
- this.startDate = this.minDate;
467
-
468
- if (this.maxDate && this.startDate.isAfter(this.maxDate))
469
- this.startDate = this.maxDate;
470
-
471
- if (!this.isShowing)
472
- this.updateElement();
473
-
474
- this.updateMonthsInView();
475
- },
476
-
477
- setEndDate: function(endDate) {
478
- if (typeof endDate === 'string')
479
- this.endDate = moment(endDate, this.locale.format);
480
-
481
- if (typeof endDate === 'object')
482
- this.endDate = moment(endDate);
483
-
484
- if (!this.timePicker)
485
- this.endDate = this.endDate.endOf('day');
486
-
487
- if (this.timePicker && this.timePickerIncrement)
488
- this.endDate.minute(Math.round(this.endDate.minute() / this.timePickerIncrement) * this.timePickerIncrement);
489
-
490
- if (this.endDate.isBefore(this.startDate))
491
- this.endDate = this.startDate.clone();
492
-
493
- if (this.maxDate && this.endDate.isAfter(this.maxDate))
494
- this.endDate = this.maxDate;
495
-
496
- if (this.dateLimit && this.startDate.clone().add(this.dateLimit).isBefore(this.endDate))
497
- this.endDate = this.startDate.clone().add(this.dateLimit);
498
-
499
- this.previousRightTime = this.endDate.clone();
500
-
501
- if (!this.isShowing)
502
- this.updateElement();
503
-
504
- this.updateMonthsInView();
505
- },
506
-
507
- isInvalidDate: function() {
508
- return false;
509
- },
510
-
511
- updateView: function() {
512
- if (this.timePicker) {
513
- this.renderTimePicker('left');
514
- this.renderTimePicker('right');
515
- if (!this.endDate) {
516
- this.container.find('.right .calendar-time select').attr('disabled', 'disabled').addClass('disabled');
517
- } else {
518
- this.container.find('.right .calendar-time select').removeAttr('disabled').removeClass('disabled');
519
- }
520
- }
521
- if (this.endDate) {
522
- this.container.find('input[name="daterangepicker_end"]').removeClass('active');
523
- this.container.find('input[name="daterangepicker_start"]').addClass('active');
524
- } else {
525
- this.container.find('input[name="daterangepicker_end"]').addClass('active');
526
- this.container.find('input[name="daterangepicker_start"]').removeClass('active');
527
- }
528
- this.updateMonthsInView();
529
- this.updateCalendars();
530
- this.updateFormInputs();
531
- },
532
-
533
- updateMonthsInView: function() {
534
- if (this.endDate) {
535
-
536
- //if both dates are visible already, do nothing
537
- if (!this.singleDatePicker && this.leftCalendar.month && this.rightCalendar.month &&
538
- (this.startDate.format('YYYY-MM') == this.leftCalendar.month.format('YYYY-MM') || this.startDate.format('YYYY-MM') == this.rightCalendar.month.format('YYYY-MM'))
539
- &&
540
- (this.endDate.format('YYYY-MM') == this.leftCalendar.month.format('YYYY-MM') || this.endDate.format('YYYY-MM') == this.rightCalendar.month.format('YYYY-MM'))
541
- ) {
542
- return;
543
- }
544
-
545
- this.leftCalendar.month = this.startDate.clone().date(2);
546
- if (!this.linkedCalendars && (this.endDate.month() != this.startDate.month() || this.endDate.year() != this.startDate.year())) {
547
- this.rightCalendar.month = this.endDate.clone().date(2);
548
- } else {
549
- this.rightCalendar.month = this.startDate.clone().date(2).add(1, 'month');
550
- }
551
-
552
- } else {
553
- if (this.leftCalendar.month.format('YYYY-MM') != this.startDate.format('YYYY-MM') && this.rightCalendar.month.format('YYYY-MM') != this.startDate.format('YYYY-MM')) {
554
- this.leftCalendar.month = this.startDate.clone().date(2);
555
- this.rightCalendar.month = this.startDate.clone().date(2).add(1, 'month');
556
- }
557
- }
558
- },
559
-
560
- updateCalendars: function() {
561
-
562
- if (this.timePicker) {
563
- var hour, minute, second;
564
- if (this.endDate) {
565
- hour = parseInt(this.container.find('.left .hourselect').val(), 10);
566
- minute = parseInt(this.container.find('.left .minuteselect').val(), 10);
567
- second = this.timePickerSeconds ? parseInt(this.container.find('.left .secondselect').val(), 10) : 0;
568
- if (!this.timePicker24Hour) {
569
- var ampm = this.container.find('.left .ampmselect').val();
570
- if (ampm === 'PM' && hour < 12)
571
- hour += 12;
572
- if (ampm === 'AM' && hour === 12)
573
- hour = 0;
574
- }
575
- } else {
576
- hour = parseInt(this.container.find('.right .hourselect').val(), 10);
577
- minute = parseInt(this.container.find('.right .minuteselect').val(), 10);
578
- second = this.timePickerSeconds ? parseInt(this.container.find('.right .secondselect').val(), 10) : 0;
579
- if (!this.timePicker24Hour) {
580
- var ampm = this.container.find('.right .ampmselect').val();
581
- if (ampm === 'PM' && hour < 12)
582
- hour += 12;
583
- if (ampm === 'AM' && hour === 12)
584
- hour = 0;
585
- }
586
- }
587
- this.leftCalendar.month.hour(hour).minute(minute).second(second);
588
- this.rightCalendar.month.hour(hour).minute(minute).second(second);
589
- }
590
-
591
- this.renderCalendar('left');
592
- this.renderCalendar('right');
593
-
594
- //highlight any predefined range matching the current start and end dates
595
- this.container.find('.ranges li').removeClass('active');
596
- if (this.endDate == null) return;
597
-
598
- this.calculateChosenLabel();
599
- },
600
-
601
- renderCalendar: function(side) {
602
-
603
- //
604
- // Build the matrix of dates that will populate the calendar
605
- //
606
-
607
- var calendar = side == 'left' ? this.leftCalendar : this.rightCalendar;
608
- var month = calendar.month.month();
609
- var year = calendar.month.year();
610
- var hour = calendar.month.hour();
611
- var minute = calendar.month.minute();
612
- var second = calendar.month.second();
613
- var daysInMonth = moment([year, month]).daysInMonth();
614
- var firstDay = moment([year, month, 1]);
615
- var lastDay = moment([year, month, daysInMonth]);
616
- var lastMonth = moment(firstDay).subtract(1, 'month').month();
617
- var lastYear = moment(firstDay).subtract(1, 'month').year();
618
- var daysInLastMonth = moment([lastYear, lastMonth]).daysInMonth();
619
- var dayOfWeek = firstDay.day();
620
-
621
- //initialize a 6 rows x 7 columns array for the calendar
622
- var calendar = [];
623
- calendar.firstDay = firstDay;
624
- calendar.lastDay = lastDay;
625
-
626
- for (var i = 0; i < 6; i++) {
627
- calendar[i] = [];
628
- }
629
-
630
- //populate the calendar with date objects
631
- var startDay = daysInLastMonth - dayOfWeek + this.locale.firstDay + 1;
632
- if (startDay > daysInLastMonth)
633
- startDay -= 7;
634
-
635
- if (dayOfWeek == this.locale.firstDay)
636
- startDay = daysInLastMonth - 6;
637
-
638
- var curDate = moment([lastYear, lastMonth, startDay, 12, minute, second]);
639
-
640
- var col, row;
641
- for (var i = 0, col = 0, row = 0; i < 42; i++, col++, curDate = moment(curDate).add(24, 'hour')) {
642
- if (i > 0 && col % 7 === 0) {
643
- col = 0;
644
- row++;
645
- }
646
- calendar[row][col] = curDate.clone().hour(hour).minute(minute).second(second);
647
- curDate.hour(12);
648
-
649
- if (this.minDate && calendar[row][col].format('YYYY-MM-DD') == this.minDate.format('YYYY-MM-DD') && calendar[row][col].isBefore(this.minDate) && side == 'left') {
650
- calendar[row][col] = this.minDate.clone();
651
- }
652
-
653
- if (this.maxDate && calendar[row][col].format('YYYY-MM-DD') == this.maxDate.format('YYYY-MM-DD') && calendar[row][col].isAfter(this.maxDate) && side == 'right') {
654
- calendar[row][col] = this.maxDate.clone();
655
- }
656
-
657
- }
658
-
659
- //make the calendar object available to hoverDate/clickDate
660
- if (side == 'left') {
661
- this.leftCalendar.calendar = calendar;
662
- } else {
663
- this.rightCalendar.calendar = calendar;
664
- }
665
-
666
- //
667
- // Display the calendar
668
- //
669
-
670
- var minDate = side == 'left' ? this.minDate : this.startDate;
671
- var maxDate = this.maxDate;
672
- var selected = side == 'left' ? this.startDate : this.endDate;
673
-
674
- var html = '<table class="table-condensed">';
675
- html += '<thead>';
676
- html += '<tr>';
677
-
678
- // add empty cell for week number
679
- if (this.showWeekNumbers || this.showISOWeekNumbers)
680
- html += '<th></th>';
681
-
682
- if ((!minDate || minDate.isBefore(calendar.firstDay)) && (!this.linkedCalendars || side == 'left')) {
683
- html += '<th class="prev available"><i class="fa fa-chevron-left glyphicon glyphicon-chevron-left"></i></th>';
684
- } else {
685
- html += '<th></th>';
686
- }
687
-
688
- var dateHtml = this.locale.monthNames[calendar[1][1].month()] + calendar[1][1].format(" YYYY");
689
-
690
- if (this.showDropdowns) {
691
- var currentMonth = calendar[1][1].month();
692
- var currentYear = calendar[1][1].year();
693
- var maxYear = (maxDate && maxDate.year()) || (currentYear + 5);
694
- var minYear = (minDate && minDate.year()) || (currentYear - 50);
695
- var inMinYear = currentYear == minYear;
696
- var inMaxYear = currentYear == maxYear;
697
-
698
- var monthHtml = '<select class="monthselect">';
699
- for (var m = 0; m < 12; m++) {
700
- if ((!inMinYear || m >= minDate.month()) && (!inMaxYear || m <= maxDate.month())) {
701
- monthHtml += "<option value='" + m + "'" +
702
- (m === currentMonth ? " selected='selected'" : "") +
703
- ">" + this.locale.monthNames[m] + "</option>";
704
- } else {
705
- monthHtml += "<option value='" + m + "'" +
706
- (m === currentMonth ? " selected='selected'" : "") +
707
- " disabled='disabled'>" + this.locale.monthNames[m] + "</option>";
708
- }
709
- }
710
- monthHtml += "</select>";
711
-
712
- var yearHtml = '<select class="yearselect">';
713
- for (var y = minYear; y <= maxYear; y++) {
714
- yearHtml += '<option value="' + y + '"' +
715
- (y === currentYear ? ' selected="selected"' : '') +
716
- '>' + y + '</option>';
717
- }
718
- yearHtml += '</select>';
719
-
720
- dateHtml = monthHtml + yearHtml;
721
- }
722
-
723
- html += '<th colspan="5" class="month">' + dateHtml + '</th>';
724
- if ((!maxDate || maxDate.isAfter(calendar.lastDay)) && (!this.linkedCalendars || side == 'right' || this.singleDatePicker)) {
725
- html += '<th class="next available"><i class="fa fa-chevron-right glyphicon glyphicon-chevron-right"></i></th>';
726
- } else {
727
- html += '<th></th>';
728
- }
729
-
730
- html += '</tr>';
731
- html += '<tr>';
732
-
733
- // add week number label
734
- if (this.showWeekNumbers || this.showISOWeekNumbers)
735
- html += '<th class="week">' + this.locale.weekLabel + '</th>';
736
-
737
- $.each(this.locale.daysOfWeek, function(index, dayOfWeek) {
738
- html += '<th>' + dayOfWeek + '</th>';
739
- });
740
-
741
- html += '</tr>';
742
- html += '</thead>';
743
- html += '<tbody>';
744
-
745
- //adjust maxDate to reflect the dateLimit setting in order to
746
- //grey out end dates beyond the dateLimit
747
- if (this.endDate == null && this.dateLimit) {
748
- var maxLimit = this.startDate.clone().add(this.dateLimit).endOf('day');
749
- if (!maxDate || maxLimit.isBefore(maxDate)) {
750
- maxDate = maxLimit;
751
- }
752
- }
753
-
754
- for (var row = 0; row < 6; row++) {
755
- html += '<tr>';
756
-
757
- // add week number
758
- if (this.showWeekNumbers)
759
- html += '<td class="week">' + calendar[row][0].week() + '</td>';
760
- else if (this.showISOWeekNumbers)
761
- html += '<td class="week">' + calendar[row][0].isoWeek() + '</td>';
762
-
763
- for (var col = 0; col < 7; col++) {
764
-
765
- var classes = [];
766
-
767
- //highlight today's date
768
- if (calendar[row][col].isSame(new Date(), "day"))
769
- classes.push('today');
770
-
771
- //highlight weekends
772
- if (calendar[row][col].isoWeekday() > 5)
773
- classes.push('weekend');
774
-
775
- //grey out the dates in other months displayed at beginning and end of this calendar
776
- if (calendar[row][col].month() != calendar[1][1].month())
777
- classes.push('off');
778
-
779
- //don't allow selection of dates before the minimum date
780
- if (this.minDate && calendar[row][col].isBefore(this.minDate, 'day'))
781
- classes.push('off', 'disabled');
782
-
783
- //don't allow selection of dates after the maximum date
784
- if (maxDate && calendar[row][col].isAfter(maxDate, 'day'))
785
- classes.push('off', 'disabled');
786
-
787
- //don't allow selection of date if a custom function decides it's invalid
788
- if (this.isInvalidDate(calendar[row][col]))
789
- classes.push('off', 'disabled');
790
-
791
- //highlight the currently selected start date
792
- if (calendar[row][col].format('YYYY-MM-DD') == this.startDate.format('YYYY-MM-DD'))
793
- classes.push('active', 'start-date');
794
-
795
- //highlight the currently selected end date
796
- if (this.endDate != null && calendar[row][col].format('YYYY-MM-DD') == this.endDate.format('YYYY-MM-DD'))
797
- classes.push('active', 'end-date');
798
-
799
- //highlight dates in-between the selected dates
800
- if (this.endDate != null && calendar[row][col] > this.startDate && calendar[row][col] < this.endDate)
801
- classes.push('in-range');
802
-
803
- var cname = '', disabled = false;
804
- for (var i = 0; i < classes.length; i++) {
805
- cname += classes[i] + ' ';
806
- if (classes[i] == 'disabled')
807
- disabled = true;
808
- }
809
- if (!disabled)
810
- cname += 'available';
811
-
812
- html += '<td class="' + cname.replace(/^\s+|\s+$/g, '') + '" data-title="' + 'r' + row + 'c' + col + '">' + calendar[row][col].date() + '</td>';
813
-
814
- }
815
- html += '</tr>';
816
- }
817
-
818
- html += '</tbody>';
819
- html += '</table>';
820
-
821
- this.container.find('.calendar.' + side + ' .calendar-table').html(html);
822
-
823
- },
824
-
825
- renderTimePicker: function(side) {
826
-
827
- var html, selected, minDate, maxDate = this.maxDate;
828
-
829
- if (this.dateLimit && (!this.maxDate || this.startDate.clone().add(this.dateLimit).isAfter(this.maxDate)))
830
- maxDate = this.startDate.clone().add(this.dateLimit);
831
-
832
- if (side == 'left') {
833
- selected = this.startDate.clone();
834
- minDate = this.minDate;
835
- } else if (side == 'right') {
836
- selected = this.endDate ? this.endDate.clone() : this.previousRightTime.clone();
837
- minDate = this.startDate;
838
-
839
- //Preserve the time already selected
840
- var timeSelector = this.container.find('.calendar.right .calendar-time div');
841
- if (timeSelector.html() != '') {
842
-
843
- selected.hour(timeSelector.find('.hourselect option:selected').val() || selected.hour());
844
- selected.minute(timeSelector.find('.minuteselect option:selected').val() || selected.minute());
845
- selected.second(timeSelector.find('.secondselect option:selected').val() || selected.second());
846
-
847
- if (!this.timePicker24Hour) {
848
- var ampm = timeSelector.find('.ampmselect option:selected').val();
849
- if (ampm === 'PM' && selected.hour() < 12)
850
- selected.hour(selected.hour() + 12);
851
- if (ampm === 'AM' && selected.hour() === 12)
852
- selected.hour(0);
853
- }
854
-
855
- if (selected.isBefore(this.startDate))
856
- selected = this.startDate.clone();
857
-
858
- if (selected.isAfter(maxDate))
859
- selected = maxDate.clone();
860
-
861
- }
862
- }
863
-
864
- //
865
- // hours
866
- //
867
-
868
- html = '<select class="hourselect">';
869
-
870
- var start = this.timePicker24Hour ? 0 : 1;
871
- var end = this.timePicker24Hour ? 23 : 12;
872
-
873
- for (var i = start; i <= end; i++) {
874
- var i_in_24 = i;
875
- if (!this.timePicker24Hour)
876
- i_in_24 = selected.hour() >= 12 ? (i == 12 ? 12 : i + 12) : (i == 12 ? 0 : i);
877
-
878
- var time = selected.clone().hour(i_in_24);
879
- var disabled = false;
880
- if (minDate && time.minute(59).isBefore(minDate))
881
- disabled = true;
882
- if (maxDate && time.minute(0).isAfter(maxDate))
883
- disabled = true;
884
-
885
- if (i_in_24 == selected.hour() && !disabled) {
886
- html += '<option value="' + i + '" selected="selected">' + i + '</option>';
887
- } else if (disabled) {
888
- html += '<option value="' + i + '" disabled="disabled" class="disabled">' + i + '</option>';
889
- } else {
890
- html += '<option value="' + i + '">' + i + '</option>';
891
- }
892
- }
893
-
894
- html += '</select> ';
895
-
896
- //
897
- // minutes
898
- //
899
-
900
- html += ': <select class="minuteselect">';
901
-
902
- for (var i = 0; i < 60; i += this.timePickerIncrement) {
903
- var padded = i < 10 ? '0' + i : i;
904
- var time = selected.clone().minute(i);
905
-
906
- var disabled = false;
907
- if (minDate && time.second(59).isBefore(minDate))
908
- disabled = true;
909
- if (maxDate && time.second(0).isAfter(maxDate))
910
- disabled = true;
911
-
912
- if (selected.minute() == i && !disabled) {
913
- html += '<option value="' + i + '" selected="selected">' + padded + '</option>';
914
- } else if (disabled) {
915
- html += '<option value="' + i + '" disabled="disabled" class="disabled">' + padded + '</option>';
916
- } else {
917
- html += '<option value="' + i + '">' + padded + '</option>';
918
- }
919
- }
920
-
921
- html += '</select> ';
922
-
923
- //
924
- // seconds
925
- //
926
-
927
- if (this.timePickerSeconds) {
928
- html += ': <select class="secondselect">';
929
-
930
- for (var i = 0; i < 60; i++) {
931
- var padded = i < 10 ? '0' + i : i;
932
- var time = selected.clone().second(i);
933
-
934
- var disabled = false;
935
- if (minDate && time.isBefore(minDate))
936
- disabled = true;
937
- if (maxDate && time.isAfter(maxDate))
938
- disabled = true;
939
-
940
- if (selected.second() == i && !disabled) {
941
- html += '<option value="' + i + '" selected="selected">' + padded + '</option>';
942
- } else if (disabled) {
943
- html += '<option value="' + i + '" disabled="disabled" class="disabled">' + padded + '</option>';
944
- } else {
945
- html += '<option value="' + i + '">' + padded + '</option>';
946
- }
947
- }
948
-
949
- html += '</select> ';
950
- }
951
-
952
- //
953
- // AM/PM
954
- //
955
-
956
- if (!this.timePicker24Hour) {
957
- html += '<select class="ampmselect">';
958
-
959
- var am_html = '';
960
- var pm_html = '';
961
-
962
- if (minDate && selected.clone().hour(12).minute(0).second(0).isBefore(minDate))
963
- am_html = ' disabled="disabled" class="disabled"';
964
-
965
- if (maxDate && selected.clone().hour(0).minute(0).second(0).isAfter(maxDate))
966
- pm_html = ' disabled="disabled" class="disabled"';
967
-
968
- if (selected.hour() >= 12) {
969
- html += '<option value="AM"' + am_html + '>AM</option><option value="PM" selected="selected"' + pm_html + '>PM</option>';
970
- } else {
971
- html += '<option value="AM" selected="selected"' + am_html + '>AM</option><option value="PM"' + pm_html + '>PM</option>';
972
- }
973
-
974
- html += '</select>';
975
- }
976
-
977
- this.container.find('.calendar.' + side + ' .calendar-time div').html(html);
978
-
979
- },
980
-
981
- updateFormInputs: function() {
982
-
983
- //ignore mouse movements while an above-calendar text input has focus
984
- if (this.container.find('input[name=daterangepicker_start]').is(":focus") || this.container.find('input[name=daterangepicker_end]').is(":focus"))
985
- return;
986
-
987
- this.container.find('input[name=daterangepicker_start]').val(this.startDate.format(this.locale.format));
988
- if (this.endDate)
989
- this.container.find('input[name=daterangepicker_end]').val(this.endDate.format(this.locale.format));
990
-
991
- if (this.singleDatePicker || (this.endDate && (this.startDate.isBefore(this.endDate) || this.startDate.isSame(this.endDate)))) {
992
- this.container.find('button.applyBtn').removeAttr('disabled');
993
- } else {
994
- this.container.find('button.applyBtn').attr('disabled', 'disabled');
995
- }
996
-
997
- },
998
-
999
- move: function() {
1000
- var parentOffset = { top: 0, left: 0 },
1001
- containerTop;
1002
- var parentRightEdge = $(window).width();
1003
- if (!this.parentEl.is('body')) {
1004
- parentOffset = {
1005
- top: this.parentEl.offset().top - this.parentEl.scrollTop(),
1006
- left: this.parentEl.offset().left - this.parentEl.scrollLeft()
1007
- };
1008
- parentRightEdge = this.parentEl[0].clientWidth + this.parentEl.offset().left;
1009
- }
1010
-
1011
- if (this.drops == 'up')
1012
- containerTop = this.element.offset().top - this.container.outerHeight() - parentOffset.top;
1013
- else
1014
- containerTop = this.element.offset().top + this.element.outerHeight() - parentOffset.top;
1015
- this.container[this.drops == 'up' ? 'addClass' : 'removeClass']('dropup');
1016
-
1017
- if (this.opens == 'left') {
1018
- this.container.css({
1019
- top: containerTop,
1020
- right: parentRightEdge - this.element.offset().left - this.element.outerWidth() - 11,
1021
- left: 'auto'
1022
- });
1023
- if (this.container.offset().left < 0) {
1024
- this.container.css({
1025
- right: 'auto',
1026
- left: 9
1027
- });
1028
- }
1029
- } else if (this.opens == 'center') {
1030
- this.container.css({
1031
- top: containerTop,
1032
- left: this.element.offset().left - parentOffset.left + this.element.outerWidth() / 2
1033
- - this.container.outerWidth() / 2,
1034
- right: 'auto'
1035
- });
1036
- if (this.container.offset().left < 0) {
1037
- this.container.css({
1038
- right: 'auto',
1039
- left: 9
1040
- });
1041
- }
1042
- } else {
1043
- this.container.css({
1044
- top: containerTop,
1045
- left: this.element.offset().left - parentOffset.left,
1046
- right: 'auto'
1047
- });
1048
- if (this.container.offset().left + this.container.outerWidth() > $(window).width()) {
1049
- this.container.css({
1050
- left: 'auto',
1051
- right: 0
1052
- });
1053
- }
1054
- }
1055
- },
1056
-
1057
- show: function(e) {
1058
- if (this.isShowing) return;
1059
-
1060
- // Create a click proxy that is private to this instance of datepicker, for unbinding
1061
- this._outsideClickProxy = $.proxy(function(e) { this.outsideClick(e); }, this);
1062
-
1063
- // Bind global datepicker mousedown for hiding and
1064
- $(document)
1065
- .on('mousedown.daterangepicker', this._outsideClickProxy)
1066
- // also support mobile devices
1067
- .on('touchend.daterangepicker', this._outsideClickProxy)
1068
- // also explicitly play nice with Bootstrap dropdowns, which stopPropagation when clicking them
1069
- .on('click.daterangepicker', '[data-toggle=dropdown]', this._outsideClickProxy)
1070
- // and also close when focus changes to outside the picker (eg. tabbing between controls)
1071
- .on('focusin.daterangepicker', this._outsideClickProxy);
1072
-
1073
- // Reposition the picker if the window is resized while it's open
1074
- $(window).on('resize.daterangepicker', $.proxy(function(e) { this.move(e); }, this));
1075
-
1076
- this.oldStartDate = this.startDate.clone();
1077
- this.oldEndDate = this.endDate.clone();
1078
- this.previousRightTime = this.endDate.clone();
1079
-
1080
- this.updateView();
1081
- this.container.show();
1082
- this.move();
1083
- this.element.trigger('show.daterangepicker', this);
1084
- this.isShowing = true;
1085
- },
1086
-
1087
- hide: function(e) {
1088
- if (!this.isShowing) return;
1089
-
1090
- //incomplete date selection, revert to last values
1091
- if (!this.endDate) {
1092
- this.startDate = this.oldStartDate.clone();
1093
- this.endDate = this.oldEndDate.clone();
1094
- }
1095
-
1096
- //if a new date range was selected, invoke the user callback function
1097
- if (!this.startDate.isSame(this.oldStartDate) || !this.endDate.isSame(this.oldEndDate))
1098
- this.callback(this.startDate, this.endDate, this.chosenLabel);
1099
-
1100
- //if picker is attached to a text input, update it
1101
- this.updateElement();
1102
-
1103
- $(document).off('.daterangepicker');
1104
- $(window).off('.daterangepicker');
1105
- this.container.hide();
1106
- this.element.trigger('hide.daterangepicker', this);
1107
- this.isShowing = false;
1108
- },
1109
-
1110
- toggle: function(e) {
1111
- if (this.isShowing) {
1112
- this.hide();
1113
- } else {
1114
- this.show();
1115
- }
1116
- },
1117
-
1118
- outsideClick: function(e) {
1119
- var target = $(e.target);
1120
- // if the page is clicked anywhere except within the daterangerpicker/button
1121
- // itself then call this.hide()
1122
- if (
1123
- // ie modal dialog fix
1124
- e.type == "focusin" ||
1125
- target.closest(this.element).length ||
1126
- target.closest(this.container).length ||
1127
- target.closest('.calendar-table').length
1128
- ) return;
1129
- this.hide();
1130
- },
1131
-
1132
- showCalendars: function() {
1133
- this.container.addClass('show-calendar');
1134
- this.move();
1135
- this.element.trigger('showCalendar.daterangepicker', this);
1136
- },
1137
-
1138
- hideCalendars: function() {
1139
- this.container.removeClass('show-calendar');
1140
- this.element.trigger('hideCalendar.daterangepicker', this);
1141
- },
1142
-
1143
- hoverRange: function(e) {
1144
-
1145
- //ignore mouse movements while an above-calendar text input has focus
1146
- if (this.container.find('input[name=daterangepicker_start]').is(":focus") || this.container.find('input[name=daterangepicker_end]').is(":focus"))
1147
- return;
1148
-
1149
- var label = e.target.innerHTML;
1150
- if (label == this.locale.customRangeLabel) {
1151
- this.updateView();
1152
- } else {
1153
- var dates = this.ranges[label];
1154
- this.container.find('input[name=daterangepicker_start]').val(dates[0].format(this.locale.format));
1155
- this.container.find('input[name=daterangepicker_end]').val(dates[1].format(this.locale.format));
1156
- }
1157
-
1158
- },
1159
-
1160
- clickRange: function(e) {
1161
- var label = e.target.innerHTML;
1162
- this.chosenLabel = label;
1163
- if (label == this.locale.customRangeLabel) {
1164
- this.showCalendars();
1165
- } else {
1166
- var dates = this.ranges[label];
1167
- this.startDate = dates[0];
1168
- this.endDate = dates[1];
1169
-
1170
- if (!this.timePicker) {
1171
- this.startDate.startOf('day');
1172
- this.endDate.endOf('day');
1173
- }
1174
- if (!this.alwaysShowCalendars)
1175
- this.hideCalendars();
1176
- this.clickApply_custom();
1177
- }
1178
- },
1179
-
1180
- clickPrev: function(e) {
1181
- var cal = $(e.target).parents('.calendar');
1182
- if (cal.hasClass('left')) {
1183
- this.leftCalendar.month.subtract(1, 'month');
1184
- if (this.linkedCalendars)
1185
- this.rightCalendar.month.subtract(1, 'month');
1186
- } else {
1187
- this.rightCalendar.month.subtract(1, 'month');
1188
- }
1189
- this.updateCalendars();
1190
- },
1191
-
1192
- clickNext: function(e) {
1193
- var cal = $(e.target).parents('.calendar');
1194
- if (cal.hasClass('left')) {
1195
- this.leftCalendar.month.add(1, 'month');
1196
- } else {
1197
- this.rightCalendar.month.add(1, 'month');
1198
- if (this.linkedCalendars)
1199
- this.leftCalendar.month.add(1, 'month');
1200
- }
1201
- this.updateCalendars();
1202
- },
1203
-
1204
- hoverDate: function(e) {
1205
-
1206
- //ignore mouse movements while an above-calendar text input has focus
1207
- if (this.container.find('input[name=daterangepicker_start]').is(":focus") || this.container.find('input[name=daterangepicker_end]').is(":focus"))
1208
- return;
1209
-
1210
- //ignore dates that can't be selected
1211
- if (!$(e.target).hasClass('available')) return;
1212
-
1213
- //have the text inputs above calendars reflect the date being hovered over
1214
- var title = $(e.target).attr('data-title');
1215
- var row = title.substr(1, 1);
1216
- var col = title.substr(3, 1);
1217
- var cal = $(e.target).parents('.calendar');
1218
- var date = cal.hasClass('left') ? this.leftCalendar.calendar[row][col] : this.rightCalendar.calendar[row][col];
1219
-
1220
- if (this.endDate) {
1221
- this.container.find('input[name=daterangepicker_start]').val(date.format(this.locale.format));
1222
- } else {
1223
- this.container.find('input[name=daterangepicker_end]').val(date.format(this.locale.format));
1224
- }
1225
-
1226
- //highlight the dates between the start date and the date being hovered as a potential end date
1227
- var leftCalendar = this.leftCalendar;
1228
- var rightCalendar = this.rightCalendar;
1229
- var startDate = this.startDate;
1230
- if (!this.endDate) {
1231
- this.container.find('.calendar td').each(function(index, el) {
1232
-
1233
- //skip week numbers, only look at dates
1234
- if ($(el).hasClass('week')) return;
1235
-
1236
- var title = $(el).attr('data-title');
1237
- var row = title.substr(1, 1);
1238
- var col = title.substr(3, 1);
1239
- var cal = $(el).parents('.calendar');
1240
- var dt = cal.hasClass('left') ? leftCalendar.calendar[row][col] : rightCalendar.calendar[row][col];
1241
-
1242
- if (dt.isAfter(startDate) && dt.isBefore(date)) {
1243
- $(el).addClass('in-range');
1244
- } else {
1245
- $(el).removeClass('in-range');
1246
- }
1247
-
1248
- });
1249
- }
1250
-
1251
- },
1252
-
1253
- clickDate: function(e) {
1254
-
1255
- if (!$(e.target).hasClass('available')) return;
1256
-
1257
- var title = $(e.target).attr('data-title');
1258
- var row = title.substr(1, 1);
1259
- var col = title.substr(3, 1);
1260
- var cal = $(e.target).parents('.calendar');
1261
- var date = cal.hasClass('left') ? this.leftCalendar.calendar[row][col] : this.rightCalendar.calendar[row][col];
1262
-
1263
- //
1264
- // this function needs to do a few things:
1265
- // * alternate between selecting a start and end date for the range,
1266
- // * if the time picker is enabled, apply the hour/minute/second from the select boxes to the clicked date
1267
- // * if autoapply is enabled, and an end date was chosen, apply the selection
1268
- // * if single date picker mode, and time picker isn't enabled, apply the selection immediately
1269
- //
1270
-
1271
- if (this.endDate || date.isBefore(this.startDate, 'day')) {
1272
- if (this.timePicker) {
1273
- var hour = parseInt(this.container.find('.left .hourselect').val(), 10);
1274
- if (!this.timePicker24Hour) {
1275
- var ampm = this.container.find('.left .ampmselect').val();
1276
- if (ampm === 'PM' && hour < 12)
1277
- hour += 12;
1278
- if (ampm === 'AM' && hour === 12)
1279
- hour = 0;
1280
- }
1281
- var minute = parseInt(this.container.find('.left .minuteselect').val(), 10);
1282
- var second = this.timePickerSeconds ? parseInt(this.container.find('.left .secondselect').val(), 10) : 0;
1283
- date = date.clone().hour(hour).minute(minute).second(second);
1284
- }
1285
- this.endDate = null;
1286
- this.setStartDate(date.clone());
1287
- } else if (!this.endDate && date.isBefore(this.startDate)) {
1288
- //special case: clicking the same date for start/end,
1289
- //but the time of the end date is before the start date
1290
- this.setEndDate(this.startDate.clone());
1291
- } else {
1292
- if (this.timePicker) {
1293
- var hour = parseInt(this.container.find('.right .hourselect').val(), 10);
1294
- if (!this.timePicker24Hour) {
1295
- var ampm = this.container.find('.right .ampmselect').val();
1296
- if (ampm === 'PM' && hour < 12)
1297
- hour += 12;
1298
- if (ampm === 'AM' && hour === 12)
1299
- hour = 0;
1300
- }
1301
- var minute = parseInt(this.container.find('.right .minuteselect').val(), 10);
1302
- var second = this.timePickerSeconds ? parseInt(this.container.find('.right .secondselect').val(), 10) : 0;
1303
- date = date.clone().hour(hour).minute(minute).second(second);
1304
- }
1305
- this.setEndDate(date.clone());
1306
- if (this.autoApply) {
1307
- this.calculateChosenLabel();
1308
- this.clickApply();
1309
- }
1310
- }
1311
-
1312
- if (this.singleDatePicker) {
1313
- this.setEndDate(this.startDate);
1314
- if (!this.timePicker)
1315
- this.clickApply();
1316
- }
1317
-
1318
- this.updateView();
1319
-
1320
- },
1321
-
1322
- calculateChosenLabel: function() {
1323
- var customRange = true;
1324
- var i = 0;
1325
- for (var range in this.ranges) {
1326
- if (this.timePicker) {
1327
- if (this.startDate.isSame(this.ranges[range][0]) && this.endDate.isSame(this.ranges[range][1])) {
1328
- customRange = false;
1329
- this.chosenLabel = this.container.find('.ranges li:eq(' + i + ')').addClass('active').html();
1330
- break;
1331
- }
1332
- } else {
1333
- //ignore times when comparing dates if time picker is not enabled
1334
- if (this.startDate.format('YYYY-MM-DD') == this.ranges[range][0].format('YYYY-MM-DD') && this.endDate.format('YYYY-MM-DD') == this.ranges[range][1].format('YYYY-MM-DD')) {
1335
- customRange = false;
1336
- this.chosenLabel = this.container.find('.ranges li:eq(' + i + ')').addClass('active').html();
1337
- break;
1338
- }
1339
- }
1340
- i++;
1341
- }
1342
- if (customRange) {
1343
- this.chosenLabel = this.container.find('.ranges li:last').addClass('active').html();
1344
- this.showCalendars();
1345
- }
1346
- },
1347
-
1348
- clickApply: function(e) {
1349
- this.hide();
1350
- this.element.trigger('apply.daterangepicker', this);
1351
- },
1352
- clickApply_custom: function(e) {
1353
- this.container.find('.ranges li:last').mouseenter();
1354
- this.element.trigger('apply.daterangepicker', this);
1355
- },
1356
-
1357
- clickCancel: function(e) {
1358
- this.startDate = this.oldStartDate;
1359
- this.endDate = this.oldEndDate;
1360
- this.hide();
1361
- this.element.trigger('cancel.daterangepicker', this);
1362
- },
1363
-
1364
- monthOrYearChanged: function(e) {
1365
- var isLeft = $(e.target).closest('.calendar').hasClass('left'),
1366
- leftOrRight = isLeft ? 'left' : 'right',
1367
- cal = this.container.find('.calendar.'+leftOrRight);
1368
-
1369
- // Month must be Number for new moment versions
1370
- var month = parseInt(cal.find('.monthselect').val(), 10);
1371
- var year = cal.find('.yearselect').val();
1372
-
1373
- if (!isLeft) {
1374
- if (year < this.startDate.year() || (year == this.startDate.year() && month < this.startDate.month())) {
1375
- month = this.startDate.month();
1376
- year = this.startDate.year();
1377
- }
1378
- }
1379
-
1380
- if (this.minDate) {
1381
- if (year < this.minDate.year() || (year == this.minDate.year() && month < this.minDate.month())) {
1382
- month = this.minDate.month();
1383
- year = this.minDate.year();
1384
- }
1385
- }
1386
-
1387
- if (this.maxDate) {
1388
- if (year > this.maxDate.year() || (year == this.maxDate.year() && month > this.maxDate.month())) {
1389
- month = this.maxDate.month();
1390
- year = this.maxDate.year();
1391
- }
1392
- }
1393
-
1394
- if (isLeft) {
1395
- this.leftCalendar.month.month(month).year(year);
1396
- if (this.linkedCalendars)
1397
- this.rightCalendar.month = this.leftCalendar.month.clone().add(1, 'month');
1398
- } else {
1399
- this.rightCalendar.month.month(month).year(year);
1400
- if (this.linkedCalendars)
1401
- this.leftCalendar.month = this.rightCalendar.month.clone().subtract(1, 'month');
1402
- }
1403
- this.updateCalendars();
1404
- },
1405
-
1406
- timeChanged: function(e) {
1407
-
1408
- var cal = $(e.target).closest('.calendar'),
1409
- isLeft = cal.hasClass('left');
1410
-
1411
- var hour = parseInt(cal.find('.hourselect').val(), 10);
1412
- var minute = parseInt(cal.find('.minuteselect').val(), 10);
1413
- var second = this.timePickerSeconds ? parseInt(cal.find('.secondselect').val(), 10) : 0;
1414
-
1415
- if (!this.timePicker24Hour) {
1416
- var ampm = cal.find('.ampmselect').val();
1417
- if (ampm === 'PM' && hour < 12)
1418
- hour += 12;
1419
- if (ampm === 'AM' && hour === 12)
1420
- hour = 0;
1421
- }
1422
-
1423
- if (isLeft) {
1424
- var start = this.startDate.clone();
1425
- start.hour(hour);
1426
- start.minute(minute);
1427
- start.second(second);
1428
- this.setStartDate(start);
1429
- if (this.singleDatePicker) {
1430
- this.endDate = this.startDate.clone();
1431
- } else if (this.endDate && this.endDate.format('YYYY-MM-DD') == start.format('YYYY-MM-DD') && this.endDate.isBefore(start)) {
1432
- this.setEndDate(start.clone());
1433
- }
1434
- } else if (this.endDate) {
1435
- var end = this.endDate.clone();
1436
- end.hour(hour);
1437
- end.minute(minute);
1438
- end.second(second);
1439
- this.setEndDate(end);
1440
- }
1441
-
1442
- //update the calendars so all clickable dates reflect the new time component
1443
- this.updateCalendars();
1444
-
1445
- //update the form inputs above the calendars with the new time
1446
- this.updateFormInputs();
1447
-
1448
- //re-render the time pickers because changing one selection can affect what's enabled in another
1449
- this.renderTimePicker('left');
1450
- this.renderTimePicker('right');
1451
-
1452
- },
1453
-
1454
- formInputsChanged: function(e) {
1455
- var isRight = $(e.target).closest('.calendar').hasClass('right');
1456
- var start = moment(this.container.find('input[name="daterangepicker_start"]').val(), this.locale.format);
1457
- var end = moment(this.container.find('input[name="daterangepicker_end"]').val(), this.locale.format);
1458
-
1459
- if (start.isValid() && end.isValid()) {
1460
-
1461
- if (isRight && end.isBefore(start))
1462
- start = end.clone();
1463
-
1464
- this.setStartDate(start);
1465
- this.setEndDate(end);
1466
-
1467
- if (isRight) {
1468
- this.container.find('input[name="daterangepicker_start"]').val(this.startDate.format(this.locale.format));
1469
- } else {
1470
- this.container.find('input[name="daterangepicker_end"]').val(this.endDate.format(this.locale.format));
1471
- }
1472
-
1473
- }
1474
-
1475
- this.updateCalendars();
1476
- if (this.timePicker) {
1477
- this.renderTimePicker('left');
1478
- this.renderTimePicker('right');
1479
- }
1480
- },
1481
-
1482
- elementChanged: function() {
1483
- if (!this.element.is('input')) return;
1484
- if (!this.element.val().length) return;
1485
- if (this.element.val().length < this.locale.format.length) return;
1486
-
1487
- var dateString = this.element.val().split(this.locale.separator),
1488
- start = null,
1489
- end = null;
1490
-
1491
- if (dateString.length === 2) {
1492
- start = moment(dateString[0], this.locale.format);
1493
- end = moment(dateString[1], this.locale.format);
1494
- }
1495
-
1496
- if (this.singleDatePicker || start === null || end === null) {
1497
- start = moment(this.element.val(), this.locale.format);
1498
- end = start;
1499
- }
1500
-
1501
- if (!start.isValid() || !end.isValid()) return;
1502
-
1503
- this.setStartDate(start);
1504
- this.setEndDate(end);
1505
- this.updateView();
1506
- },
1507
-
1508
- keydown: function(e) {
1509
- //hide on tab or enter
1510
- if ((e.keyCode === 9) || (e.keyCode === 13)) {
1511
- this.hide();
1512
- }
1513
- },
1514
-
1515
- updateElement: function() {
1516
- if (this.element.is('input') && !this.singleDatePicker && this.autoUpdateInput) {
1517
- this.element.val(this.startDate.format(this.locale.format) + this.locale.separator + this.endDate.format(this.locale.format));
1518
- this.element.trigger('change');
1519
- } else if (this.element.is('input') && this.autoUpdateInput) {
1520
- this.element.val(this.startDate.format(this.locale.format));
1521
- this.element.trigger('change');
1522
- }
1523
- },
1524
-
1525
- remove: function() {
1526
- this.container.remove();
1527
- this.element.off('.daterangepicker');
1528
- this.element.removeData();
1529
- }
1530
-
1531
- };
1532
-
1533
- $.fn.daterangepicker = function(options, callback) {
1534
- this.each(function() {
1535
- var el = $(this);
1536
- if (el.data('daterangepicker'))
1537
- el.data('daterangepicker').remove();
1538
- el.data('daterangepicker', new DateRangePicker(el, options, callback));
1539
- });
1540
- return this;
1541
- };
1542
-
1543
- return DateRangePicker;
1544
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1545
  }));
1
+ /**
2
+ * @version: 2.1.19
3
+ * @author: Dan Grossman http://www.dangrossman.info/
4
+ * @copyright: Copyright (c) 2012-2015 Dan Grossman. All rights reserved.
5
+ * @license: Licensed under the MIT license. See http://www.opensource.org/licenses/mit-license.php
6
+ * @website: https://www.improvely.com/
7
+ */
8
+
9
+ (function(root, factory) {
10
+
11
+ if (typeof define === 'function' && define.amd) {
12
+ define(['moment', 'jquery', 'exports'], function(momentjs, $, exports) {
13
+ root.daterangepicker = factory(root, exports, momentjs, $);
14
+ });
15
+
16
+ } else if (typeof exports !== 'undefined') {
17
+ var momentjs = require('moment');
18
+ var jQuery = (typeof window != 'undefined') ? window.jQuery : undefined; //isomorphic issue
19
+ if (!jQuery) {
20
+ try {
21
+ jQuery = require('jquery');
22
+ if (!jQuery.fn) jQuery.fn = {}; //isomorphic issue
23
+ } catch (err) {
24
+ if (!jQuery) throw new Error('jQuery dependency not found');
25
+ }
26
+ }
27
+
28
+ factory(root, exports, momentjs, jQuery);
29
+
30
+ // Finally, as a browser global.
31
+ } else {
32
+ root.daterangepicker = factory(root, {}, root.moment || moment, (root.jQuery || root.Zepto || root.ender || root.$));
33
+ }
34
+
35
+ }(this || {}, function(root, daterangepicker, moment, $) { // 'this' doesn't exist on a server
36
+
37
+ var DateRangePicker = function(element, options, cb) {
38
+
39
+ //default settings for options
40
+ this.parentEl = 'body';
41
+ this.element = $(element);
42
+ this.startDate = moment().startOf('day');
43
+ this.endDate = moment().endOf('day');
44
+ this.minDate = false;
45
+ this.maxDate = false;
46
+ this.dateLimit = false;
47
+ this.autoApply = false;
48
+ this.singleDatePicker = false;
49
+ this.showDropdowns = false;
50
+ this.showWeekNumbers = false;
51
+ this.showISOWeekNumbers = false;
52
+ this.timePicker = false;
53
+ this.timePicker24Hour = false;
54
+ this.timePickerIncrement = 1;
55
+ this.timePickerSeconds = false;
56
+ this.linkedCalendars = true;
57
+ this.autoUpdateInput = true;
58
+ this.alwaysShowCalendars = false;
59
+ this.ranges = {};
60
+
61
+ this.opens = 'right';
62
+ if (this.element.hasClass('pull-right'))
63
+ this.opens = 'left';
64
+
65
+ this.drops = 'down';
66
+ if (this.element.hasClass('dropup'))
67
+ this.drops = 'up';
68
+
69
+ this.buttonClasses = 'btn btn-sm';
70
+ this.applyClass = 'btn-success';
71
+ this.cancelClass = 'btn-default';
72
+
73
+ this.locale = {
74
+ format: 'MM/DD/YYYY',
75
+ separator: ' - ',
76
+ applyLabel: 'Apply',
77
+ cancelLabel: 'Cancel',
78
+ weekLabel: 'W',
79
+ customRangeLabel: 'Custom Range',
80
+ daysOfWeek: moment.weekdaysMin(),
81
+ monthNames: moment.monthsShort(),
82
+ firstDay: moment.localeData().firstDayOfWeek()
83
+ };
84
+
85
+ this.callback = function() { };
86
+
87
+ //some state information
88
+ this.isShowing = false;
89
+ this.leftCalendar = {};
90
+ this.rightCalendar = {};
91
+
92
+ //custom options from user
93
+ if (typeof options !== 'object' || options === null)
94
+ options = {};
95
+
96
+ //allow setting options with data attributes
97
+ //data-api options will be overwritten with custom javascript options
98
+ options = $.extend(this.element.data(), options);
99
+
100
+ //html template for the picker UI
101
+ if (typeof options.template !== 'string' && !(options.template instanceof $))
102
+ options.template = '<div class="daterangepicker dropdown-menu">' +
103
+ '<div class="calendar left">' +
104
+ '<div class="daterangepicker_input">' +
105
+ '<input class="input-mini" type="text" name="daterangepicker_start" value="" />' +
106
+ '<i class="fa fa-calendar glyphicon glyphicon-calendar"></i>' +
107
+ '<div class="calendar-time">' +
108
+ '<div></div>' +
109
+ '<i class="fa fa-clock-o glyphicon glyphicon-time"></i>' +
110
+ '</div>' +
111
+ '</div>' +
112
+ '<div class="calendar-table"></div>' +
113
+ '</div>' +
114
+ '<div class="calendar right">' +
115
+ '<div class="daterangepicker_input">' +
116
+ '<input class="input-mini" type="text" name="daterangepicker_end" value="" />' +
117
+ '<i class="fa fa-calendar glyphicon glyphicon-calendar"></i>' +
118
+ '<div class="calendar-time">' +
119
+ '<div></div>' +
120
+ '<i class="fa fa-clock-o glyphicon glyphicon-time"></i>' +
121
+ '</div>' +
122
+ '</div>' +
123
+ '<div class="calendar-table"></div>' +
124
+ '</div>' +
125
+ '<div class="ranges">' +
126
+ '<div class="range_inputs">' +
127
+ '<button class="applyBtn" disabled="disabled" type="button"></button> ' +
128
+ '<button class="cancelBtn" type="button"></button>' +
129
+ '</div>' +
130
+ '</div>' +
131
+ '</div>';
132
+
133
+ this.parentEl = (options.parentEl && $(options.parentEl).length) ? $(options.parentEl) : $(this.parentEl);
134
+ this.container = $(options.template).appendTo(this.parentEl);
135
+
136
+ //
137
+ // handle all the possible options overriding defaults
138
+ //
139
+
140
+ if (typeof options.locale === 'object') {
141
+
142
+ if (typeof options.locale.format === 'string')
143
+ this.locale.format = options.locale.format;
144
+
145
+ if (typeof options.locale.separator === 'string')
146
+ this.locale.separator = options.locale.separator;
147
+
148
+ if (typeof options.locale.daysOfWeek === 'object')
149
+ this.locale.daysOfWeek = options.locale.daysOfWeek.slice();
150
+
151
+ if (typeof options.locale.monthNames === 'object')
152
+ this.locale.monthNames = options.locale.monthNames.slice();
153
+
154
+ if (typeof options.locale.firstDay === 'number')
155
+ this.locale.firstDay = options.locale.firstDay;
156
+
157
+ if (typeof options.locale.applyLabel === 'string')
158
+ this.locale.applyLabel = options.locale.applyLabel;
159
+
160
+ if (typeof options.locale.cancelLabel === 'string')
161
+ this.locale.cancelLabel = options.locale.cancelLabel;
162
+
163
+ if (typeof options.locale.weekLabel === 'string')
164
+ this.locale.weekLabel = options.locale.weekLabel;
165
+
166
+ if (typeof options.locale.customRangeLabel === 'string')
167
+ this.locale.customRangeLabel = options.locale.customRangeLabel;
168
+
169
+ }
170
+ if (typeof options.startDate === 'string')
171
+ this.startDate = moment(options.startDate, this.locale.format);
172
+
173
+ if (typeof options.endDate === 'string')
174
+ this.endDate = moment(options.endDate, this.locale.format);
175
+
176
+ if (typeof options.minDate === 'string')
177
+ this.minDate = moment(options.minDate, this.locale.format);
178
+
179
+ if (typeof options.maxDate === 'string')
180
+ this.maxDate = moment(options.maxDate, this.locale.format);
181
+
182
+ if (typeof options.startDate === 'object')
183
+ this.startDate = moment(options.startDate);
184
+
185
+ if (typeof options.endDate === 'object')
186
+ this.endDate = moment(options.endDate);
187
+
188
+ if (typeof options.minDate === 'object')
189
+ this.minDate = moment(options.minDate);
190
+
191
+ if (typeof options.maxDate === 'object')
192
+ this.maxDate = moment(options.maxDate);
193
+
194
+ // sanity check for bad options
195
+ if (this.minDate && this.startDate.isBefore(this.minDate))
196
+ this.startDate = this.minDate.clone();
197
+
198
+ // sanity check for bad options
199
+ if (this.maxDate && this.endDate.isAfter(this.maxDate))
200
+ this.endDate = this.maxDate.clone();
201
+
202
+ if (typeof options.applyClass === 'string')
203
+ this.applyClass = options.applyClass;
204
+
205
+ if (typeof options.cancelClass === 'string')
206
+ this.cancelClass = options.cancelClass;
207
+
208
+ if (typeof options.dateLimit === 'object')
209
+ this.dateLimit = options.dateLimit;
210
+
211
+ if (typeof options.opens === 'string')
212
+ this.opens = options.opens;
213
+
214
+ if (typeof options.drops === 'string')
215
+ this.drops = options.drops;
216
+
217
+ if (typeof options.showWeekNumbers === 'boolean')
218
+ this.showWeekNumbers = options.showWeekNumbers;
219
+
220
+ if (typeof options.showISOWeekNumbers === 'boolean')
221
+ this.showISOWeekNumbers = options.showISOWeekNumbers;
222
+
223
+ if (typeof options.buttonClasses === 'string')
224
+ this.buttonClasses = options.buttonClasses;
225
+
226
+ if (typeof options.buttonClasses === 'object')
227
+ this.buttonClasses = options.buttonClasses.join(' ');
228
+
229
+ if (typeof options.showDropdowns === 'boolean')
230
+ this.showDropdowns = options.showDropdowns;
231
+
232
+ if (typeof options.singleDatePicker === 'boolean') {
233
+ this.singleDatePicker = options.singleDatePicker;
234
+ if (this.singleDatePicker)
235
+ this.endDate = this.startDate.clone();
236
+ }
237
+
238
+ if (typeof options.timePicker === 'boolean')
239
+ this.timePicker = options.timePicker;
240
+
241
+ if (typeof options.timePickerSeconds === 'boolean')
242
+ this.timePickerSeconds = options.timePickerSeconds;
243
+
244
+ if (typeof options.timePickerIncrement === 'number')
245
+ this.timePickerIncrement = options.timePickerIncrement;
246
+
247
+ if (typeof options.timePicker24Hour === 'boolean')
248
+ this.timePicker24Hour = options.timePicker24Hour;
249
+
250
+ if (typeof options.autoApply === 'boolean')
251
+ this.autoApply = options.autoApply;
252
+
253
+ if (typeof options.autoUpdateInput === 'boolean')
254
+ this.autoUpdateInput = options.autoUpdateInput;
255
+
256
+ if (typeof options.linkedCalendars === 'boolean')
257
+ this.linkedCalendars = options.linkedCalendars;
258
+
259
+ if (typeof options.isInvalidDate === 'function')
260
+ this.isInvalidDate = options.isInvalidDate;
261
+
262
+ if (typeof options.alwaysShowCalendars === 'boolean')
263
+ this.alwaysShowCalendars = options.alwaysShowCalendars;
264
+
265
+ // update day names order to firstDay
266
+ if (this.locale.firstDay != 0) {
267
+ var iterator = this.locale.firstDay;
268
+ while (iterator > 0) {
269
+ this.locale.daysOfWeek.push(this.locale.daysOfWeek.shift());
270
+ iterator--;
271
+ }
272
+ }
273
+
274
+ var start, end, range;
275
+ //if no start/end dates set, check if an input element contains initial values
276
+ if (typeof options.startDate === 'undefined' && typeof options.endDate === 'undefined') {
277
+ if ($(this.element).is('input[type=text]')) {
278
+ var val = $(this.element).val(),
279
+ split = val.split(this.locale.separator);
280
+
281
+ start = end = null;
282
+
283
+ if (split.length == 2) {
284
+ start = moment(split[0], this.locale.format);
285
+ end = moment(split[1], this.locale.format);
286
+ } else if (this.singleDatePicker && val !== "") {
287
+ start = moment(val, this.locale.format);
288
+ end = moment(val, this.locale.format);
289
+ }
290
+ if (start !== null && end !== null) {
291
+ this.setStartDate(start);
292
+ this.setEndDate(end);
293
+ }
294
+ }
295
+ }
296
+
297
+ if (typeof options.ranges === 'object') {
298
+
299
+ for (range in options.ranges) {
300
+
301
+ if (typeof options.ranges[range][0] === 'string')
302
+ start = moment(options.ranges[range][0], this.locale.format);
303
+ else
304
+ start = moment(options.ranges[range][0]);
305
+
306
+ if (typeof options.ranges[range][1] === 'string')
307
+ end = moment(options.ranges[range][1], this.locale.format);
308
+ else
309
+ end = moment(options.ranges[range][1]);
310
+
311
+ // If the start or end date exceed those allowed by the minDate or dateLimit
312
+ // options, shorten the range to the allowable period.
313
+ if (this.minDate && start.isBefore(this.minDate))
314
+ start = this.minDate.clone();
315
+
316
+ var maxDate = this.maxDate;
317
+ if (this.dateLimit && start.clone().add(this.dateLimit).isAfter(maxDate))
318
+ maxDate = start.clone().add(this.dateLimit);
319
+ if (maxDate && end.isAfter(maxDate))
320
+ end = maxDate.clone();
321
+
322
+ // If the end of the range is before the minimum or the start of the range is
323
+ // after the maximum, don't display this range option at all.
324
+ if ((this.minDate && end.isBefore(this.minDate)) || (maxDate && start.isAfter(maxDate)))
325
+ continue;
326
+
327
+ //Support unicode chars in the range names.
328
+ var elem = document.createElement('textarea');
329
+ elem.innerHTML = range;
330
+ var rangeHtml = elem.value;
331
+
332
+ this.ranges[rangeHtml] = [start, end];
333
+ }
334
+
335
+ var list = '<ul>';
336
+ for (range in this.ranges) {
337
+ list += '<li>' + range + '</li>';
338
+ }
339
+ list += '<li>' + this.locale.customRangeLabel + '</li>';
340
+ list += '</ul>';
341
+ this.container.find('.ranges').prepend(list);
342
+ }
343
+
344
+ if (typeof cb === 'function') {
345
+
346
+ this.callback = cb;
347
+ }
348
+
349
+ if (!this.timePicker) {
350
+ this.startDate = this.startDate.startOf('day');
351
+ this.endDate = this.endDate.endOf('day');
352
+ this.container.find('.calendar-time').hide();
353
+ }
354
+
355
+ //can't be used together for now
356
+ if (this.timePicker && this.autoApply)
357
+ this.autoApply = false;
358
+
359
+ if (this.autoApply && typeof options.ranges !== 'object') {
360
+ this.container.find('.ranges').hide();
361
+ } else if (this.autoApply) {
362
+ this.container.find('.applyBtn, .cancelBtn').addClass('hide');
363
+ }
364
+
365
+ if (this.singleDatePicker) {
366
+
367
+ this.container.addClass('single');
368
+ this.container.find('.calendar.left').addClass('single');
369
+ this.container.find('.calendar.left').show();
370
+ this.container.find('.calendar.right').hide();
371
+ this.container.find('.daterangepicker_input input, .daterangepicker_input i').hide();
372
+ if (!this.timePicker) {
373
+ this.container.find('.ranges').hide();
374
+ }
375
+ }
376
+
377
+ if ((typeof options.ranges === 'undefined' && !this.singleDatePicker) || this.alwaysShowCalendars) {
378
+ this.container.addClass('show-calendar');
379
+ }
380
+
381
+ this.container.addClass('opens' + this.opens);
382
+
383
+ //swap the position of the predefined ranges if opens right
384
+ if (typeof options.ranges !== 'undefined' && this.opens == 'right') {
385
+ var ranges = this.container.find('.ranges');
386
+ var html = ranges.clone();
387
+ ranges.remove();
388
+ this.container.find('.calendar.left').parent().prepend(html);
389
+ }
390
+
391
+ //apply CSS classes and labels to buttons
392
+ this.container.find('.applyBtn, .cancelBtn').addClass(this.buttonClasses);
393
+ if (this.applyClass.length)
394
+ this.container.find('.applyBtn').addClass(this.applyClass);
395
+ if (this.cancelClass.length)
396
+ this.container.find('.cancelBtn').addClass(this.cancelClass);
397
+ this.container.find('.applyBtn').html(this.locale.applyLabel);
398
+ this.container.find('.cancelBtn').html(this.locale.cancelLabel);
399
+
400
+ //
401
+ // event listeners
402
+ //
403
+
404
+ this.container.find('.calendar')
405
+ .on('click.daterangepicker', '.prev', $.proxy(this.clickPrev, this))
406
+ .on('click.daterangepicker', '.next', $.proxy(this.clickNext, this))
407
+ .on('click.daterangepicker', 'td.available', $.proxy(this.clickDate, this))
408
+ .on('mouseenter.daterangepicker', 'td.available', $.proxy(this.hoverDate, this))
409
+ .on('mouseleave.daterangepicker', 'td.available', $.proxy(this.updateFormInputs, this))
410
+ .on('change.daterangepicker', 'select.yearselect', $.proxy(this.monthOrYearChanged, this))
411
+ .on('change.daterangepicker', 'select.monthselect', $.proxy(this.monthOrYearChanged, this))
412
+ .on('change.daterangepicker', 'select.hourselect,select.minuteselect,select.secondselect,select.ampmselect', $.proxy(this.timeChanged, this))
413
+ .on('click.daterangepicker', '.daterangepicker_input input', $.proxy(this.showCalendars, this))
414
+ //.on('keyup.daterangepicker', '.daterangepicker_input input', $.proxy(this.formInputsChanged, this))
415
+ .on('change.daterangepicker', '.daterangepicker_input input', $.proxy(this.formInputsChanged, this));
416
+
417
+ this.container.find('.ranges')
418
+ .on('click.daterangepicker', 'button.applyBtn', $.proxy(this.clickApply, this))
419
+ .on('click.daterangepicker', 'button.cancelBtn', $.proxy(this.clickCancel, this))
420
+ .on('click.daterangepicker', 'li', $.proxy(this.clickRange, this))
421
+ .on('mouseenter.daterangepicker', 'li', $.proxy(this.hoverRange, this))
422
+ .on('mouseleave.daterangepicker', 'li', $.proxy(this.updateFormInputs, this));
423
+
424
+ if (this.element.is('input')) {
425
+ this.element.on({
426
+ 'click.daterangepicker': $.proxy(this.show, this),
427
+ 'focus.daterangepicker': $.proxy(this.show, this),
428
+ 'keyup.daterangepicker': $.proxy(this.elementChanged, this),
429
+ 'keydown.daterangepicker': $.proxy(this.keydown, this)
430
+ });
431
+ } else {
432
+ this.element.on('click.daterangepicker', $.proxy(this.toggle, this));
433
+ }
434
+
435
+ //
436
+ // if attached to a text input, set the initial value
437
+ //
438
+
439
+ if (this.element.is('input') && !this.singleDatePicker && this.autoUpdateInput) {
440
+ this.element.val(this.startDate.format(this.locale.format) + this.locale.separator + this.endDate.format(this.locale.format));
441
+ this.element.trigger('change');
442
+ } else if (this.element.is('input') && this.autoUpdateInput) {
443
+ this.element.val(this.startDate.format(this.locale.format));
444
+ this.element.trigger('change');
445
+ }
446
+
447
+ };
448
+
449
+ DateRangePicker.prototype = {
450
+
451
+ constructor: DateRangePicker,
452
+
453
+ setStartDate: function(startDate) {
454
+ if (typeof startDate === 'string')
455
+ this.startDate = moment(startDate, this.locale.format);
456
+
457
+ if (typeof startDate === 'object')
458
+ this.startDate = moment(startDate);
459
+
460
+ if (!this.timePicker)
461
+ this.startDate = this.startDate.startOf('day');
462
+
463
+ if (this.timePicker && this.timePickerIncrement)
464
+ this.startDate.minute(Math.round(this.startDate.minute() / this.timePickerIncrement) * this.timePickerIncrement);
465
+
466
+ if (this.minDate && this.startDate.isBefore(this.minDate))
467
+ this.startDate = this.minDate;
468
+
469
+ if (this.maxDate && this.startDate.isAfter(this.maxDate))
470
+ this.startDate = this.maxDate;
471
+
472
+ if (!this.isShowing)
473
+ this.updateElement();
474
+
475
+ this.updateMonthsInView();
476
+ },
477
+
478
+ setEndDate: function(endDate) {
479
+ if (typeof endDate === 'string')
480
+ this.endDate = moment(endDate, this.locale.format);
481
+
482
+ if (typeof endDate === 'object')
483
+ this.endDate = moment(endDate);
484
+
485
+ if (!this.timePicker)
486
+ this.endDate = this.endDate.endOf('day');
487
+
488
+ if (this.timePicker && this.timePickerIncrement)
489
+ this.endDate.minute(Math.round(this.endDate.minute() / this.timePickerIncrement) * this.timePickerIncrement);
490
+
491
+ if (this.endDate.isBefore(this.startDate)){
492
+ var a = this.endDate;
493
+ this.endDate = this.startDate.clone();
494
+ this.startDate = a;
495
+ }
496
+
497
+ if(new Date(this.startDate).getTime() == new Date(endDate).getTime()){
498
+ this.endDate = this.startDate.clone();
499
+ }
500
+
501
+ if (this.maxDate && this.endDate.isAfter(this.maxDate))
502
+ this.endDate = this.maxDate;
503
+
504
+ if (this.dateLimit && this.startDate.clone().add(this.dateLimit).isBefore(this.endDate))
505
+ this.endDate = this.startDate.clone().add(this.dateLimit);
506
+
507
+ this.previousRightTime = this.endDate.clone();
508
+
509
+ if (!this.isShowing)
510
+ this.updateElement();
511
+
512
+ this.updateMonthsInView();
513
+ },
514
+
515
+ isInvalidDate: function() {
516
+ return false;
517
+ },
518
+
519
+ updateView: function() {
520
+ if (this.timePicker) {
521
+ this.renderTimePicker('left');
522
+ this.renderTimePicker('right');
523
+ if (!this.endDate) {
524
+ this.container.find('.right .calendar-time select').attr('disabled', 'disabled').addClass('disabled');
525
+ } else {
526
+ this.container.find('.right .calendar-time select').removeAttr('disabled').removeClass('disabled');
527
+ }
528
+ }
529
+ if (this.endDate) {
530
+ this.container.find('input[name="daterangepicker_end"]').removeClass('active');
531
+ this.container.find('input[name="daterangepicker_start"]').addClass('active');
532
+ } else {
533
+ this.container.find('input[name="daterangepicker_end"]').addClass('active');
534
+ this.container.find('input[name="daterangepicker_start"]').removeClass('active');
535
+ }
536
+ this.updateMonthsInView();
537
+ this.updateCalendars();
538
+ this.updateFormInputs();
539
+ },
540
+
541
+ updateMonthsInView: function() {
542
+ if (this.endDate) {
543
+
544
+ //if both dates are visible already, do nothing
545
+ if (!this.singleDatePicker && this.leftCalendar.month && this.rightCalendar.month &&
546
+ (this.startDate.format('YYYY-MM') == this.leftCalendar.month.format('YYYY-MM') || this.startDate.format('YYYY-MM') == this.rightCalendar.month.format('YYYY-MM'))
547
+ &&
548
+ (this.endDate.format('YYYY-MM') == this.leftCalendar.month.format('YYYY-MM') || this.endDate.format('YYYY-MM') == this.rightCalendar.month.format('YYYY-MM'))
549
+ ) {
550
+ return;
551
+ }
552
+
553
+ this.leftCalendar.month = this.startDate.clone().date(2);
554
+ if (!this.linkedCalendars && (this.endDate.month() != this.startDate.month() || this.endDate.year() != this.startDate.year())) {
555
+ this.rightCalendar.month = this.endDate.clone().date(2);
556
+ } else {
557
+ this.rightCalendar.month = this.startDate.clone().date(2).add(1, 'month');
558
+ }
559
+
560
+ } else {
561
+ if (this.leftCalendar.month.format('YYYY-MM') != this.startDate.format('YYYY-MM') && this.rightCalendar.month.format('YYYY-MM') != this.startDate.format('YYYY-MM')) {
562
+ this.leftCalendar.month = this.startDate.clone().date(2);
563
+ this.rightCalendar.month = this.startDate.clone().date(2).add(1, 'month');
564
+ }
565
+ }
566
+ },
567
+
568
+ updateCalendars: function() {
569
+
570
+ if (this.timePicker) {
571
+ var hour, minute, second;
572
+ if (this.endDate) {
573
+ hour = parseInt(this.container.find('.left .hourselect').val(), 10);
574
+ minute = parseInt(this.container.find('.left .minuteselect').val(), 10);
575
+ second = this.timePickerSeconds ? parseInt(this.container.find('.left .secondselect').val(), 10) : 0;
576
+ if (!this.timePicker24Hour) {
577
+ var ampm = this.container.find('.left .ampmselect').val();
578
+ if (ampm === 'PM' && hour < 12)
579
+ hour += 12;
580
+ if (ampm === 'AM' && hour === 12)
581
+ hour = 0;
582
+ }
583
+ } else {
584
+ hour = parseInt(this.container.find('.right .hourselect').val(), 10);
585
+ minute = parseInt(this.container.find('.right .minuteselect').val(), 10);
586
+ second = this.timePickerSeconds ? parseInt(this.container.find('.right .secondselect').val(), 10) : 0;
587
+ if (!this.timePicker24Hour) {
588
+ var ampm = this.container.find('.right .ampmselect').val();
589
+ if (ampm === 'PM' && hour < 12)
590
+ hour += 12;
591
+ if (ampm === 'AM' && hour === 12)
592
+ hour = 0;
593
+ }
594
+ }
595
+ this.leftCalendar.month.hour(hour).minute(minute).second(second);
596
+ this.rightCalendar.month.hour(hour).minute(minute).second(second);
597
+ }
598
+
599
+ this.renderCalendar('left');
600
+ this.renderCalendar('right');
601
+
602
+ //highlight any predefined range matching the current start and end dates
603
+ this.container.find('.ranges li').removeClass('active');
604
+ if (this.endDate == null) return;
605
+
606
+ this.calculateChosenLabel();
607
+ },
608
+
609
+ renderCalendar: function(side) {
610
+
611
+ //
612
+ // Build the matrix of dates that will populate the calendar
613
+ //
614
+
615
+ var calendar = side == 'left' ? this.leftCalendar : this.rightCalendar;
616
+ var month = calendar.month.month();
617
+ var year = calendar.month.year();
618
+ var hour = calendar.month.hour();
619
+ var minute = calendar.month.minute();
620
+ var second = calendar.month.second();
621
+ var daysInMonth = moment([year, month]).daysInMonth();
622
+ var firstDay = moment([year, month, 1]);
623
+ var lastDay = moment([year, month, daysInMonth]);
624
+ var lastMonth = moment(firstDay).subtract(1, 'month').month();
625
+ var lastYear = moment(firstDay).subtract(1, 'month').year();
626
+ var daysInLastMonth = moment([lastYear, lastMonth]).daysInMonth();
627
+ var dayOfWeek = firstDay.day();
628
+
629
+ //initialize a 6 rows x 7 columns array for the calendar
630
+ var calendar = [];
631
+ calendar.firstDay = firstDay;
632
+ calendar.lastDay = lastDay;
633
+
634
+ for (var i = 0; i < 6; i++) {
635
+ calendar[i] = [];
636
+ }
637
+
638
+ //populate the calendar with date objects
639
+ var startDay = daysInLastMonth - dayOfWeek + this.locale.firstDay + 1;
640
+ if (startDay > daysInLastMonth)
641
+ startDay -= 7;
642
+
643
+ if (dayOfWeek == this.locale.firstDay)
644
+ startDay = daysInLastMonth - 6;
645
+
646
+ var curDate = moment([lastYear, lastMonth, startDay, 12, minute, second]);
647
+
648
+ var col, row;
649
+ for (var i = 0, col = 0, row = 0; i < 42; i++, col++, curDate = moment(curDate).add(24, 'hour')) {
650
+ if (i > 0 && col % 7 === 0) {
651
+ col = 0;
652
+ row++;
653
+ }
654
+ calendar[row][col] = curDate.clone().hour(hour).minute(minute).second(second);
655
+ curDate.hour(12);
656
+
657
+ if (this.minDate && calendar[row][col].format('YYYY-MM-DD') == this.minDate.format('YYYY-MM-DD') && calendar[row][col].isBefore(this.minDate) && side == 'left') {
658
+ calendar[row][col] = this.minDate.clone();
659
+ }
660
+
661
+ if (this.maxDate && calendar[row][col].format('YYYY-MM-DD') == this.maxDate.format('YYYY-MM-DD') && calendar[row][col].isAfter(this.maxDate) && side == 'right') {
662
+ calendar[row][col] = this.maxDate.clone();
663
+ }
664
+
665
+ }
666
+
667
+ //make the calendar object available to hoverDate/clickDate
668
+ if (side == 'left') {
669
+ this.leftCalendar.calendar = calendar;
670
+ } else {
671
+ this.rightCalendar.calendar = calendar;
672
+ }
673
+
674
+ //
675
+ // Display the calendar
676
+ //
677
+
678
+ var minDate = side == 'left' ? this.minDate : this.startDate;
679
+ var maxDate = this.maxDate;
680
+ var selected = side == 'left' ? this.startDate : this.endDate;
681
+
682
+ var html = '<table class="table-condensed">';
683
+ html += '<thead>';
684
+ html += '<tr>';
685
+
686
+ // add empty cell for week number
687
+ if (this.showWeekNumbers || this.showISOWeekNumbers)
688
+ html += '<th></th>';
689
+
690
+ if ((!minDate || minDate.isBefore(calendar.firstDay)) && (!this.linkedCalendars || side == 'left')) {
691
+ html += '<th class="prev available"><i class="fa fa-chevron-left glyphicon glyphicon-chevron-left"></i></th>';
692
+ } else {
693
+ html += '<th></th>';
694
+ }
695
+
696
+ var dateHtml = this.locale.monthNames[calendar[1][1].month()] + calendar[1][1].format(" YYYY");
697
+
698
+ if (this.showDropdowns) {
699
+ var currentMonth = calendar[1][1].month();
700
+ var currentYear = calendar[1][1].year();
701
+ var maxYear = (maxDate && maxDate.year()) || (currentYear + 5);
702
+ var minYear = (minDate && minDate.year()) || (currentYear - 50);
703
+ var inMinYear = currentYear == minYear;
704
+ var inMaxYear = currentYear == maxYear;
705
+
706
+ var monthHtml = '<select class="monthselect">';
707
+ for (var m = 0; m < 12; m++) {
708
+ if ((!inMinYear || m >= minDate.month()) && (!inMaxYear || m <= maxDate.month())) {
709
+ monthHtml += "<option value='" + m + "'" +
710
+ (m === currentMonth ? " selected='selected'" : "") +
711
+ ">" + this.locale.monthNames[m] + "</option>";
712
+ } else {
713
+ monthHtml += "<option value='" + m + "'" +
714
+ (m === currentMonth ? " selected='selected'" : "") +
715
+ " disabled='disabled'>" + this.locale.monthNames[m] + "</option>";
716
+ }
717
+ }
718
+ monthHtml += "</select>";
719
+
720
+ var yearHtml = '<select class="yearselect">';
721
+ for (var y = minYear; y <= maxYear; y++) {
722
+ yearHtml += '<option value="' + y + '"' +
723
+ (y === currentYear ? ' selected="selected"' : '') +
724
+ '>' + y + '</option>';
725
+ }
726
+ yearHtml += '</select>';
727
+
728
+ dateHtml = monthHtml + yearHtml;
729
+ }
730
+
731
+ html += '<th colspan="5" class="month">' + dateHtml + '</th>';
732
+ if ((!maxDate || maxDate.isAfter(calendar.lastDay)) && (!this.linkedCalendars || side == 'right' || this.singleDatePicker)) {
733
+ html += '<th class="next available"><i class="fa fa-chevron-right glyphicon glyphicon-chevron-right"></i></th>';
734
+ } else {
735
+ html += '<th></th>';
736
+ }
737
+
738
+ html += '</tr>';
739
+ html += '<tr>';
740
+
741
+ // add week number label
742
+ if (this.showWeekNumbers || this.showISOWeekNumbers)
743
+ html += '<th class="week">' + this.locale.weekLabel + '</th>';
744
+
745
+ $.each(this.locale.daysOfWeek, function(index, dayOfWeek) {
746
+ html += '<th>' + dayOfWeek + '</th>';
747
+ });
748
+
749
+ html += '</tr>';
750
+ html += '</thead>';
751
+ html += '<tbody>';
752
+
753
+ //adjust maxDate to reflect the dateLimit setting in order to
754
+ //grey out end dates beyond the dateLimit
755
+ if (this.endDate == null && this.dateLimit) {
756
+ var maxLimit = this.startDate.clone().add(this.dateLimit).endOf('day');
757
+ if (!maxDate || maxLimit.isBefore(maxDate)) {
758
+ maxDate = maxLimit;
759
+ }
760
+ }
761
+
762
+ for (var row = 0; row < 6; row++) {
763
+ html += '<tr>';
764
+
765
+ // add week number
766
+ if (this.showWeekNumbers)
767
+ html += '<td class="week">' + calendar[row][0].week() + '</td>';
768
+ else if (this.showISOWeekNumbers)
769
+ html += '<td class="week">' + calendar[row][0].isoWeek() + '</td>';
770
+
771
+ for (var col = 0; col < 7; col++) {
772
+
773
+ var classes = [];
774
+
775
+ //highlight today's date
776
+ if (calendar[row][col].isSame(new Date(), "day"))
777
+ classes.push('today');
778
+
779
+ //highlight weekends
780
+ if (calendar[row][col].isoWeekday() > 5)
781
+ classes.push('weekend');
782
+
783
+ //grey out the dates in other months displayed at beginning and end of this calendar
784
+ if (calendar[row][col].month() != calendar[1][1].month())
785
+ classes.push('off');
786
+
787
+ //don't allow selection of dates before the minimum date
788
+ if (this.minDate && calendar[row][col].isBefore(this.minDate, 'day'))
789
+ classes.push('off', 'disabled');
790
+
791
+ //don't allow selection of dates after the maximum date
792
+ if (maxDate && calendar[row][col].isAfter(maxDate, 'day'))
793
+ classes.push('off', 'disabled');
794
+
795
+ //don't allow selection of date if a custom function decides it's invalid
796
+ if (this.isInvalidDate(calendar[row][col]))
797
+ classes.push('off', 'disabled');
798
+
799
+ //highlight the currently selected start date
800
+ if (calendar[row][col].format('YYYY-MM-DD') == this.startDate.format('YYYY-MM-DD'))
801
+ classes.push('active', 'start-date');
802
+
803
+ //highlight the currently selected end date
804
+ if (this.endDate != null && calendar[row][col].format('YYYY-MM-DD') == this.endDate.format('YYYY-MM-DD'))
805
+ classes.push('active', 'end-date');
806
+
807
+ //highlight dates in-between the selected dates
808
+ if (this.endDate != null && calendar[row][col] > this.startDate && calendar[row][col] < this.endDate)
809
+ classes.push('in-range');
810
+
811
+ var cname = '', disabled = false;
812
+ for (var i = 0; i < classes.length; i++) {
813
+ cname += classes[i] + ' ';
814
+ if (classes[i] == 'disabled')
815
+ disabled = true;
816
+ }
817
+ if (!disabled)
818
+ cname += 'available';
819
+
820
+ html += '<td class="' + cname.replace(/^\s+|\s+$/g, '') + '" data-title="' + 'r' + row + 'c' + col + '">' + calendar[row][col].date() + '</td>';
821
+
822
+ }
823
+ html += '</tr>';
824
+ }
825
+
826
+ html += '</tbody>';
827
+ html += '</table>';
828
+
829
+ this.container.find('.calendar.' + side + ' .calendar-table').html(html);
830
+
831
+ },
832
+
833
+ renderTimePicker: function(side) {
834
+
835
+ var html, selected, minDate, maxDate = this.maxDate;
836
+
837
+ if (this.dateLimit && (!this.maxDate || this.startDate.clone().add(this.dateLimit).isAfter(this.maxDate)))
838
+ maxDate = this.startDate.clone().add(this.dateLimit);
839
+
840
+ if (side == 'left') {
841
+ selected = this.startDate.clone();
842
+ minDate = this.minDate;
843
+ } else if (side == 'right') {
844
+ selected = this.endDate ? this.endDate.clone() : this.previousRightTime.clone();
845
+ minDate = this.startDate;
846
+
847
+ //Preserve the time already selected
848
+ var timeSelector = this.container.find('.calendar.right .calendar-time div');
849
+ if (timeSelector.html() != '') {
850
+
851
+ selected.hour(timeSelector.find('.hourselect option:selected').val() || selected.hour());
852
+ selected.minute(timeSelector.find('.minuteselect option:selected').val() || selected.minute());
853
+ selected.second(timeSelector.find('.secondselect option:selected').val() || selected.second());
854
+
855
+ if (!this.timePicker24Hour) {
856
+ var ampm = timeSelector.find('.ampmselect option:selected').val();
857
+ if (ampm === 'PM' && selected.hour() < 12)
858
+ selected.hour(selected.hour() + 12);
859
+ if (ampm === 'AM' && selected.hour() === 12)
860
+ selected.hour(0);
861
+ }
862
+
863
+ if (selected.isBefore(this.startDate))
864
+ selected = this.startDate.clone();
865
+
866
+ if (selected.isAfter(maxDate))
867
+ selected = maxDate.clone();
868
+
869
+ }
870
+ }
871
+
872
+ //
873
+ // hours
874
+ //
875
+
876
+ html = '<select class="hourselect">';
877
+
878
+ var start = this.timePicker24Hour ? 0 : 1;
879
+ var end = this.timePicker24Hour ? 23 : 12;
880
+
881
+ for (var i = start; i <= end; i++) {
882
+ var i_in_24 = i;
883
+ if (!this.timePicker24Hour)
884
+ i_in_24 = selected.hour() >= 12 ? (i == 12 ? 12 : i + 12) : (i == 12 ? 0 : i);
885
+
886
+ var time = selected.clone().hour(i_in_24);
887
+ var disabled = false;
888
+ if (minDate && time.minute(59).isBefore(minDate))
889
+ disabled = true;
890
+ if (maxDate && time.minute(0).isAfter(maxDate))
891
+ disabled = true;
892
+
893
+ if (i_in_24 == selected.hour() && !disabled) {
894
+ html += '<option value="' + i + '" selected="selected">' + i + '</option>';
895
+ } else if (disabled) {
896
+ html += '<option value="' + i + '" disabled="disabled" class="disabled">' + i + '</option>';
897
+ } else {
898
+ html += '<option value="' + i + '">' + i + '</option>';
899
+ }
900
+ }
901
+
902
+ html += '</select> ';
903
+
904
+ //
905
+ // minutes
906
+ //
907
+
908
+ html += ': <select class="minuteselect">';
909
+
910
+ for (var i = 0; i < 60; i += this.timePickerIncrement) {
911
+ var padded = i < 10 ? '0' + i : i;
912
+ var time = selected.clone().minute(i);
913
+
914
+ var disabled = false;
915
+ if (minDate && time.second(59).isBefore(minDate))
916
+ disabled = true;
917
+ if (maxDate && time.second(0).isAfter(maxDate))
918
+ disabled = true;
919
+
920
+ if (selected.minute() == i && !disabled) {
921
+ html += '<option value="' + i + '" selected="selected">' + padded + '</option>';
922
+ } else if (disabled) {
923
+ html += '<option value="' + i + '" disabled="disabled" class="disabled">' + padded + '</option>';
924
+ } else {
925
+ html += '<option value="' + i + '">' + padded + '</option>';
926
+ }
927
+ }
928
+
929
+ html += '</select> ';
930
+
931
+ //
932
+ // seconds
933
+ //
934
+
935
+ if (this.timePickerSeconds) {
936
+ html += ': <select class="secondselect">';
937
+
938
+ for (var i = 0; i < 60; i++) {
939
+ var padded = i < 10 ? '0' + i : i;
940
+ var time = selected.clone().second(i);
941
+
942
+ var disabled = false;
943
+ if (minDate && time.isBefore(minDate))
944
+ disabled = true;
945
+ if (maxDate && time.isAfter(maxDate))
946
+ disabled = true;
947
+
948
+ if (selected.second() == i && !disabled) {
949
+ html += '<option value="' + i + '" selected="selected">' + padded + '</option>';
950
+ } else if (disabled) {
951
+ html += '<option value="' + i + '" disabled="disabled" class="disabled">' + padded + '</option>';
952
+ } else {
953
+ html += '<option value="' + i + '">' + padded + '</option>';
954
+ }
955
+ }
956
+
957
+ html += '</select> ';
958
+ }
959
+
960
+ //
961
+ // AM/PM
962
+ //
963
+
964
+ if (!this.timePicker24Hour) {
965
+ html += '<select class="ampmselect">';
966
+
967
+ var am_html = '';
968
+ var pm_html = '';
969
+
970
+ if (minDate && selected.clone().hour(12).minute(0).second(0).isBefore(minDate))
971
+ am_html = ' disabled="disabled" class="disabled"';
972
+
973
+ if (maxDate && selected.clone().hour(0).minute(0).second(0).isAfter(maxDate))
974
+ pm_html = ' disabled="disabled" class="disabled"';
975
+
976
+ if (selected.hour() >= 12) {
977
+ html += '<option value="AM"' + am_html + '>AM</option><option value="PM" selected="selected"' + pm_html + '>PM</option>';
978
+ } else {
979
+ html += '<option value="AM" selected="selected"' + am_html + '>AM</option><option value="PM"' + pm_html + '>PM</option>';
980
+ }
981
+
982
+ html += '</select>';
983
+ }
984
+
985
+ this.container.find('.calendar.' + side + ' .calendar-time div').html(html);
986
+
987
+ },
988
+
989
+ updateFormInputs: function() {
990
+
991
+ //ignore mouse movements while an above-calendar text input has focus
992
+ if (this.container.find('input[name=daterangepicker_start]').is(":focus") || this.container.find('input[name=daterangepicker_end]').is(":focus"))
993
+ return;
994
+
995
+ this.container.find('input[name=daterangepicker_start]').val(this.startDate.format(this.locale.format));
996
+ if (this.endDate)
997
+ this.container.find('input[name=daterangepicker_end]').val(this.endDate.format(this.locale.format));
998
+
999
+ if (this.singleDatePicker || (this.endDate && (this.startDate.isBefore(this.endDate) || this.startDate.isSame(this.endDate)))) {
1000
+ this.container.find('button.applyBtn').removeAttr('disabled');
1001
+ } else {
1002
+ this.container.find('button.applyBtn').attr('disabled', 'disabled');
1003
+ }
1004
+
1005
+ },
1006
+
1007
+ move: function() {
1008
+ var parentOffset = { top: 0, left: 0 },
1009
+ containerTop;
1010
+ var parentRightEdge = $(window).width();
1011
+ if (!this.parentEl.is('body')) {
1012
+ parentOffset = {
1013
+ top: this.parentEl.offset().top - this.parentEl.scrollTop(),
1014
+ left: this.parentEl.offset().left - this.parentEl.scrollLeft()
1015
+ };
1016
+ parentRightEdge = this.parentEl[0].clientWidth + this.parentEl.offset().left;
1017
+ }
1018
+
1019
+ if (this.drops == 'up')
1020
+ containerTop = this.element.offset().top - this.container.outerHeight() - parentOffset.top;
1021
+ else
1022
+ containerTop = this.element.offset().top + this.element.outerHeight() - parentOffset.top;
1023
+ this.container[this.drops == 'up' ? 'addClass' : 'removeClass']('dropup');
1024
+
1025
+ if (this.opens == 'left') {
1026
+ this.container.css({
1027
+ top: containerTop,
1028
+ right: parentRightEdge - this.element.offset().left - this.element.outerWidth() - 11,
1029
+ left: 'auto'
1030
+ });
1031
+ if (this.container.offset().left < 0) {
1032
+ this.container.css({
1033
+ right: 'auto',
1034
+ left: 9
1035
+ });
1036
+ }
1037
+ } else if (this.opens == 'center') {
1038
+ this.container.css({
1039
+ top: containerTop,
1040
+ left: this.element.offset().left - parentOffset.left + this.element.outerWidth() / 2
1041
+ - this.container.outerWidth() / 2,
1042
+ right: 'auto'
1043
+ });
1044
+ if (this.container.offset().left < 0) {
1045
+ this.container.css({
1046
+ right: 'auto',
1047
+ left: 9
1048
+ });
1049
+ }
1050
+ } else {
1051
+ this.container.css({
1052
+ top: containerTop,
1053
+ left: this.element.offset().left - parentOffset.left,
1054
+ right: 'auto'
1055
+ });
1056
+ if (this.container.offset().left + this.container.outerWidth() > $(window).width()) {
1057
+ this.container.css({
1058
+ left: 'auto',
1059
+ right: 0
1060
+ });
1061
+ }
1062
+ }
1063
+ },
1064
+
1065
+ show: function(e) {
1066
+ if (this.isShowing) return;
1067
+
1068
+ // Create a click proxy that is private to this instance of datepicker, for unbinding
1069
+ this._outsideClickProxy = $.proxy(function(e) { this.outsideClick(e); }, this);
1070
+
1071
+ // Bind global datepicker mousedown for hiding and
1072
+ $(document)
1073
+ .on('mousedown.daterangepicker', this._outsideClickProxy)
1074
+ // also support mobile devices
1075
+ .on('touchend.daterangepicker', this._outsideClickProxy)
1076
+ // also explicitly play nice with Bootstrap dropdowns, which stopPropagation when clicking them
1077
+ .on('click.daterangepicker', '[data-toggle=dropdown]', this._outsideClickProxy)
1078
+ // and also close when focus changes to outside the picker (eg. tabbing between controls)
1079
+ .on('focusin.daterangepicker', this._outsideClickProxy);
1080
+
1081
+ // Reposition the picker if the window is resized while it's open
1082
+ $(window).on('resize.daterangepicker', $.proxy(function(e) { this.move(e); }, this));
1083
+
1084
+ this.oldStartDate = this.startDate.clone();
1085
+ this.oldEndDate = this.endDate.clone();
1086
+ this.previousRightTime = this.endDate.clone();
1087
+
1088
+ this.updateView();
1089
+ this.container.show();
1090
+ this.move();
1091
+ this.element.trigger('show.daterangepicker', this);
1092
+ this.isShowing = true;
1093
+ },
1094
+
1095
+ hide: function(e) {
1096
+ if (!this.isShowing) return;
1097
+
1098
+ //incomplete date selection, revert to last values
1099
+ if (!this.endDate) {
1100
+ this.startDate = this.oldStartDate.clone();
1101
+ this.endDate = this.oldEndDate.clone();
1102
+ }
1103
+
1104
+ //if a new date range was selected, invoke the user callback function
1105
+ if (!this.startDate.isSame(this.oldStartDate) || !this.endDate.isSame(this.oldEndDate))
1106
+ this.callback(this.startDate, this.endDate, this.chosenLabel);
1107
+
1108
+ //if picker is attached to a text input, update it
1109
+ this.updateElement();
1110
+
1111
+ $(document).off('.daterangepicker');
1112
+ $(window).off('.daterangepicker');
1113
+ this.container.hide();
1114
+ this.element.trigger('hide.daterangepicker', this);
1115
+ this.isShowing = false;
1116
+ },
1117
+
1118
+ toggle: function(e) {
1119
+ if (this.isShowing) {
1120
+ this.hide();
1121
+ } else {
1122
+ this.show();
1123
+ }
1124
+ },
1125
+
1126
+ outsideClick: function(e) {
1127
+ var target = $(e.target);
1128
+ // if the page is clicked anywhere except within the daterangerpicker/button
1129
+ // itself then call this.hide()
1130
+ if (
1131
+ // ie modal dialog fix
1132
+ e.type == "focusin" ||
1133
+ target.closest(this.element).length ||
1134
+ target.closest(this.container).length ||
1135
+ target.closest('.calendar-table').length
1136
+ ) return;
1137
+ this.hide();
1138
+ },
1139
+
1140
+ showCalendars: function() {
1141
+ this.container.addClass('show-calendar');
1142
+ this.move();
1143
+ this.element.trigger('showCalendar.daterangepicker', this);
1144
+ },
1145
+
1146
+ hideCalendars: function() {
1147
+ this.container.removeClass('show-calendar');
1148
+ this.element.trigger('hideCalendar.daterangepicker', this);
1149
+ },
1150
+
1151
+ hoverRange: function(e) {
1152
+
1153
+ //ignore mouse movements while an above-calendar text input has focus
1154
+ if (this.container.find('input[name=daterangepicker_start]').is(":focus") || this.container.find('input[name=daterangepicker_end]').is(":focus"))
1155
+ return;
1156
+
1157
+ var label = e.target.innerHTML;
1158
+ if (label == this.locale.customRangeLabel) {
1159
+ this.updateView();
1160
+ } else {
1161
+ var dates = this.ranges[label];
1162
+ this.container.find('input[name=daterangepicker_start]').val(dates[0].format(this.locale.format));
1163
+ this.container.find('input[name=daterangepicker_end]').val(dates[1].format(this.locale.format));
1164
+ }
1165
+
1166
+ },
1167
+
1168
+ clickRange: function(e) {
1169
+ var label = e.target.innerHTML;
1170
+ this.chosenLabel = label;
1171
+ if (label == this.locale.customRangeLabel) {
1172
+ this.showCalendars();
1173
+ } else {
1174
+ var dates = this.ranges[label];
1175
+ this.startDate = dates[0];
1176
+ this.endDate = dates[1];
1177
+
1178
+ if (!this.timePicker) {
1179
+ this.startDate.startOf('day');
1180
+ this.endDate.endOf('day');
1181
+ }
1182
+ if (!this.alwaysShowCalendars)
1183
+ this.hideCalendars();
1184
+ this.clickApply_custom();
1185
+ }
1186
+ },
1187
+
1188
+ clickPrev: function(e) {
1189
+ var cal = $(e.target).parents('.calendar');
1190
+ if (cal.hasClass('left')) {
1191
+ this.leftCalendar.month.subtract(1, 'month');
1192
+ if (this.linkedCalendars)
1193
+ this.rightCalendar.month.subtract(1, 'month');
1194
+ } else {
1195
+ this.rightCalendar.month.subtract(1, 'month');
1196
+ }
1197
+ this.updateCalendars();
1198
+ },
1199
+
1200
+ clickNext: function(e) {
1201
+ var cal = $(e.target).parents('.calendar');
1202
+ if (cal.hasClass('left')) {
1203
+ this.leftCalendar.month.add(1, 'month');
1204
+ } else {
1205
+ this.rightCalendar.month.add(1, 'month');
1206
+ if (this.linkedCalendars)
1207
+ this.leftCalendar.month.add(1, 'month');
1208
+ }
1209
+ this.updateCalendars();
1210
+ },
1211
+
1212
+ hoverDate: function(e) {
1213
+
1214
+ //ignore mouse movements while an above-calendar text input has focus
1215
+ if (this.container.find('input[name=daterangepicker_start]').is(":focus") || this.container.find('input[name=daterangepicker_end]').is(":focus"))
1216
+ return;
1217
+
1218
+ //ignore dates that can't be selected
1219
+ if (!$(e.target).hasClass('available')) return;
1220
+
1221
+ //have the text inputs above calendars reflect the date being hovered over
1222
+ var title = $(e.target).attr('data-title');
1223
+ var row = title.substr(1, 1);
1224
+ var col = title.substr(3, 1);
1225
+ var cal = $(e.target).parents('.calendar');
1226
+ var date = cal.hasClass('left') ? this.leftCalendar.calendar[row][col] : this.rightCalendar.calendar[row][col];
1227
+
1228
+ if (this.endDate) {
1229
+ this.container.find('input[name=daterangepicker_start]').val(date.format(this.locale.format));
1230
+ } else {
1231
+ this.container.find('input[name=daterangepicker_end]').val(date.format(this.locale.format));
1232
+ }
1233
+
1234
+ //highlight the dates between the start date and the date being hovered as a potential end date
1235
+ var leftCalendar = this.leftCalendar;
1236
+ var rightCalendar = this.rightCalendar;
1237
+ var startDate = this.startDate;
1238
+ if (!this.endDate) {
1239
+ this.container.find('.calendar td').each(function(index, el) {
1240
+
1241
+ //skip week numbers, only look at dates
1242
+ if ($(el).hasClass('week')) return;
1243
+
1244
+ var title = $(el).attr('data-title');
1245
+ var row = title.substr(1, 1);
1246
+ var col = title.substr(3, 1);
1247
+ var cal = $(el).parents('.calendar');
1248
+ var dt = cal.hasClass('left') ? leftCalendar.calendar[row][col] : rightCalendar.calendar[row][col];
1249
+
1250
+ if (dt.isAfter(startDate) && dt.isBefore(date)) {
1251
+ $(el).addClass('in-range');
1252
+ } else {
1253
+ $(el).removeClass('in-range');
1254
+ }
1255
+
1256
+ });
1257
+ }
1258
+
1259
+ },
1260
+
1261
+ clickDate: function(e) {
1262
+
1263
+ if (!$(e.target).hasClass('available')) return;
1264
+
1265
+ var title = $(e.target).attr('data-title');
1266
+ var row = title.substr(1, 1);
1267
+ var col = title.substr(3, 1);
1268
+ var cal = $(e.target).parents('.calendar');
1269
+ var date = cal.hasClass('left') ? this.leftCalendar.calendar[row][col] : this.rightCalendar.calendar[row][col];
1270
+
1271
+ //
1272
+ // this function needs to do a few things:
1273
+ // * alternate between selecting a start and end date for the range,
1274
+ // * if the time picker is enabled, apply the hour/minute/second from the select boxes to the clicked date
1275
+ // * if autoapply is enabled, and an end date was chosen, apply the selection
1276
+ // * if single date picker mode, and time picker isn't enabled, apply the selection immediately
1277
+ //
1278
+
1279
+
1280
+ if (this.endDate) {
1281
+ if (this.timePicker) {
1282
+ var hour = parseInt(this.container.find('.left .hourselect').val(), 10);
1283
+ if (!this.timePicker24Hour) {
1284
+ var ampm = this.container.find('.left .ampmselect').val();
1285
+ if (ampm === 'PM' && hour < 12)
1286
+ hour += 12;
1287
+ if (ampm === 'AM' && hour === 12)
1288
+ hour = 0;
1289
+ }
1290
+ var minute = parseInt(this.container.find('.left .minuteselect').val(), 10);
1291
+ var second = this.timePickerSeconds ? parseInt(this.container.find('.left .secondselect').val(), 10) : 0;
1292
+ date = date.clone().hour(hour).minute(minute).second(second);
1293
+ }
1294
+ this.endDate = null;
1295
+ this.setStartDate(date.clone());
1296
+ }
1297
+ else if (!this.endDate && date.isBefore(this.startDate, 'day')) {
1298
+ //special case: clicking the same date for start/end,
1299
+ //but the time of the end date is before the start date
1300
+ this.setEndDate(date.clone());
1301
+ }
1302
+ else if (!this.endDate && new Date(this.startDate).getTime() == new Date(date._d).getTime()) {
1303
+ //special case: clicking the same date for start/end,
1304
+ //but the time of the end date is before the start date
1305
+ this.setEndDate(this.startDate.clone());
1306
+ }
1307
+ else {
1308
+ if (this.timePicker) {
1309
+ var hour = parseInt(this.container.find('.right .hourselect').val(), 10);
1310
+ if (!this.timePicker24Hour) {
1311
+ var ampm = this.container.find('.right .ampmselect').val();
1312
+ if (ampm === 'PM' && hour < 12)
1313
+ hour += 12;
1314
+ if (ampm === 'AM' && hour === 12)
1315
+ hour = 0;
1316
+ }
1317
+ var minute = parseInt(this.container.find('.right .minuteselect').val(), 10);
1318
+ var second = this.timePickerSeconds ? parseInt(this.container.find('.right .secondselect').val(), 10) : 0;
1319
+ date = date.clone().hour(hour).minute(minute).second(second);
1320
+ }
1321
+ this.setEndDate(date.clone());
1322
+ if (this.autoApply) {
1323
+ this.calculateChosenLabel();
1324
+ this.clickApply();
1325
+ }
1326
+ }
1327
+
1328
+ if (this.singleDatePicker) {
1329
+ this.setEndDate(this.startDate);
1330
+ if (!this.timePicker)
1331
+ this.clickApply();
1332
+ }
1333
+
1334
+ this.updateView();
1335
+
1336
+ },
1337
+
1338
+ calculateChosenLabel: function() {
1339
+ var customRange = true;
1340
+ var i = 0;
1341
+ for (var range in this.ranges) {
1342
+ if (this.timePicker) {
1343
+ if (this.startDate.isSame(this.ranges[range][0]) && this.endDate.isSame(this.ranges[range][1])) {
1344
+ customRange = false;
1345
+ this.chosenLabel = this.container.find('.ranges li:eq(' + i + ')').addClass('active').html();
1346
+ break;
1347
+ }
1348
+ } else {
1349
+ //ignore times when comparing dates if time picker is not enabled
1350
+ if (this.startDate.format('YYYY-MM-DD') == this.ranges[range][0].format('YYYY-MM-DD') && this.endDate.format('YYYY-MM-DD') == this.ranges[range][1].format('YYYY-MM-DD')) {
1351
+ customRange = false;
1352
+ this.chosenLabel = this.container.find('.ranges li:eq(' + i + ')').addClass('active').html();
1353
+ break;
1354
+ }
1355
+ }
1356
+ i++;
1357
+ }
1358
+ if (customRange) {
1359
+ this.chosenLabel = this.container.find('.ranges li:last').addClass('active').html();
1360
+ this.showCalendars();
1361
+ }
1362
+ },
1363
+
1364
+ clickApply: function(e) {
1365
+ this.hide();
1366
+ this.element.trigger('apply.daterangepicker', this);
1367
+ },
1368
+ clickApply_custom: function(e) {
1369
+ this.container.find('.ranges li:last').mouseenter();
1370
+ this.element.trigger('apply.daterangepicker', this);
1371
+ },
1372
+
1373
+ clickCancel: function(e) {
1374
+ this.startDate = this.oldStartDate;
1375
+ this.endDate = this.oldEndDate;
1376
+ this.hide();
1377
+ this.element.trigger('cancel.daterangepicker', this);
1378
+ },
1379
+
1380
+ monthOrYearChanged: function(e) {
1381
+ var isLeft = $(e.target).closest('.calendar').hasClass('left'),
1382
+ leftOrRight = isLeft ? 'left' : 'right',
1383
+ cal = this.container.find('.calendar.'+leftOrRight);
1384
+
1385
+ // Month must be Number for new moment versions
1386
+ var month = parseInt(cal.find('.monthselect').val(), 10);
1387
+ var year = cal.find('.yearselect').val();
1388
+
1389
+ if (!isLeft) {
1390
+ if (year < this.startDate.year() || (year == this.startDate.year() && month < this.startDate.month())) {
1391
+ month = this.startDate.month();
1392
+ year = this.startDate.year();
1393
+ }
1394
+ }
1395
+
1396
+ if (this.minDate) {
1397
+ if (year < this.minDate.year() || (year == this.minDate.year() && month < this.minDate.month())) {
1398
+ month = this.minDate.month();
1399
+ year = this.minDate.year();
1400
+ }
1401
+ }
1402
+
1403
+ if (this.maxDate) {
1404
+ if (year > this.maxDate.year() || (year == this.maxDate.year() && month > this.maxDate.month())) {
1405
+ month = this.maxDate.month();
1406
+ year = this.maxDate.year();
1407
+ }
1408
+ }
1409
+
1410
+ if (isLeft) {
1411
+ this.leftCalendar.month.month(month).year(year);
1412
+ if (this.linkedCalendars)
1413
+ this.rightCalendar.month = this.leftCalendar.month.clone().add(1, 'month');
1414
+ } else {
1415
+ this.rightCalendar.month.month(month).year(year);
1416
+ if (this.linkedCalendars)
1417
+ this.leftCalendar.month = this.rightCalendar.month.clone().subtract(1, 'month');
1418
+ }
1419
+ this.updateCalendars();
1420
+ },
1421
+
1422
+ timeChanged: function(e) {
1423
+
1424
+ var cal = $(e.target).closest('.calendar'),
1425
+ isLeft = cal.hasClass('left');
1426
+
1427
+ var hour = parseInt(cal.find('.hourselect').val(), 10);
1428
+ var minute = parseInt(cal.find('.minuteselect').val(), 10);
1429
+ var second = this.timePickerSeconds ? parseInt(cal.find('.secondselect').val(), 10) : 0;
1430
+
1431
+ if (!this.timePicker24Hour) {
1432
+ var ampm = cal.find('.ampmselect').val();
1433
+ if (ampm === 'PM' && hour < 12)
1434
+ hour += 12;
1435
+ if (ampm === 'AM' && hour === 12)
1436
+ hour = 0;
1437
+ }
1438
+
1439
+ if (isLeft) {
1440
+ var start = this.startDate.clone();
1441
+ start.hour(hour);
1442
+ start.minute(minute);
1443
+ start.second(second);
1444
+ this.setStartDate(start);
1445
+ if (this.singleDatePicker) {
1446
+ this.endDate = this.startDate.clone();
1447
+ } else if (this.endDate && this.endDate.format('YYYY-MM-DD') == start.format('YYYY-MM-DD') && this.endDate.isBefore(start)) {
1448
+ this.setEndDate(start.clone());
1449
+ }
1450
+ } else if (this.endDate) {
1451
+ var end = this.endDate.clone();
1452
+ end.hour(hour);
1453
+ end.minute(minute);
1454
+ end.second(second);
1455
+ this.setEndDate(end);
1456
+ }
1457
+
1458
+ //update the calendars so all clickable dates reflect the new time component
1459
+ this.updateCalendars();
1460
+
1461
+ //update the form inputs above the calendars with the new time
1462
+ this.updateFormInputs();
1463
+
1464
+ //re-render the time pickers because changing one selection can affect what's enabled in another
1465
+ this.renderTimePicker('left');
1466
+ this.renderTimePicker('right');
1467
+
1468
+ },
1469
+
1470
+ formInputsChanged: function(e) {
1471
+ var isRight = $(e.target).closest('.calendar').hasClass('right');
1472
+ var start = moment(this.container.find('input[name="daterangepicker_start"]').val(), this.locale.format);
1473
+ var end = moment(this.container.find('input[name="daterangepicker_end"]').val(), this.locale.format);
1474
+
1475
+ if (start.isValid() && end.isValid()) {
1476
+
1477
+ if (isRight && end.isBefore(start))
1478
+ start = end.clone();
1479
+
1480
+ this.setStartDate(start);
1481
+ this.setEndDate(end);
1482
+
1483
+ if (isRight) {
1484
+ this.container.find('input[name="daterangepicker_start"]').val(this.startDate.format(this.locale.format));
1485
+ } else {
1486
+ this.container.find('input[name="daterangepicker_end"]').val(this.endDate.format(this.locale.format));
1487
+ }
1488
+
1489
+ }
1490
+
1491
+ this.updateCalendars();
1492
+ if (this.timePicker) {
1493
+ this.renderTimePicker('left');
1494
+ this.renderTimePicker('right');
1495
+ }
1496
+ },
1497
+
1498
+ elementChanged: function() {
1499
+ if (!this.element.is('input')) return;
1500
+ if (!this.element.val().length) return;
1501
+ if (this.element.val().length < this.locale.format.length) return;
1502
+
1503
+ var dateString = this.element.val().split(this.locale.separator),
1504
+ start = null,
1505
+ end = null;
1506
+
1507
+ if (dateString.length === 2) {
1508
+ start = moment(dateString[0], this.locale.format);
1509
+ end = moment(dateString[1], this.locale.format);
1510
+ }
1511
+
1512
+ if (this.singleDatePicker || start === null || end === null) {
1513
+ start = moment(this.element.val(), this.locale.format);
1514
+ end = start;
1515
+ }
1516
+
1517
+ if (!start.isValid() || !end.isValid()) return;
1518
+
1519
+ this.setStartDate(start);
1520
+ this.setEndDate(end);
1521
+ this.updateView();
1522
+ },
1523
+
1524
+ keydown: function(e) {
1525
+ //hide on tab or enter
1526
+ if ((e.keyCode === 9) || (e.keyCode === 13)) {
1527
+ this.hide();
1528
+ }
1529
+ },
1530
+
1531
+ updateElement: function() {
1532
+ if (this.element.is('input') && !this.singleDatePicker && this.autoUpdateInput) {
1533
+ this.element.val(this.startDate.format(this.locale.format) + this.locale.separator + this.endDate.format(this.locale.format));
1534
+ this.element.trigger('change');
1535
+ } else if (this.element.is('input') && this.autoUpdateInput) {
1536
+ this.element.val(this.startDate.format(this.locale.format));
1537
+ this.element.trigger('change');
1538
+ }
1539
+ },
1540
+
1541
+ remove: function() {
1542
+ this.container.remove();
1543
+ this.element.off('.daterangepicker');
1544
+ this.element.removeData();
1545
+ }
1546
+
1547
+ };
1548
+
1549
+ $.fn.daterangepicker = function(options, callback) {
1550
+ this.each(function() {
1551
+ var el = $(this);
1552
+ if (el.data('daterangepicker'))
1553
+ el.data('daterangepicker').remove();
1554
+ el.data('daterangepicker', new DateRangePicker(el, options, callback));
1555
+ });
1556
+ return this;
1557
+ };
1558
+
1559
+ return DateRangePicker;
1560
+
1561
  }));
inc/js/gawd_admin.js CHANGED
@@ -2046,7 +2046,7 @@ function gawd_pie_chart_post_page(uri, divID) {
2046
  var dimension = 'date';
2047
  var timezone = -(new Date().getTimezoneOffset() / 60);
2048
  if (divID == 'gawd_post_page_popup') {
2049
- var chart_div = '<div id="opacity_div"></div><div id="loading_div" style="display:none; text-align: center; position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: 9999;"><img src="' + gawd_admin.gawd_plugin_url + '/assets/ajax_loader.gif" style="margin-top: 200px; width:50px;"></div><div class="page_chart_div"><div class="close_button_cont"><a href="#" class="gawd_btn">X</a>';
2050
  chart_div += '<select name="gawd_post_page_popup_date" id="gawd_post_page_popup_date">';
2051
  chart_div += '<option value="'+date_7+'">Last 7 Days</option><option value="'+date_30+'">Last 30 Days</option>';
2052
  chart_div += '<option value="'+date_last_month+'">Last month</option><option value="'+date_last_week+'">Last week</option>';
@@ -2276,7 +2276,7 @@ function post_page_stats(uri, divID) {
2276
  var end_date = start_end_date[1];
2277
  var timezone = -(new Date().getTimezoneOffset() / 60);
2278
  if (divID == 'gawd_post_page_popup') {
2279
- var chart_div = '<div id="opacity_div"></div><div id="loading_div" style="display:none; text-align: center; position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: 9999;"><img src="' + gawd_admin.gawd_plugin_url + '/assets/ajax_loader.gif" style="margin-top: 200px; width:50px;"></div><div class="page_chart_div"><div class="close_button_cont"><a href="#" class="gawd_btn">X</a>';
2280
  chart_div += '<select name="gawd_post_page_popup_date" id="gawd_post_page_popup_date">';
2281
  chart_div += '<option value="'+date_7+'">Last 7 Days</option><option value="'+date_30+'">Last 30 Days</option>';
2282
  chart_div += '<option value="'+date_last_month+'">Last month</option><option value="'+date_last_week+'">Last week</option>';
2046
  var dimension = 'date';
2047
  var timezone = -(new Date().getTimezoneOffset() / 60);
2048
  if (divID == 'gawd_post_page_popup') {
2049
+ var chart_div = '<div id="opacity_div"></div><div id="loading_div" style="display:none; text-align: center; position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: 9999;"><img src="' + gawd_admin.gawd_plugin_url + '/assets/ajax_loader.gif" style="margin-top: 200px; width:50px;"></div><div class="page_chart_div"><div class="close_button_cont"><button class="gawd_btn">X</button>';
2050
  chart_div += '<select name="gawd_post_page_popup_date" id="gawd_post_page_popup_date">';
2051
  chart_div += '<option value="'+date_7+'">Last 7 Days</option><option value="'+date_30+'">Last 30 Days</option>';
2052
  chart_div += '<option value="'+date_last_month+'">Last month</option><option value="'+date_last_week+'">Last week</option>';
2276
  var end_date = start_end_date[1];
2277
  var timezone = -(new Date().getTimezoneOffset() / 60);
2278
  if (divID == 'gawd_post_page_popup') {
2279
+ var chart_div = '<div id="opacity_div"></div><div id="loading_div" style="display:none; text-align: center; position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: 9999;"><img src="' + gawd_admin.gawd_plugin_url + '/assets/ajax_loader.gif" style="margin-top: 200px; width:50px;"></div><div class="page_chart_div"><div class="close_button_cont"><button class="gawd_btn">X</button>';
2280
  chart_div += '<select name="gawd_post_page_popup_date" id="gawd_post_page_popup_date">';
2281
  chart_div += '<option value="'+date_7+'">Last 7 Days</option><option value="'+date_30+'">Last 30 Days</option>';
2282
  chart_div += '<option value="'+date_last_month+'">Last month</option><option value="'+date_last_week+'">Last week</option>';
inc/js/gawd_front.js CHANGED
@@ -1,276 +1,276 @@
1
- jQuery(document).ready(function(){
2
- jQuery('#wp-admin-bar-gawd a').on('click', function(){
3
- var uri = '#' + jQuery('#wp-admin-bar-gawd a span').attr('data-url');
4
- var uri = jQuery('header h1').text();
5
- gawd_chart_type_post_page_front(uri, 'gawd_post_page_popup');
6
- })
7
- })
8
- function gawd_chart_type_post_page_front(uri,divID){
9
- if(jQuery("#gawd_chart_type_post_page").val() == 'pie'){
10
- gawd_pie_chart_post_page_front(uri,divID);
11
- }
12
- else{
13
- post_page_stats_front(uri,divID);
14
- }
15
- }
16
- function gawd_pie_chart_post_page_front(uri,divID){
17
- //jQuery("#chart").empty();
18
- //jQuery("#metric_compare").hide();
19
- //jQuery(".vs_image").hide();
20
- jQuery(".opacity_div_compact").show();
21
- jQuery(".loading_div_compact").show();
22
- if(typeof divID == 'undefined'){
23
- divID = 'gawd_post_page_popup';
24
- }
25
- var chartType = 'pie';
26
- var fillAlphas = 0;
27
-
28
- var metric = typeof jQuery("#gawd_metric_post_page").val() != 'undefined' ? jQuery("#gawd_metric_post_page").val() : (typeof jQuery("#gawd_metric_post_page_popup").val() != 'undefined' ? jQuery("#gawd_metric_post_page_popup").val() : 'sessions');
29
- var date_30 = gawd_front.date_30;
30
- var date_7 = gawd_front.date_7;
31
- var date_yesterday = gawd_front.date_yesterday;
32
- var date_today = gawd_front.date_today;
33
- var date_this_month = gawd_front.date_this_month;
34
- var date_last_month = gawd_front.date_last_month;
35
- var date_last_week = gawd_front.date_last_week;
36
-
37
- start_date = typeof jQuery("#gawd_post_page_date").val() != 'undefined' ? jQuery("#gawd_post_page_date").val() : (typeof jQuery("#gawd_post_page_popup_date").val() != 'undefined' ? jQuery("#gawd_post_page_popup_date").val() : date_30);
38
- var dimension = 'date';
39
- var timezone = -(new Date().getTimezoneOffset()/60);
40
- if(divID == 'gawd_post_page_popup'){
41
- var chart_div = '<div id="opacity_div"></div><div id="loading_div" style="display:none; text-align: center; position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: 9999;"><img src="'+gawd_front.gawd_plugin_url+'/assets/ajax_loader.gif" style="margin-top: 200px; width:50px;"></div><div class="page_chart_div"><div style="width:100%; height:100%; position:relative;" class="close_button_cont"><a href="#" class="gawd_btn" >X</a>';
42
- chart_div += '<select name="gawd_post_page_popup_date" id="gawd_post_page_popup_date" class="gawd_draw_analytics_front">';
43
- chart_div += '<option value="'+date_30+'">Last 30 Days</option><option value="'+date_7+'">Last 7 Days</option>';
44
- chart_div += '<option value="'+date_last_month+'">Last month</option><option value="'+date_last_week+'">Last week</option>';
45
- chart_div += '<option value="'+date_this_month+'">This month</option><option value="'+date_yesterday+'">Yesterday</option>';
46
- chart_div += '<option value="'+date_today+'">Today</option>';
47
- chart_div += '</select>';
48
- chart_div += '<select name="gawd_metric_post_page_popup" id="gawd_metric_post_page_popup" class="gawd_draw_analytics_front">';
49
- chart_div += '<option value="sessions" >Sessions</option><option value="users" >Users</option><option value="bounceRate" >Bounce Rate</option><option value="pageviews" >Pageviews</option><option value="percentNewSessions">% New Sessions</option><option value="avgSessionDuration">Avg Session Duration</option>';
50
- chart_div += '</select>';
51
- chart_div += '<select name="gawd_chart_type_post_page" id="gawd_chart_type_post_page" class="gawd_draw_analytics_front">';
52
- chart_div += '<option value="line">Line Chart</option><option value="pie">Pie Cart</option><option value="column">Column Chart</option>';
53
- chart_div += '</select>';
54
- chart_div += '<div id="gawd_post_page_popup"></div></div>';
55
- jQuery(".page_chart_div").remove();
56
- jQuery('#opacity_div').remove();
57
- jQuery( "body" ).append(chart_div);
58
- jQuery("#gawd_metric_post_page_popup").val(metric);
59
- jQuery("#gawd_chart_type_post_page").val(chartType);
60
- jQuery("#gawd_post_page_popup_date").val(start_date);
61
- jQuery( "#loading_div" ).show();
62
- jQuery( "#opacity_div" ).show();
63
- jQuery('#gawd_post_page_popup').height('400');
64
- jQuery('#gawd_metric_post_page_popup, #gawd_post_page_popup_date, #gawd_chart_type_post_page').on('change',function(){
65
- gawd_chart_type_post_page_front(uri,'gawd_post_page_popup');
66
- })
67
- }
68
- var dates = start_date.split('/-/');
69
-
70
- jQuery("#gawd_post_page_meta").empty();
71
- jQuery('#gawd_post_page_meta').height('300');
72
- jQuery.post(gawd_front.ajaxurl, {
73
- action: 'show_page_post_data',
74
- metric: metric,
75
- start_date: dates[0],
76
- end_date: dates[1],
77
- dimension: dimension,
78
- timezone: timezone,
79
- chart: 'pie',
80
- security: gawd_front.ajaxnonce,
81
- filter: uri,
82
- }).done(function (data) {
83
- jQuery(".opacity_div_compact").hide();
84
- jQuery(".loading_div_compact").hide();
85
- if(divID == 'gawd_post_page_popup'){
86
- jQuery( "#loading_div" ).remove();
87
- jQuery( ".gawd_btn" ).show();
88
- jQuery('#opacity_div, .gawd_btn').on('click', function(){
89
- jQuery('#opacity_div').remove();
90
- jQuery( ".gawd_btn" ).remove();
91
- jQuery( ".page_chart_div" ).remove();
92
- jQuery( "#loading_div" ).remove();
93
- })
94
- }
95
- var result = JSON.parse(data);
96
- result = result.chart_data
97
- var diff = ((Date.parse(dates[1]).getTime() - Date.parse(dates[0]).getTime()) / 3600 / 24 / 1000)+1;
98
- if(diff > 8){
99
- dimension = 'Week';
100
- metric = metric.replace(/([A-Z])/g, " $1").trim();
101
- metric = metric.charAt(0).toUpperCase() + metric.slice(1);
102
- metric = metric.replace(/ +/g, ' ');
103
- }
104
- var chart = AmCharts.makeChart( divID, {
105
- "type": "pie",
106
- "theme": "light",
107
- 'sequencedAnimation': false,
108
- "dataProvider": result,
109
- "valueField": metric,
110
- "titleField": dimension,
111
- "depth3D": 15,
112
- "angle": 30,
113
- "minRadius": 70,
114
- "startDuration": 0,
115
- "percentPrecision": 1,
116
- "precision": 0,
117
- "balloon":{
118
- "fixedPosition":true
119
- },
120
- 'groupPercent': 1,
121
- 'marginTop': 0,
122
- "export": {
123
- "enabled": true
124
- },
125
- "legend": {
126
- "enabled": true,
127
- "align": "center",
128
- "markerType": "circle",
129
- },
130
- } );
131
- jQuery("#"+divID).find('a').remove();
132
- //jQuery("#gbox_griddiv").remove();
133
- //var grid = '<table id="griddiv"></table><div id="pager"></div>';
134
- //jQuery('.gawd_chart_conteiner').append(grid);
135
- //gawd_draw_table(result,metric,metric_compare,dimension);
136
- })
137
- }
138
- function post_page_stats_front(uri,divID){
139
- if(typeof divID == 'undefined'){
140
- divID = 'gawd_post_page_popup';
141
- }
142
- var chartType = 'line';
143
- var fillAlphas = 0;
144
- var checked_line = "";
145
- var checked_column = "";
146
- if(jQuery("#gawd_chart_type_post_page").val() == 'line'){
147
- chartType = 'line';
148
- var checked = 'selected="selected"';
149
- fillAlphas = 0;
150
- }
151
- else if(jQuery("#gawd_chart_type_post_page").val() == 'column'){
152
- chartType = 'column';
153
- checked_column = 'selected="selected"';
154
- fillAlphas = 1;
155
- }
156
- var metric = typeof jQuery("#gawd_metric_post_page_popup").val() != 'undefined' ? jQuery("#gawd_metric_post_page_popup").val() : 'sessions';
157
- var date_30 = gawd_front.date_30;
158
- var date_7 = gawd_front.date_7;
159
- var date_yesterday = gawd_front.date_yesterday;
160
- var date_today = gawd_front.date_today;
161
- var date_this_month = gawd_front.date_this_month;
162
- var date_last_month = gawd_front.date_last_month;
163
- var date_last_week = gawd_front.date_last_week;
164
-
165
- start_date = typeof jQuery("#gawd_post_page_date").val() != 'undefined' ? jQuery("#gawd_post_page_date").val() : (typeof jQuery("#gawd_post_page_popup_date").val() != 'undefined' ? jQuery("#gawd_post_page_popup_date").val() : date_30);
166
- var dimension = 'date';
167
- var timezone = -(new Date().getTimezoneOffset()/60);
168
- var chart_div = '<div id="opacity_div"></div><div id="loading_div" style="display:none; text-align: center; position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: 9999;"><img src="'+gawd_front.gawd_plugin_url+'/assets/ajax_loader.gif" style="margin-top: 200px; width:50px;"></div><div class="page_chart_div"><div style="width:100%; height:100%; position:relative;" class="close_button_cont"><a href="#" class="gawd_btn" >X</a>';
169
- chart_div += '<select name="gawd_post_page_popup_date" id="gawd_post_page_popup_date" class="gawd_draw_analytics_front">';
170
- chart_div += '<option value="'+date_30+'">Last 30 Days</option><option value="'+date_7+'">Last 7 Days</option>';
171
- chart_div += '<option value="'+date_last_week+'">Last week</option><option value="'+date_last_month+'">Last month</option>';
172
- chart_div += '<option value="'+date_this_month+'">This month</option><option value="'+date_yesterday+'">Yesterday</option>';
173
- chart_div += '<option value="'+date_today+'">Today</option>';
174
- chart_div += '</select>';
175
- chart_div += '<select name="gawd_metric_post_page_popup" id="gawd_metric_post_page_popup" class="gawd_draw_analytics_front">';
176
- chart_div += '<option value="sessions" >Sessions</option><option value="users" >Users</option><option value="bounceRate" >Bounce Rate</option><option value="pageviews" >Pageviews</option><option value="percentNewSessions">% New Sessions</option><option value="avgSessionDuration">Avg Session Duration</option><option value="pageviewsPerSession" >Pages/Session</option>';
177
- chart_div += '</select>';
178
- chart_div += '<select name="gawd_chart_type_post_page" id="gawd_chart_type_post_page" class="gawd_draw_analytics_front">';
179
- chart_div += '<option '+checked_line+' value="line">Line Chart</option><option value="pie">Pie Cart</option><option '+checked_column+' value="column">Column Chart</option>';
180
- chart_div += '</select>';
181
- chart_div += '<div id="gawd_post_page_popup"></div></div></div>';
182
- jQuery(".page_chart_div").remove();
183
- jQuery('#opacity_div').remove();
184
-
185
- jQuery( "body" ).append(chart_div);
186
- jQuery("#gawd_metric_post_page_popup").val(metric)
187
- jQuery("#gawd_post_page_popup_date").val(start_date)
188
- jQuery( "#loading_div" ).show();
189
- jQuery( "#opacity_div" ).show();
190
- jQuery('#gawd_post_page_popup').height('400');
191
- jQuery('#gawd_metric_post_page_popup, #gawd_post_page_popup_date, #gawd_chart_type_post_page').on('change',function(){
192
- gawd_chart_type_post_page_front(uri,'gawd_post_page_popup');
193
- })
194
- jQuery("#gawd_post_page_meta").empty();
195
- jQuery('#gawd_post_page_meta').height('300');
196
- var dates = start_date.split('/-/');
197
- jQuery.post(gawd_front.ajaxurl, {
198
- action: 'show_page_post_data',
199
- metric: metric,
200
- start_date: dates[0],
201
- end_date: dates[1],
202
- dimension: dimension,
203
- timezone: timezone,
204
- chart: 'line',
205
- security: gawd_front.ajaxnonce,
206
- filter: uri,
207
-
208
- }).done(function (data) {
209
- var data = JSON.parse(data);
210
- data = data.chart_data;
211
- if(divID == 'gawd_post_page_popup'){
212
- jQuery( "#loading_div" ).remove();
213
- jQuery( ".gawd_btn" ).show();
214
- jQuery('#opacity_div, .gawd_btn').on('click', function(){
215
- jQuery('#opacity_div').remove();
216
- jQuery( ".gawd_btn" ).remove();
217
- jQuery( ".page_chart_div" ).remove();
218
- jQuery( "#loading_div" ).remove();
219
- })
220
-
221
- }
222
-
223
- var chart = AmCharts.makeChart(divID, {
224
- "dataProvider": data,
225
- "type": "serial",
226
- "theme": "light",
227
- "percentPrecision": 1,
228
- "precision": 0,
229
- "export": {
230
- "enabled": true
231
- },
232
- "dataDateFormat": "YYYY-MM-DD",
233
- "valueAxes": [{
234
- "id": "g1",
235
- "axisAlpha": 0.4,
236
- "position": "left",
237
- "title": metric,
238
- "ignoreAxisWidth":false
239
-
240
- }],
241
- "chartCursor": {
242
- "pan": true,
243
- "valueLineEnabled": true,
244
- "valueLineBalloonEnabled": true,
245
- "cursorAlpha": 1,
246
- "cursorColor": "#258cbb",
247
- "limitToGraph": "g1",
248
- "valueLineAlpha": 0.2
249
- },
250
- "graphs": [{
251
- "type": chartType,
252
- "valueAxis": "g1",
253
- "fillAlphas": fillAlphas,
254
- "bullet": "round",
255
- "bulletBorderAlpha": 1,
256
- "bulletColor": "#FFFFFF",
257
- "bulletSize": 5,
258
- //"hideBulletsCount": 50,
259
- "lineThickness": 2,
260
- "title": metric,
261
- "useLineColorForBulletBorder": true,
262
- "valueField": metric,
263
- }],
264
- "categoryField": dimension,
265
- "categoryAxis": {
266
- "parseDates": true,
267
- "equalSpacing": true,
268
- "dashLength": 2,
269
- "minorGridEnabled": true,
270
- "boldLabels": true,
271
- "labelFrequency": 1,
272
- }
273
- } )
274
- jQuery("#"+divID).find('a').remove();
275
- })
276
- }
1
+ jQuery(document).ready(function(){
2
+ jQuery('#wp-admin-bar-gawd a').on('click', function(){
3
+ var uri = '#' + jQuery('#wp-admin-bar-gawd a span').attr('data-url');
4
+ var uri = jQuery('header h1').text();
5
+ gawd_chart_type_post_page_front(uri, 'gawd_post_page_popup');
6
+ })
7
+ })
8
+ function gawd_chart_type_post_page_front(uri,divID){
9
+ if(jQuery("#gawd_chart_type_post_page").val() == 'pie'){
10
+ gawd_pie_chart_post_page_front(uri,divID);
11
+ }
12
+ else{
13
+ post_page_stats_front(uri,divID);
14
+ }
15
+ }
16
+ function gawd_pie_chart_post_page_front(uri,divID){
17
+ //jQuery("#chart").empty();
18
+ //jQuery("#metric_compare").hide();
19
+ //jQuery(".vs_image").hide();
20
+ jQuery(".opacity_div_compact").show();
21
+ jQuery(".loading_div_compact").show();
22
+ if(typeof divID == 'undefined'){
23
+ divID = 'gawd_post_page_popup';
24
+ }
25
+ var chartType = 'pie';
26
+ var fillAlphas = 0;
27
+
28
+ var metric = typeof jQuery("#gawd_metric_post_page").val() != 'undefined' ? jQuery("#gawd_metric_post_page").val() : (typeof jQuery("#gawd_metric_post_page_popup").val() != 'undefined' ? jQuery("#gawd_metric_post_page_popup").val() : 'sessions');
29
+ var date_30 = gawd_front.date_30;
30
+ var date_7 = gawd_front.date_7;
31
+ var date_yesterday = gawd_front.date_yesterday;
32
+ var date_today = gawd_front.date_today;
33
+ var date_this_month = gawd_front.date_this_month;
34
+ var date_last_month = gawd_front.date_last_month;
35
+ var date_last_week = gawd_front.date_last_week;
36
+
37
+ start_date = typeof jQuery("#gawd_post_page_date").val() != 'undefined' ? jQuery("#gawd_post_page_date").val() : (typeof jQuery("#gawd_post_page_popup_date").val() != 'undefined' ? jQuery("#gawd_post_page_popup_date").val() : date_30);
38
+ var dimension = 'date';
39
+ var timezone = -(new Date().getTimezoneOffset()/60);
40
+ if(divID == 'gawd_post_page_popup'){
41
+ var chart_div = '<div id="opacity_div"></div><div id="loading_div" style="display:none; text-align: center; position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: 9999;"><img src="'+gawd_front.gawd_plugin_url+'/assets/ajax_loader.gif" style="margin-top: 200px; width:50px;"></div><div class="page_chart_div"><div style="width:100%; height:100%; position:relative;" class="close_button_cont"><button class="gawd_btn" >X</button>';
42
+ chart_div += '<select name="gawd_post_page_popup_date" id="gawd_post_page_popup_date" class="gawd_draw_analytics_front">';
43
+ chart_div += '<option value="'+date_30+'">Last 30 Days</option><option value="'+date_7+'">Last 7 Days</option>';
44
+ chart_div += '<option value="'+date_last_month+'">Last month</option><option value="'+date_last_week+'">Last week</option>';
45
+ chart_div += '<option value="'+date_this_month+'">This month</option><option value="'+date_yesterday+'">Yesterday</option>';
46
+ chart_div += '<option value="'+date_today+'">Today</option>';
47
+ chart_div += '</select>';
48
+ chart_div += '<select name="gawd_metric_post_page_popup" id="gawd_metric_post_page_popup" class="gawd_draw_analytics_front">';
49
+ chart_div += '<option value="sessions" >Sessions</option><option value="users" >Users</option><option value="bounceRate" >Bounce Rate</option><option value="pageviews" >Pageviews</option><option value="percentNewSessions">% New Sessions</option><option value="avgSessionDuration">Avg Session Duration</option>';
50
+ chart_div += '</select>';
51
+ chart_div += '<select name="gawd_chart_type_post_page" id="gawd_chart_type_post_page" class="gawd_draw_analytics_front">';
52
+ chart_div += '<option value="line">Line Chart</option><option value="pie">Pie Cart</option><option value="column">Column Chart</option>';
53
+ chart_div += '</select>';
54
+ chart_div += '<div id="gawd_post_page_popup"></div></div>';
55
+ jQuery(".page_chart_div").remove();
56
+ jQuery('#opacity_div').remove();
57
+ jQuery( "body" ).append(chart_div);
58
+ jQuery("#gawd_metric_post_page_popup").val(metric);
59
+ jQuery("#gawd_chart_type_post_page").val(chartType);
60
+ jQuery("#gawd_post_page_popup_date").val(start_date);
61
+ jQuery( "#loading_div" ).show();
62
+ jQuery( "#opacity_div" ).show();
63
+ jQuery('#gawd_post_page_popup').height('400');
64
+ jQuery('#gawd_metric_post_page_popup, #gawd_post_page_popup_date, #gawd_chart_type_post_page').on('change',function(){
65
+ gawd_chart_type_post_page_front(uri,'gawd_post_page_popup');
66
+ })
67
+ }
68
+ var dates = start_date.split('/-/');
69
+
70
+ jQuery("#gawd_post_page_meta").empty();
71
+ jQuery('#gawd_post_page_meta').height('300');
72
+ jQuery.post(gawd_front.ajaxurl, {
73
+ action: 'show_page_post_data',
74
+ metric: metric,
75
+ start_date: dates[0],
76
+ end_date: dates[1],
77
+ dimension: dimension,
78
+ timezone: timezone,
79
+ chart: 'pie',
80
+ security: gawd_front.ajaxnonce,
81
+ filter: uri,
82
+ }).done(function (data) {
83
+ jQuery(".opacity_div_compact").hide();
84
+ jQuery(".loading_div_compact").hide();
85
+ if(divID == 'gawd_post_page_popup'){
86
+ jQuery( "#loading_div" ).remove();
87
+ jQuery( ".gawd_btn" ).show();
88
+ jQuery('#opacity_div, .gawd_btn').on('click', function(){
89
+ jQuery('#opacity_div').remove();
90
+ jQuery( ".gawd_btn" ).remove();
91
+ jQuery( ".page_chart_div" ).remove();
92
+ jQuery( "#loading_div" ).remove();
93
+ })
94
+ }
95
+ var result = JSON.parse(data);
96
+ result = result.chart_data
97
+ var diff = ((Date.parse(dates[1]).getTime() - Date.parse(dates[0]).getTime()) / 3600 / 24 / 1000)+1;
98
+ if(diff > 8){
99
+ dimension = 'Week';
100
+ metric = metric.replace(/([A-Z])/g, " $1").trim();
101
+ metric = metric.charAt(0).toUpperCase() + metric.slice(1);
102
+ metric = metric.replace(/ +/g, ' ');
103
+ }
104
+ var chart = AmCharts.makeChart( divID, {
105
+ "type": "pie",
106
+ "theme": "light",
107
+ 'sequencedAnimation': false,
108
+ "dataProvider": result,
109
+ "valueField": metric,
110
+ "titleField": dimension,
111
+ "depth3D": 15,
112
+ "angle": 30,
113
+ "minRadius": 70,
114
+ "startDuration": 0,
115
+ "percentPrecision": 1,
116
+ "precision": 0,
117
+ "balloon":{
118
+ "fixedPosition":true
119
+ },
120
+ 'groupPercent': 1,
121
+ 'marginTop': 0,
122
+ "export": {
123
+ "enabled": true
124
+ },
125
+ "legend": {
126
+ "enabled": true,
127
+ "align": "center",
128
+ "markerType": "circle",
129
+ },
130
+ } );
131
+ jQuery("#"+divID).find('a').remove();
132
+ //jQuery("#gbox_griddiv").remove();
133
+ //var grid = '<table id="griddiv"></table><div id="pager"></div>';
134
+ //jQuery('.gawd_chart_conteiner').append(grid);
135
+ //gawd_draw_table(result,metric,metric_compare,dimension);
136
+ })
137
+ }
138
+ function post_page_stats_front(uri,divID){
139
+ if(typeof divID == 'undefined'){
140
+ divID = 'gawd_post_page_popup';
141
+ }
142
+ var chartType = 'line';
143
+ var fillAlphas = 0;
144
+ var checked_line = "";
145
+ var checked_column = "";
146
+ if(jQuery("#gawd_chart_type_post_page").val() == 'line'){
147
+ chartType = 'line';
148
+ var checked = 'selected="selected"';
149
+ fillAlphas = 0;
150
+ }
151
+ else if(jQuery("#gawd_chart_type_post_page").val() == 'column'){
152
+ chartType = 'column';
153
+ checked_column = 'selected="selected"';
154
+ fillAlphas = 1;
155
+ }
156
+ var metric = typeof jQuery("#gawd_metric_post_page_popup").val() != 'undefined' ? jQuery("#gawd_metric_post_page_popup").val() : 'sessions';
157
+ var date_30 = gawd_front.date_30;
158
+ var date_7 = gawd_front.date_7;
159
+ var date_yesterday = gawd_front.date_yesterday;
160
+ var date_today = gawd_front.date_today;
161
+ var date_this_month = gawd_front.date_this_month;
162
+ var date_last_month = gawd_front.date_last_month;
163
+ var date_last_week = gawd_front.date_last_week;
164
+
165
+ start_date = typeof jQuery("#gawd_post_page_date").val() != 'undefined' ? jQuery("#gawd_post_page_date").val() : (typeof jQuery("#gawd_post_page_popup_date").val() != 'undefined' ? jQuery("#gawd_post_page_popup_date").val() : date_30);
166
+ var dimension = 'date';
167
+ var timezone = -(new Date().getTimezoneOffset()/60);
168
+ var chart_div = '<div id="opacity_div"></div><div id="loading_div" style="display:none; text-align: center; position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: 9999;"><img src="'+gawd_front.gawd_plugin_url+'/assets/ajax_loader.gif" style="margin-top: 200px; width:50px;"></div><div class="page_chart_div"><div style="width:100%; height:100%; position:relative;" class="close_button_cont"><button class="gawd_btn" >X</button>';
169
+ chart_div += '<select name="gawd_post_page_popup_date" id="gawd_post_page_popup_date" class="gawd_draw_analytics_front">';
170
+ chart_div += '<option value="'+date_30+'">Last 30 Days</option><option value="'+date_7+'">Last 7 Days</option>';
171
+ chart_div += '<option value="'+date_last_week+'">Last week</option><option value="'+date_last_month+'">Last month</option>';
172
+ chart_div += '<option value="'+date_this_month+'">This month</option><option value="'+date_yesterday+'">Yesterday</option>';
173
+ chart_div += '<option value="'+date_today+'">Today</option>';
174
+ chart_div += '</select>';
175
+ chart_div += '<select name="gawd_metric_post_page_popup" id="gawd_metric_post_page_popup" class="gawd_draw_analytics_front">';
176
+ chart_div += '<option value="sessions" >Sessions</option><option value="users" >Users</option><option value="bounceRate" >Bounce Rate</option><option value="pageviews" >Pageviews</option><option value="percentNewSessions">% New Sessions</option><option value="avgSessionDuration">Avg Session Duration</option><option value="pageviewsPerSession" >Pages/Session</option>';
177
+ chart_div += '</select>';
178
+ chart_div += '<select name="gawd_chart_type_post_page" id="gawd_chart_type_post_page" class="gawd_draw_analytics_front">';
179
+ chart_div += '<option '+checked_line+' value="line">Line Chart</option><option value="pie">Pie Cart</option><option '+checked_column+' value="column">Column Chart</option>';
180
+ chart_div += '</select>';
181
+ chart_div += '<div id="gawd_post_page_popup"></div></div></div>';
182
+ jQuery(".page_chart_div").remove();
183
+ jQuery('#opacity_div').remove();
184
+
185
+ jQuery( "body" ).append(chart_div);
186
+ jQuery("#gawd_metric_post_page_popup").val(metric)
187
+ jQuery("#gawd_post_page_popup_date").val(start_date)
188
+ jQuery( "#loading_div" ).show();
189
+ jQuery( "#opacity_div" ).show();
190
+ jQuery('#gawd_post_page_popup').height('400');
191
+ jQuery('#gawd_metric_post_page_popup, #gawd_post_page_popup_date, #gawd_chart_type_post_page').on('change',function(){
192
+ gawd_chart_type_post_page_front(uri,'gawd_post_page_popup');
193
+ })
194
+ jQuery("#gawd_post_page_meta").empty();
195
+ jQuery('#gawd_post_page_meta').height('300');
196
+ var dates = start_date.split('/-/');
197
+ jQuery.post(gawd_front.ajaxurl, {
198
+ action: 'show_page_post_data',
199
+ metric: metric,
200
+ start_date: dates[0],
201
+ end_date: dates[1],
202
+ dimension: dimension,
203
+ timezone: timezone,
204
+ chart: 'line',
205
+ security: gawd_front.ajaxnonce,
206
+ filter: uri,
207
+
208
+ }).done(function (data) {
209
+ var data = JSON.parse(data);
210
+ data = data.chart_data;
211
+ if(divID == 'gawd_post_page_popup'){
212
+ jQuery( "#loading_div" ).remove();
213
+ jQuery( ".gawd_btn" ).show();
214
+ jQuery('#opacity_div, .gawd_btn').on('click', function(){
215
+ jQuery('#opacity_div').remove();
216
+ jQuery( ".gawd_btn" ).remove();
217
+ jQuery( ".page_chart_div" ).remove();
218
+ jQuery( "#loading_div" ).remove();
219
+ })
220
+
221
+ }
222
+
223
+ var chart = AmCharts.makeChart(divID, {
224
+ "dataProvider": data,
225
+ "type": "serial",
226
+ "theme": "light",
227
+ "percentPrecision": 1,
228
+ "precision": 0,
229
+ "export": {
230
+ "enabled": true
231
+ },
232
+ "dataDateFormat": "YYYY-MM-DD",
233
+ "valueAxes": [{
234
+ "id": "g1",
235
+ "axisAlpha": 0.4,
236
+ "position": "left",
237
+ "title": metric,
238
+ "ignoreAxisWidth":false
239
+
240
+ }],
241
+ "chartCursor": {
242
+ "pan": true,
243
+ "valueLineEnabled": true,
244
+ "valueLineBalloonEnabled": true,
245
+ "cursorAlpha": 1,
246
+ "cursorColor": "#258cbb",
247
+ "limitToGraph": "g1",
248
+ "valueLineAlpha": 0.2
249
+ },
250
+ "graphs": [{
251
+ "type": chartType,
252
+ "valueAxis": "g1",
253
+ "fillAlphas": fillAlphas,
254
+ "bullet": "round",
255
+ "bulletBorderAlpha": 1,
256
+ "bulletColor": "#FFFFFF",
257
+ "bulletSize": 5,
258
+ //"hideBulletsCount": 50,
259
+ "lineThickness": 2,
260
+ "title": metric,
261
+ "useLineColorForBulletBorder": true,
262
+ "valueField": metric,
263
+ }],
264
+ "categoryField": dimension,
265
+ "categoryAxis": {
266
+ "parseDates": true,
267
+ "equalSpacing": true,
268
+ "dashLength": 2,
269
+ "minorGridEnabled": true,
270
+ "boldLabels": true,
271
+ "labelFrequency": 1,
272
+ }
273
+ } )
274
+ jQuery("#"+divID).find('a').remove();
275
+ })
276
+ }
include/gawd-notices-class.php ADDED
@@ -0,0 +1,232 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if (!defined('ABSPATH')) {
3
+ exit;
4
+ }
5
+
6
+ class GAWD_Notices {
7
+ protected $prefix = 'gawd';
8
+ protected $plugin_url = GAWD_URL;
9
+ protected $plugin_version = "gawd_version";
10
+ protected $plugin_name = 'WD Google Analytics';
11
+ protected $promo_link = '';
12
+
13
+ public $notice_spam = 0;
14
+ public $notice_spam_max = 1;
15
+
16
+ // Basic actions to run
17
+ public function __construct() {
18
+
19
+ // Runs the admin notice ignore function incase a dismiss button has been clicked
20
+ add_action('admin_init', array($this, 'admin_notice_ignore'));
21
+ // Runs the admin notice temp ignore function incase a temp dismiss link has been clicked
22
+ add_action('admin_init', array($this, 'admin_notice_temp_ignore'));
23
+ add_action('admin_notices', array($this, 'wd_admin_notices'));
24
+ }
25
+
26
+ // Checks to ensure notices aren't disabled and the user has the correct permissions.
27
+ public function wd_admin_notice() {
28
+ $settings = get_option($this->prefix . '_admin_notice');
29
+ if (!isset($settings['disable_admin_notices']) || (isset($settings['disable_admin_notices']) && $settings['disable_admin_notices'] == 0)) {
30
+ if (current_user_can('manage_options')) {
31
+ return true;
32
+ }
33
+ }
34
+ return false;
35
+ }
36
+
37
+ // Primary notice function that can be called from an outside function sending necessary variables
38
+ public function admin_notice($admin_notices) {
39
+
40
+ // Check options
41
+ if (!$this->wd_admin_notice()) {
42
+ return false;
43
+ }
44
+
45
+ foreach ($admin_notices as $slug => $admin_notice) {
46
+ // Call for spam protection
47
+ if ($this->anti_notice_spam()) {
48
+ return false;
49
+ }
50
+
51
+ // Check for proper page to display on
52
+ if (isset( $admin_notices[$slug]['pages']) && is_array( $admin_notices[$slug]['pages'])) {
53
+ if (!$this->admin_notice_pages($admin_notices[$slug]['pages'])) {
54
+ return false;
55
+ }
56
+ }
57
+
58
+ // Check for required fields
59
+ if (!$this->required_fields($admin_notices[$slug])) {
60
+
61
+ // Get the current date then set start date to either passed value or current date value and add interval
62
+ $current_date = current_time("n/j/Y");
63
+ $start = (isset($admin_notices[$slug]['start']) ? $admin_notices[$slug]['start'] : $current_date);
64
+ $start = date("n/j/Y", strtotime($start));
65
+ $date_array = explode('/', $start);
66
+ $interval = (isset($admin_notices[$slug]['int']) ? $admin_notices[$slug]['int'] : 0);
67
+
68
+ $date_array[1] += $interval;
69
+ $start = date("n/j/Y", mktime(0, 0, 0, $date_array[0], $date_array[1], $date_array[2]));
70
+
71
+ // This is the main notices storage option
72
+ $admin_notices_option = get_option($this->prefix . '_admin_notice', array());
73
+ // Check if the message is already stored and if so just grab the key otherwise store the message and its associated date information
74
+ if (!array_key_exists( $slug, $admin_notices_option)) {
75
+ $admin_notices_option[$slug]['start'] = $start;
76
+ $admin_notices_option[$slug]['int'] = $interval;
77
+ update_option($this->prefix . '_admin_notice', $admin_notices_option);
78
+ }
79
+
80
+ // Sanity check to ensure we have accurate information
81
+ // New date information will not overwrite old date information
82
+ $admin_display_check = (isset($admin_notices_option[$slug]['dismissed']) ? $admin_notices_option[$slug]['dismissed'] : 0);
83
+ $admin_display_start = (isset($admin_notices_option[$slug]['start']) ? $admin_notices_option[$slug]['start'] : $start);
84
+ $admin_display_interval = (isset($admin_notices_option[$slug]['int']) ? $admin_notices_option[$slug]['int'] : $interval);
85
+ $admin_display_msg = (isset($admin_notices[$slug]['msg']) ? $admin_notices[$slug]['msg'] : '');
86
+ $admin_display_title = (isset($admin_notices[$slug]['title']) ? $admin_notices[$slug]['title'] : '');
87
+ $admin_display_link = (isset($admin_notices[$slug]['link']) ? $admin_notices[$slug]['link'] : '');
88
+ $output_css = false;
89
+
90
+ // Ensure the notice hasn't been hidden and that the current date is after the start date
91
+ if ($admin_display_check == 0 && strtotime($admin_display_start) <= strtotime($current_date)) {
92
+
93
+ // Get remaining query string
94
+ $query_str = (isset($admin_notices[$slug]['later_link']) ? $admin_notices[$slug]['later_link'] : esc_url(add_query_arg($this->prefix . '_admin_notice_ignore', $slug)));
95
+ if (strpos($slug, 'promo') === FALSE) {
96
+ // Admin notice display output
97
+ echo '<div class="update-nag wd-admin-notice">
98
+ <div class="' . $this->prefix . '-notice-logo"></div>
99
+ <p class="wd-notice-title">' . $admin_display_title . '</p>
100
+ <p class="wd-notice-body">' . $admin_display_msg . '</p>
101
+ <ul class="wd-notice-body wd-blue">' . $admin_display_link . '</ul>
102
+ <a href="' . $query_str . '" class="dashicons dashicons-dismiss"></a>
103
+ </div>';
104
+ }
105
+ else {
106
+ echo '<div class="admin-notice-promo">';
107
+ echo $admin_display_msg;
108
+ echo '<ul class="notice-body-promo blue">
109
+ ' . $admin_display_link . '
110
+ </ul>';
111
+ echo '<a href="' . $query_str . '" class="dashicons dashicons-dismiss close-promo"></a>';
112
+ echo '</div>';
113
+ }
114
+ $this->notice_spam += 1;
115
+ $output_css = true;
116
+ }
117
+ if ($output_css) {
118
+ wp_enqueue_style('gawd-admin-notices', GAWD_URL . '/inc/css/notices.css', array(), GAWD_VERSION);
119
+ }
120
+ }
121
+ }
122
+ }
123
+
124
+ // Spam protection check
125
+ public function anti_notice_spam() {
126
+ if ($this->notice_spam >= $this->notice_spam_max) {
127
+ return true;
128
+ }
129
+ return false;
130
+ }
131
+
132
+ // Ignore function that gets ran at admin init to ensure any messages that were dismissed get marked
133
+ public function admin_notice_ignore() {
134
+ // If user clicks to ignore the notice, update the option to not show it again
135
+ if (isset($_GET[$this->prefix . '_admin_notice_ignore'])) {
136
+ $admin_notices_option = get_option($this->prefix . '_admin_notice', array());
137
+ $admin_notices_option[$_GET[$this->prefix . '_admin_notice_ignore']]['dismissed'] = 1;
138
+ update_option($this->prefix . '_admin_notice', $admin_notices_option);
139
+ $query_str = remove_query_arg($this->prefix . '_admin_notice_ignore');
140
+ wp_redirect($query_str);
141
+ exit;
142
+ }
143
+ }
144
+
145
+ // Temp Ignore function that gets ran at admin init to ensure any messages that were temp dismissed get their start date changed
146
+ public function admin_notice_temp_ignore() {
147
+ // If user clicks to temp ignore the notice, update the option to change the start date - default interval of 14 days
148
+ if (isset($_GET[$this->prefix . '_admin_notice_temp_ignore'])) {
149
+ $admin_notices_option = get_option($this->prefix . '_admin_notice', array());
150
+ $current_date = current_time("n/j/Y");
151
+ $date_array = explode('/', $current_date);
152
+ $interval = (isset($_GET['wd_int']) ? $_GET['wd_int'] : 14);
153
+ $date_array[1] += $interval;
154
+ $new_start = date("n/j/Y", mktime(0, 0, 0, $date_array[0], $date_array[1], $date_array[2]));
155
+
156
+ $admin_notices_option[$_GET[$this->prefix . '_admin_notice_temp_ignore']]['start'] = $new_start;
157
+ $admin_notices_option[$_GET[$this->prefix . '_admin_notice_temp_ignore']]['dismissed'] = 0;
158
+ update_option($this->prefix . '_admin_notice', $admin_notices_option);
159
+ $query_str = remove_query_arg(array($this->prefix . '_admin_notice_temp_ignore', 'wd_int'));
160
+ wp_redirect( $query_str );
161
+ exit;
162
+ }
163
+ }
164
+
165
+ public function admin_notice_pages($pages) {
166
+ foreach ($pages as $key => $page) {
167
+ if (is_array($page)) {
168
+ if (isset($_GET['page']) && $_GET['page'] == $page[0] && isset($_GET['tab']) && $_GET['tab'] == $page[1]) {
169
+ return true;
170
+ }
171
+ }
172
+ else {
173
+ if ($page == 'all') {
174
+ return true;
175
+ }
176
+ if (get_current_screen()->id === $page) {
177
+ return true;
178
+ }
179
+ if (isset($_GET['page']) && $_GET['page'] == $page) {
180
+ return true;
181
+ }
182
+ }
183
+ return false;
184
+ }
185
+ }
186
+
187
+ // Required fields check
188
+ public function required_fields( $fields ) {
189
+ if (!isset( $fields['msg']) || (isset($fields['msg']) && empty($fields['msg']))) {
190
+ return true;
191
+ }
192
+ if (!isset( $fields['title']) || (isset($fields['title']) && empty($fields['title']))) {
193
+ return true;
194
+ }
195
+ return false;
196
+ }
197
+
198
+ // Special parameters function that is to be used in any extension of this class
199
+ public function special_parameters($admin_notices) {
200
+ // Intentionally left blank
201
+ }
202
+
203
+ function wd_admin_notices( $notices ) {
204
+ $two_week_review_ignore = add_query_arg( array( 'gawd_admin_notice_ignore' => 'two_week_review' ) );
205
+ $two_week_review_temp = add_query_arg( array( 'gawd_admin_notice_temp_ignore' => 'two_week_review', 'int' => 14 ) );
206
+ $notices['two_week_review'] = array(
207
+ 'title' => __( 'Leave A Review?', 'gawd' ),
208
+ 'msg' => __( 'We hope you\'ve enjoyed using WD Google Analytics! Would you consider leaving us a review on WordPress.org?', 'gawd' ),
209
+ 'link' => '<li><span class="dashicons dashicons-external"></span><a href="https://wordpress.org/support/view/plugin-reviews/wd-google-analytics?filter=5" target="_blank">' . __( 'Sure! I\'d love to!', 'gawd' ) . '</a></li>
210
+ <li> <span class="dashicons dashicons-smiley"></span><a href="' . $two_week_review_ignore . '"> ' . __( 'I\'ve already left a review', 'gawd' ) . '</a></li>
211
+ <li><span class="dashicons dashicons-calendar-alt"></span><a href="' . $two_week_review_temp . '">' . __( 'Maybe Later' ,'gawd' ) . '</a></li>
212
+ <li><span class="dashicons dashicons-dismiss"></span><a href="' . $two_week_review_ignore . '">' . __( 'Never show again' ,'gawd' ) . '</a></li>',
213
+
214
+ 'later_link'=>$two_week_review_temp,
215
+ 'int' => 14
216
+ );
217
+
218
+ $one_week_support = add_query_arg( array( 'gawd_admin_notice_ignore' => 'one_week_support' ) );
219
+ $notices['one_week_support'] = array(
220
+ 'title' => __( 'Hey! How\'s It Going?', 'gawd' ),
221
+ 'msg' => __( 'Thank you for using WD Google Analytics! We hope that you\'ve found everything you need, but if you have any questions:', 'gawd' ),
222
+ 'link' => '<li><span class="dashicons dashicons-media-text"></span><a target="_blank" href="https://web-dorado.com/wordpress-google-analytics/installation.html">' . __( 'Check out User Guide', 'gawd' ) . '</a></li>
223
+ <li><span class="dashicons dashicons-sos"></span><a target="_blank" href="https://web-dorado.com/forum/google-analytics-wd.html">' . __( 'Get Some Help' ,'gawd' ) . '</a></li>
224
+ <li><span class="dashicons dashicons-dismiss"></span><a href="' . $one_week_support . '">' . __( 'Never show again' ,'gawd' ) . '</a></li>',
225
+ 'int' => 7
226
+ );
227
+
228
+ $this->admin_notice($notices);
229
+ }
230
+ }
231
+
232
+ new GAWD_Notices();
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://web-dorado.com/products/wordpress-google-analytics-plugin.h
4
  Tags: google analytics dashboard, google analytics, statistics, tracking, analytics, analytics dashboard, stats, ga, universal analytics, ecommerce tracking, custom dimensions, custom reports
5
  Requires at least: 3.9
6
  Tested up to: 4.6
7
- Stable tag: 1.0.5
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -98,6 +98,12 @@ Upgrade to Google Analytics WD Pro for premium features:
98
 
99
  == Changelog ==
100
 
 
 
 
 
 
 
101
  = 1.0.5 =
102
  Fixed: PHP version conflict
103
  Added: Pro flags about additional functionality available in Pro version
4
  Tags: google analytics dashboard, google analytics, statistics, tracking, analytics, analytics dashboard, stats, ga, universal analytics, ecommerce tracking, custom dimensions, custom reports
5
  Requires at least: 3.9
6
  Tested up to: 4.6
7
+ Stable tag: 1.0.6
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
98
 
99
  == Changelog ==
100
 
101
+ = 1.0.6 =
102
+ Fixed: User guide links
103
+ Fixed: Bug on datepicker
104
+ Fixed: Error when deleting the web property
105
+ Added: Validation on the form for adding goals
106
+
107
  = 1.0.5 =
108
  Fixed: PHP version conflict
109
  Added: Pro flags about additional functionality available in Pro version