<commit_before>/*
 * Copyright 2014 StreetHawk
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

/**
 * Javascript interface for Streethawk library.
 * Online document https://streethawk.freshdesk.com/solution/categories/5000158959/folders/5000254780
 */

var exec = require('cordova/exec');
var SHLibrary = function() {};

var streethawkTags = {
    'sh_email' 			:	'sh_email',
	'sh_phone'			: 	'sh_phone',
    'sh_gender'			: 	'sh_gender',
    'sh_cuid'			:	'sh_cuid',
    'sh_first_name' 	:	'sh_first_name',
    'sh_last_name' 		:	'sh_last_name',
    'sh_date_of_birth' 	:	'sh_date_of_birth',
    'sh_utc_offset' 	:	'sh_utc_offset'
};

SHLibrary.prototype.streethawkinit = function(appSuccess, appFail) {
    console.log("streethawkinit");
    exec(appSuccess, appFail, 'Streethawk', 'streethawkinit', []);
    document.addEventListener("resume", function() {
        exec(appSuccess, appFail, 'Streethawk', 'shOnResume', []);
    }, false);
	document.addEventListener("pause",function() {
        exec(appSuccess, appFail, 'Streethawk', 'shOnPause', []);
    }, false);
}
SHLibrary.prototype.setAppKey = function(string_AppKey, appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'setAppKey', [string_AppKey]);
}
SHLibrary.prototype.tagNumeric = function(string_key, numeric_value, appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'tagNumeric', [string_key, numeric_value]);
}
SHLibrary.prototype.tagCuid = function(string_cuid, appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'tagCuid', [string_cuid]);
}
SHLibrary.prototype.tagString = function(string_key, string_value, appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'tagString', [string_key, string_value]);
}
SHLibrary.prototype.tagDatetime = function(string_key, datetime_value, appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'tagDatetime', [string_key, datetime_value]);
}
SHLibrary.prototype.incrementTag = function(string_key, appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'incrementTag', [string_key]);
}
SHLibrary.prototype.removeTag = function(string_key, appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'removeTag', [string_key]);
}
SHLibrary.prototype.setAdvertisementId = function(string_id, appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'setAdvertisementId', [string_id]);
}
SHLibrary.prototype.notifyViewEnter = function(string_pageName, appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'notifyViewEnter', [string_pageName]);
}
SHLibrary.prototype.notifyViewExit = function(string_pageName, appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'notifyViewExit', [string_pageName]);
}
SHLibrary.prototype.getSHLibraryVersion = function(appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'getSHLibraryVersion', []);
}
SHLibrary.prototype.getInstallId = function(appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'getInstallId', []);
}
SHLibrary.prototype.getCurrentFormattedDateTime = function(appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'getCurrentFormattedDateTime', []);
}
SHLibrary.prototype.shGetAppKey = function(appSuccess, appFail) {
    exec(appSuccess, appFail,'Streethawk', 'shGetAppKey', []);
}
SHLibrary.prototype.shDeeplinking = function(appSuccess, appFail) {
    exec(appSuccess, appFail,'Streethawk', 'shDeeplinking', []);
}
SHLibrary.prototype.shSendSimpleFeedback = function(string_title, string_message, appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'shSendSimpleFeedback', [string_title, string_message]);
}

// Push plugin

SHLibrary.prototype.shSetAlertSetting = function(int_pauseMinutes, appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'shSetAlertSetting', [int_pauseMinutes]);
}
SHLibrary.prototype.shGetAlertSettings = function(appSuccess, appFail) {
    exec(appSuccess, appFail,'Streethawk', 'shAlertSettings', []);
}
SHLibrary.prototype.shSetGcmSenderId = function(string_senderKey, appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'shSetGcmSenderId', [string_senderKey]);
}
SHLibrary.prototype.pushDataCallback = function(appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'registerPushDataCallback', []);
}
SHLibrary.prototype.pushResultCallback = function(appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'registerPushResultCallback', []);
}
SHLibrary.prototype.shRawJsonCallback = function(appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'shRawJsonCallback', []);
}
SHLibrary.prototype.shRegisterViewCallback = function(appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'shRegisterViewCallback', []);
}
SHLibrary.prototype.shGetViewName = function(appSuccess, appFail) {
   exec(appSuccess, appFail,'Streethawk', 'shGetViewName',[]);
}
SHLibrary.prototype.setUseCustomDialog = function(bool_enable, appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'setUseCustomDialog', [bool_enable]);
}
SHLibrary.prototype.forcePushToNotificationBar = function(bool_status, appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'forcePushToNotificationBar', [bool_status]);
}
SHLibrary.prototype.sendPushResult = function(bool_status, appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'forcePushToNotificationBar', [bool_status]);
}

// Growth plugin

SHLibrary.prototype.originateShareWithCampaign = function(string_utm_campaign, string_utm_source, string_utm_medium, string_utm_content, string_utm_term, string_shareUrl, string_default_url, appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'getShareUrlForAppDownload', [string_utm_campaign, string_utm_source, string_utm_medium, string_utm_content, string_utm_term, string_shareUrl, string_default_url]);
}
SHLibrary.prototype.originateShareWithSourceSelection = function(string_ID,string_deepLinkUrl, string_default_url, appSuccess, appFail) {
	exec(appSuccess, appFail, 'Streethawk', 'originateShareWithCampaign', [string_ID,string_deepLinkUrl, string_default_url]);
}

// Beacon plugin

SHLibrary.prototype.shEnterBeacon = function(string_uuid, int_majorNo, int_minorNo, double_distance, appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'shEnterBeacon', [string_uuid,int_majorNo,int_minorNo,double_distance]);
}
SHLibrary.prototype.shExitBeacon = function(string_uuid, int_majorNo, int_minorNo, appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'shExitBeacon', [string_uuid,int_majorNo,int_minorNo]);
}

// Feed plugin

SHLibrary.prototype.notifyNewFeedCallback = function(appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'registerFeedItemCallback', []);
}
SHLibrary.prototype.reportFeedAck = function(int_feedid, appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'shReportFeedAck', [int_feedid]);
}
SHLibrary.prototype.reportFeedRead = function(int_feedid, int_result, appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'shReportFeedResult', [int_feedid, int_result]);
}
SHLibrary.prototype.shGetFeedDataFromServer = function(int_offset, appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'shGetFeedDataFromServer', [int_offset]);
}

// Location plugin

SHLibrary.prototype.startLocationReporting = function(appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'shStartLocationReporting',[]);
}
SHLibrary.prototype.stopLocationReporting = function(appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'shStopLocationReporting',[]);
}
SHLibrary.prototype.reportWorkHomeLocationOnly = function(appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'shReportWorkHomeLocationOnly',[]);
}
SHLibrary.prototype.updateLocationMonitoringParams = function(int_interval_FG, int_distance_FG, int_interval_BG, int_distance_BG, appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'shUpdateLocationMonitoringParams',[int_interval_FG,int_distance_FG,int_interval_BG,int_distance_BG]);
}
SHLibrary.prototype.startLocationWithPermissionDialog = function(string_msg,appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'shStartLocationWithPermissionDialog',[string_msg]);
}

// Geofence plugin

SHLibrary.prototype.startGeofenceMonitoring = function(appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'shStartGeofenceMonitoring',[]);
}
SHLibrary.prototype.stopGeofenceMonitoring = function(appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'shStopGeofenceMonitoring',[]);
}
SHLibrary.prototype.StartGeofenceWithPermissionDialog = function(string_msg,appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'shStartGeofenceWithPermissionDialog',[string_msg]);
}

// iOS specific
SHLibrary.prototype.shSetEnableLogs = function(bool_enable, appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'shSetEnableLogs', [bool_enable]);
}
SHLibrary.prototype.shSetiTunesId = function(string_iTunesid, appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'shSetiTunesId', [string_iTunesid]);
}
SHLibrary.prototype.shiTunesId = function(appSuccess, appFail) {
    exec(appSuccess,appFail,'Streethawk', 'shiTunesId', []);
}
SHLibrary.prototype.shSetDefaultNotificationService = function(bool_enable, appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'shSetDefaultNotificationService', [bool_enable]);
}
SHLibrary.prototype.shSetNotificationEnabled = function(bool_enable, appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'shSetNotificationEnabled', [bool_enable]);
}
SHLibrary.prototype.shGetNotificationEnabled = function(appSuccess, appFail) {
    exec(appSuccess, appFail,'Streethawk', 'shGetNotificationEnabled', []);
}
SHLibrary.prototype.shSetDefaultLocationService = function(bool_enable, appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'shSetDefaultLocationService', [bool_enable]);
}
SHLibrary.prototype.shSetLocationEnabled = function(bool_enable, appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'shSetLocationEnabled', [bool_enable]);
}
SHLibrary.prototype.shGetLocationEnabled = function(appSuccess, appFail) {
    exec(appSuccess, appFail,'Streethawk', 'shGetLocationEnabled', []);
}

var myplugin = new SHLibrary();
module.exports = myplugin;
<commit_msg>Fix `sendPushResult` script.<commit_after>/*
 * Copyright 2014 StreetHawk
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

/**
 * Javascript interface for Streethawk library.
 * Online document https://streethawk.freshdesk.com/solution/categories/5000158959/folders/5000254780
 */

var exec = require('cordova/exec');
var SHLibrary = function() {};

var streethawkTags = {
    'sh_email' 			:	'sh_email',
	'sh_phone'			: 	'sh_phone',
    'sh_gender'			: 	'sh_gender',
    'sh_cuid'			:	'sh_cuid',
    'sh_first_name' 	:	'sh_first_name',
    'sh_last_name' 		:	'sh_last_name',
    'sh_date_of_birth' 	:	'sh_date_of_birth',
    'sh_utc_offset' 	:	'sh_utc_offset'
};

SHLibrary.prototype.streethawkinit = function(appSuccess, appFail) {
    console.log("streethawkinit");
    exec(appSuccess, appFail, 'Streethawk', 'streethawkinit', []);
    document.addEventListener("resume", function() {
        exec(appSuccess, appFail, 'Streethawk', 'shOnResume', []);
    }, false);
	document.addEventListener("pause",function() {
        exec(appSuccess, appFail, 'Streethawk', 'shOnPause', []);
    }, false);
}
SHLibrary.prototype.setAppKey = function(string_AppKey, appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'setAppKey', [string_AppKey]);
}
SHLibrary.prototype.tagNumeric = function(string_key, numeric_value, appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'tagNumeric', [string_key, numeric_value]);
}
SHLibrary.prototype.tagCuid = function(string_cuid, appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'tagCuid', [string_cuid]);
}
SHLibrary.prototype.tagString = function(string_key, string_value, appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'tagString', [string_key, string_value]);
}
SHLibrary.prototype.tagDatetime = function(string_key, datetime_value, appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'tagDatetime', [string_key, datetime_value]);
}
SHLibrary.prototype.incrementTag = function(string_key, appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'incrementTag', [string_key]);
}
SHLibrary.prototype.removeTag = function(string_key, appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'removeTag', [string_key]);
}
SHLibrary.prototype.setAdvertisementId = function(string_id, appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'setAdvertisementId', [string_id]);
}
SHLibrary.prototype.notifyViewEnter = function(string_pageName, appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'notifyViewEnter', [string_pageName]);
}
SHLibrary.prototype.notifyViewExit = function(string_pageName, appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'notifyViewExit', [string_pageName]);
}
SHLibrary.prototype.getSHLibraryVersion = function(appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'getSHLibraryVersion', []);
}
SHLibrary.prototype.getInstallId = function(appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'getInstallId', []);
}
SHLibrary.prototype.getCurrentFormattedDateTime = function(appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'getCurrentFormattedDateTime', []);
}
SHLibrary.prototype.shGetAppKey = function(appSuccess, appFail) {
    exec(appSuccess, appFail,'Streethawk', 'shGetAppKey', []);
}
SHLibrary.prototype.shDeeplinking = function(appSuccess, appFail) {
    exec(appSuccess, appFail,'Streethawk', 'shDeeplinking', []);
}
SHLibrary.prototype.shSendSimpleFeedback = function(string_title, string_message, appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'shSendSimpleFeedback', [string_title, string_message]);
}

// Push plugin

SHLibrary.prototype.shSetAlertSetting = function(int_pauseMinutes, appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'shSetAlertSetting', [int_pauseMinutes]);
}
SHLibrary.prototype.shGetAlertSettings = function(appSuccess, appFail) {
    exec(appSuccess, appFail,'Streethawk', 'shAlertSettings', []);
}
SHLibrary.prototype.shSetGcmSenderId = function(string_senderKey, appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'shSetGcmSenderId', [string_senderKey]);
}
SHLibrary.prototype.pushDataCallback = function(appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'registerPushDataCallback', []);
}
SHLibrary.prototype.pushResultCallback = function(appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'registerPushResultCallback', []);
}
SHLibrary.prototype.shRawJsonCallback = function(appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'shRawJsonCallback', []);
}
SHLibrary.prototype.shRegisterViewCallback = function(appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'shRegisterViewCallback', []);
}
SHLibrary.prototype.shGetViewName = function(appSuccess, appFail) {
   exec(appSuccess, appFail,'Streethawk', 'shGetViewName',[]);
}
SHLibrary.prototype.setUseCustomDialog = function(bool_enable, appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'setUseCustomDialog', [bool_enable]);
}
SHLibrary.prototype.forcePushToNotificationBar = function(bool_status, appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'forcePushToNotificationBar', [bool_status]);
}
SHLibrary.prototype.sendPushResult = function(int_msgid, int_pushresult, appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'sendPushResult', [int_msgid, int_pushresult]);
}

// Growth plugin

SHLibrary.prototype.originateShareWithCampaign = function(string_utm_campaign, string_utm_source, string_utm_medium, string_utm_content, string_utm_term, string_shareUrl, string_default_url, appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'getShareUrlForAppDownload', [string_utm_campaign, string_utm_source, string_utm_medium, string_utm_content, string_utm_term, string_shareUrl, string_default_url]);
}
SHLibrary.prototype.originateShareWithSourceSelection = function(string_ID,string_deepLinkUrl, string_default_url, appSuccess, appFail) {
	exec(appSuccess, appFail, 'Streethawk', 'originateShareWithCampaign', [string_ID,string_deepLinkUrl, string_default_url]);
}

// Beacon plugin

SHLibrary.prototype.shEnterBeacon = function(string_uuid, int_majorNo, int_minorNo, double_distance, appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'shEnterBeacon', [string_uuid,int_majorNo,int_minorNo,double_distance]);
}
SHLibrary.prototype.shExitBeacon = function(string_uuid, int_majorNo, int_minorNo, appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'shExitBeacon', [string_uuid,int_majorNo,int_minorNo]);
}

// Feed plugin

SHLibrary.prototype.notifyNewFeedCallback = function(appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'registerFeedItemCallback', []);
}
SHLibrary.prototype.reportFeedAck = function(int_feedid, appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'shReportFeedAck', [int_feedid]);
}
SHLibrary.prototype.reportFeedRead = function(int_feedid, int_result, appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'shReportFeedResult', [int_feedid, int_result]);
}
SHLibrary.prototype.shGetFeedDataFromServer = function(int_offset, appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'shGetFeedDataFromServer', [int_offset]);
}

// Location plugin

SHLibrary.prototype.startLocationReporting = function(appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'shStartLocationReporting',[]);
}
SHLibrary.prototype.stopLocationReporting = function(appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'shStopLocationReporting',[]);
}
SHLibrary.prototype.reportWorkHomeLocationOnly = function(appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'shReportWorkHomeLocationOnly',[]);
}
SHLibrary.prototype.updateLocationMonitoringParams = function(int_interval_FG, int_distance_FG, int_interval_BG, int_distance_BG, appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'shUpdateLocationMonitoringParams',[int_interval_FG,int_distance_FG,int_interval_BG,int_distance_BG]);
}
SHLibrary.prototype.startLocationWithPermissionDialog = function(string_msg,appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'shStartLocationWithPermissionDialog',[string_msg]);
}

// Geofence plugin

SHLibrary.prototype.startGeofenceMonitoring = function(appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'shStartGeofenceMonitoring',[]);
}
SHLibrary.prototype.stopGeofenceMonitoring = function(appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'shStopGeofenceMonitoring',[]);
}
SHLibrary.prototype.StartGeofenceWithPermissionDialog = function(string_msg,appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'shStartGeofenceWithPermissionDialog',[string_msg]);
}

// iOS specific
SHLibrary.prototype.shSetEnableLogs = function(bool_enable, appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'shSetEnableLogs', [bool_enable]);
}
SHLibrary.prototype.shSetiTunesId = function(string_iTunesid, appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'shSetiTunesId', [string_iTunesid]);
}
SHLibrary.prototype.shiTunesId = function(appSuccess, appFail) {
    exec(appSuccess,appFail,'Streethawk', 'shiTunesId', []);
}
SHLibrary.prototype.shSetDefaultNotificationService = function(bool_enable, appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'shSetDefaultNotificationService', [bool_enable]);
}
SHLibrary.prototype.shSetNotificationEnabled = function(bool_enable, appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'shSetNotificationEnabled', [bool_enable]);
}
SHLibrary.prototype.shGetNotificationEnabled = function(appSuccess, appFail) {
    exec(appSuccess, appFail,'Streethawk', 'shGetNotificationEnabled', []);
}
SHLibrary.prototype.shSetDefaultLocationService = function(bool_enable, appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'shSetDefaultLocationService', [bool_enable]);
}
SHLibrary.prototype.shSetLocationEnabled = function(bool_enable, appSuccess, appFail) {
    exec(appSuccess, appFail, 'Streethawk', 'shSetLocationEnabled', [bool_enable]);
}
SHLibrary.prototype.shGetLocationEnabled = function(appSuccess, appFail) {
    exec(appSuccess, appFail,'Streethawk', 'shGetLocationEnabled', []);
}

var myplugin = new SHLibrary();
module.exports = myplugin;
<|endoftext|>


<commit_before>	var map;
	var myLatlng;
	function initProfile() {

			var showTab = jQuery.getQuery('tab');
			switch(showTab){
				case 'person':
					showPerson(true);
					break;
				case 'story':
					showStory(true);
					break;
				case 'place':
				default:
					showPlace(true);
					break;
			}

			var styles = [
							{
								"elementType": "labels.icon",
								"stylers": [
								  { "visibility": "off" }
								]
							  },
							{
								"elementType": "geometry.stroke",
								"stylers": [
								  { "color": "#343434" }
								]
							  },
							{
								"elementType": "geometry.fill",
								"stylers": [
								  { "color": "#232323" }
								]
							  },
							  {
								"featureType": "landscape",
								"elementType": "geometry.fill",
								"stylers": [
								  { "color": "#232323" }
								]
							  },{
								"featureType": "road.local",
								"elementType": "geometry.stroke",
								"stylers": [
								  { "color": "#313131" }
								]
							  },{
								"featureType": "road.local",
								"elementType": "geometry.fill",
								"stylers": [
								  { "color": "#313131" }
								]
							  },{
								"featureType": "road.arterial",
								"elementType": "geometry.fill",
								"stylers": [
								  { "color": "#121212" }
								]
							  },{
								"featureType": "road.arterial",
								"elementType": "geometry.stroke",
								"stylers": [
								  { "color": "#121212" }
								]
							  },{
								"featureType": "water",
								"elementType": "geometry.fill",
								"stylers": [
								  { "color": "#292929" }
								]
							  },{
								"featureType": "poi",
								"stylers": [
								  { "visibility": "off" }
								]
							  },{
								"featureType": "transit",
								"stylers": [
								  { "visibility": "off" }
								]
							  },{
								"featureType": "road.local",
								"elementType": "labels.text",
								"stylers": [
								  { "visibility": "off" }
								]
							  },{
								"featureType": "road.highway",
								"elementType": "geometry.fill",
								"stylers": [
								  { "color": "#565656" }
								]
							  },{
								"featureType": "road.highway",
								"elementType": "labels",
								"stylers": [
								  { "visibility": "off" }
								]
							  },{
								"featureType": "road.highway",
								"elementType": "geometry",
								"stylers": [
								  { "color": "#565656" }
								]
							  },{

								"elementType": "labels.text.stroke",
								"stylers": [
								  { "color": "#111111" }
								]
							  },{
								"featureType": "administrative",
								"elementType": "labels.text.stroke",
								"stylers": [
								  { "color": "#333333" }
								]
							  },{
								"featureType": "administrative",
								"elementType": "labels.text.fill",
								"stylers": [
								  { "color": "#808080" }
								]
							  },
							  {
								"featureType": "landscape.man_made",
								"stylers": [
								  { "visibility": "off" }
								]
							  }
							];
			var styledMap = new google.maps.StyledMapType(styles,{name: "Styled Map"});

			var itemid = jQuery.getQuery('itemid');
			jQuery.getJSON( "http://miflamencoplace.com/rpc/get_profile.php?itemid="+itemid, function( data ) {
				fillProfile(data);
				placeLatlng = new google.maps.LatLng(data.lat, data.long);
				var mapOptions = {
					zoom: 14,
					disableDefaultUI: true,
					center: placeLatlng,
					scrollwheel: false,
					draggable: false
				};
				map = new google.maps.Map(document.getElementById('map-canvas'),mapOptions);
				map.mapTypes.set("map_style",styledMap);
				map.setMapTypeId("map_style");
				var vpw = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);
				var sfx = (vpw > 1024)?'hd':'';
				var marker = new google.maps.Marker({
					position: placeLatlng,
					map: map,
					title: data.title,
					icon: '../img/markers/'+sfx+data.catid+'.png'
				});

			});
	}

	function fillProfile(data){
		$('#place').css('background',' url(../img/overlay.png) repeat,url(http://miflamencoplace.com'+data.img+') no-repeat center top')
		.css('background-size','auto,cover');
		$('#place .title').html(data.title);
		$('#place .author').html('By '+data.personname);
		$('#place .personface img').attr('src','http://miflamencoplace.com'+data.personface);
		if (langid == 'en'){
			$('#place .introtext').html(data.placeintrotexten);
			$('#place .fulltext').html(data.placefulltexten);
			$('#person .authortext').html(data.persontexten);
			if (data.audioen != null){
				$('#story .downloada').click(function(){manageFile('http://miflamencoplace.com/media/k2/attachments/'+data.audioen, data.audioen )});
				if(isDownloadedFile(data.audioen)){
					alert('lo tengo');
					$('#story .downloada').addClass('pause');
				} else {
					alert('NO lo tengo');
				}
			}else{
				$('#story .downloada').hide();
			}
		} else {
			$('#place .introtext').html(data.placeintrotext);
			$('#place .fulltext').html(data.placefulltext);
			$('#person .authortext').html(data.persontext);
			if (data.audioes != null){
				$('#story .downloada').click(function(){manageFile('http://miflamencoplace.com/media/k2/attachments/'+data.audioes,data.audioes )});
				if(isDownloadedFile(data.audioes)){
					alert('lo tengo');
					$('#story .downloada').addClass('pause');
				} else {
					alert('NO lo tengo');
				}
			}else{
				$('#story .downloada').hide();
			}
		}
		$('#person').css('background','url(http://miflamencoplace.com/media/k2/items/cache/'+data.personpicture+') no-repeat center top');
		$('#person .authorname').html(data.personname);
		$('#story .placetitle').html(data.title);
		$('#story .persontitle').html('By '+data.personname);
		$('#story .right img').attr('src','http://miflamencoplace.com'+data.img);
		$('#story .authorname').html(data.personname);
		$('#story #onyoutube').attr('href',data.onyoutube);
		var galContent = '';
		data.placegallery.forEach(function(galpic) {
			galContent += '';
		});
		$('#place .gallery').html(galContent);
	}

	function zoomPicture(picture){
		$('#zoom').css('background-image','url('+picture+')');
		$('.md-modal').removeClass('md-hide');
		return false;
	}

	function closeZoom(){
		$('.md-modal').addClass('md-hide');
		$('#zoom').css('background-image','');
	}

	function toggleFilter(){
		if (jQuery('#filter').hasClass('open')) {
			jQuery('#filteropts').slideUp('fast');
			jQuery('#filter').removeClass('open');
		} else {
			jQuery('#filteropts').slideDown();
			jQuery('#filter').addClass('open');
		}
		return false;
	}

(function($){
    $.getQuery = function( query ) {
        query = query.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
        var expr = "[\\?&]"+query+"=([^&#]*)";
        var regex = new RegExp( expr );
        var results = regex.exec( window.location.href );
        if( results !== null ) {
            return results[1];
            return decodeURIComponent(results[1].replace(/\+/g, " "));
        } else {
            return false;
        }
    };
})(jQuery);

	function showPlace(open){

		jQuery('#person').fadeOut('fast');
		jQuery('#story').fadeOut('fast');
		jQuery('#place').fadeIn('slow');
		jQuery('#filteropts a').show();
		jQuery('#filteropts .place').hide();
		if (!open){
			toggleFilter();
		}
		return false;
	}
	function showPerson(open){

		jQuery('#story').fadeOut('fast');
		jQuery('#place').fadeOut('fast');
		jQuery('#person').fadeIn('slow');
		jQuery('#filteropts a').show();
		jQuery('#filteropts .person').hide();
		if (!open){
			toggleFilter();
		}
		return false;
	}
	function showStory(open){

		jQuery('#person').fadeOut('fast');
		jQuery('#place').fadeOut('fast');
		jQuery('#story').fadeIn('slow');
		jQuery('#filteropts a').show();
		jQuery('#filteropts .story').hide();
		if (!open){
			toggleFilter();
		}
		return false;
	}

	function isDownloadedFile(nameFile)
	{
		window.requestFileSystem(LocalFileSystem.PERSISTENT, 0,
			function onFileSystemSuccess(fileSystem) {
				var folderName = 'miflamencoplace'
				var directoryEntry = fileSystem.root;
				directoryEntry.getDirectory(folderName, { create: true, exclusive: false }, onDirectorySuccess, onDirectoryFail); // creating folder in sdcard
				function onDirectorySuccess(parent) {
					var directoryReader = parent.createReader();
					directoryReader.readEntries(successReader,fail);
				}
				function successReader(entries) {
					var i;
					for (i=0; i<entries.length; i++) {
						if (entries[i].name == nameFile){
							return true;
						}
					}
					if (!fileFound){
						return false;
					}
				}
			},
			onError
		);
	}

function manageFile(file, nameFile){

window.requestFileSystem(LocalFileSystem.PERSISTENT, 0,
    function onFileSystemSuccess(fileSystem) {
			var folderName = 'miflamencoplace'
			var directoryEntry = fileSystem.root; // to get root path of directory
			directoryEntry.getDirectory(folderName, { create: true, exclusive: false }, onDirectorySuccess, onDirectoryFail); // creating folder in sdcard

			function onDirectorySuccess(parent) {
				 var directoryReader = parent.createReader();
				directoryReader.readEntries(successReader,fail);
			}

			function successReader(entries) {
					var i;
					var fileFound = false;
					for (i=0; i<entries.length; i++) {
					   if (entries[i].name == nameFile){
						fileFound = true;
						playAudio(entries[i]);
					   }
					}
					if (!fileFound){
						var fp = directoryEntry.toURL(); // Returns Fulpath of local directory
						fp = fp + folderName + "/" + nameFile;
						var fileTransfer = new FileTransfer();
						fileTransfer.download(
							file,
							fp,
							function(theFile) {
								alert("download complete: " + theFile.toURI());
								playAudio(theFile);
							},
							function(error) {
								alert("download error source " + error.source);
								alert("download error target " + error.target);
								alert("upload error code: " + error.code);
							}
						);

					}
				};

    }, onError);
};

function onDirectoryFail(error) {
    //Error while creating directory
    alert("Unable to create new directory: " + error.code);
}

 function playAudio(src) {
            // Create Media object from src
	alert(src.toNativeURL());
	my_media = new Media(src.toNativeURL(), onSuccess, onError);

	// Play audio
	my_media.play();

}

function onSuccess() {
	alert("playAudio():Audio Success");
}

// onError Callback
//
function fail(){}
function onError(error) {
	alert('code: '    + error.code    + '\n' +
		  'message: ' + error.message + '\n');
}
	<commit_msg>asdasd<commit_after>	var map;
	var myLatlng;
	function initProfile() {

			var showTab = jQuery.getQuery('tab');
			switch(showTab){
				case 'person':
					showPerson(true);
					break;
				case 'story':
					showStory(true);
					break;
				case 'place':
				default:
					showPlace(true);
					break;
			}

			var styles = [
							{
								"elementType": "labels.icon",
								"stylers": [
								  { "visibility": "off" }
								]
							  },
							{
								"elementType": "geometry.stroke",
								"stylers": [
								  { "color": "#343434" }
								]
							  },
							{
								"elementType": "geometry.fill",
								"stylers": [
								  { "color": "#232323" }
								]
							  },
							  {
								"featureType": "landscape",
								"elementType": "geometry.fill",
								"stylers": [
								  { "color": "#232323" }
								]
							  },{
								"featureType": "road.local",
								"elementType": "geometry.stroke",
								"stylers": [
								  { "color": "#313131" }
								]
							  },{
								"featureType": "road.local",
								"elementType": "geometry.fill",
								"stylers": [
								  { "color": "#313131" }
								]
							  },{
								"featureType": "road.arterial",
								"elementType": "geometry.fill",
								"stylers": [
								  { "color": "#121212" }
								]
							  },{
								"featureType": "road.arterial",
								"elementType": "geometry.stroke",
								"stylers": [
								  { "color": "#121212" }
								]
							  },{
								"featureType": "water",
								"elementType": "geometry.fill",
								"stylers": [
								  { "color": "#292929" }
								]
							  },{
								"featureType": "poi",
								"stylers": [
								  { "visibility": "off" }
								]
							  },{
								"featureType": "transit",
								"stylers": [
								  { "visibility": "off" }
								]
							  },{
								"featureType": "road.local",
								"elementType": "labels.text",
								"stylers": [
								  { "visibility": "off" }
								]
							  },{
								"featureType": "road.highway",
								"elementType": "geometry.fill",
								"stylers": [
								  { "color": "#565656" }
								]
							  },{
								"featureType": "road.highway",
								"elementType": "labels",
								"stylers": [
								  { "visibility": "off" }
								]
							  },{
								"featureType": "road.highway",
								"elementType": "geometry",
								"stylers": [
								  { "color": "#565656" }
								]
							  },{

								"elementType": "labels.text.stroke",
								"stylers": [
								  { "color": "#111111" }
								]
							  },{
								"featureType": "administrative",
								"elementType": "labels.text.stroke",
								"stylers": [
								  { "color": "#333333" }
								]
							  },{
								"featureType": "administrative",
								"elementType": "labels.text.fill",
								"stylers": [
								  { "color": "#808080" }
								]
							  },
							  {
								"featureType": "landscape.man_made",
								"stylers": [
								  { "visibility": "off" }
								]
							  }
							];
			var styledMap = new google.maps.StyledMapType(styles,{name: "Styled Map"});

			var itemid = jQuery.getQuery('itemid');
			jQuery.getJSON( "http://miflamencoplace.com/rpc/get_profile.php?itemid="+itemid, function( data ) {
				fillProfile(data);
				placeLatlng = new google.maps.LatLng(data.lat, data.long);
				var mapOptions = {
					zoom: 14,
					disableDefaultUI: true,
					center: placeLatlng,
					scrollwheel: false,
					draggable: false
				};
				map = new google.maps.Map(document.getElementById('map-canvas'),mapOptions);
				map.mapTypes.set("map_style",styledMap);
				map.setMapTypeId("map_style");
				var vpw = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);
				var sfx = (vpw > 1024)?'hd':'';
				var marker = new google.maps.Marker({
					position: placeLatlng,
					map: map,
					title: data.title,
					icon: '../img/markers/'+sfx+data.catid+'.png'
				});

			});
	}

	function fillProfile(data){
		$('#place').css('background',' url(../img/overlay.png) repeat,url(http://miflamencoplace.com'+data.img+') no-repeat center top')
		.css('background-size','auto,cover');
		$('#place .title').html(data.title);
		$('#place .author').html('By '+data.personname);
		$('#place .personface img').attr('src','http://miflamencoplace.com'+data.personface);
		if (langid == 'en'){
			$('#place .introtext').html(data.placeintrotexten);
			$('#place .fulltext').html(data.placefulltexten);
			$('#person .authortext').html(data.persontexten);
			if (data.audioen != null){
				$('#story .downloada').click(function(){manageFile('http://miflamencoplace.com/media/k2/attachments/'+data.audioen, data.audioen )});
				if(isDownloadedFile(data.audioen)){
					alert('lo tengo');
					$('#story .downloada').addClass('pause');
				} else {
					alert('NO lo tengo');
				}
			}else{
				$('#story .downloada').hide();
			}
		} else {
			$('#place .introtext').html(data.placeintrotext);
			$('#place .fulltext').html(data.placefulltext);
			$('#person .authortext').html(data.persontext);
			if (data.audioes != null){
				$('#story .downloada').click(function(){manageFile('http://miflamencoplace.com/media/k2/attachments/'+data.audioes,data.audioes )});
				if(isDownloadedFile(data.audioes)){
					alert('lo tengo');
					$('#story .downloada').addClass('pause');
				} else {
					alert('NO lo tengo');
				}
			}else{
				$('#story .downloada').hide();
			}
		}
		$('#person').css('background','url(http://miflamencoplace.com/media/k2/items/cache/'+data.personpicture+') no-repeat center top');
		$('#person .authorname').html(data.personname);
		$('#story .placetitle').html(data.title);
		$('#story .persontitle').html('By '+data.personname);
		$('#story .right img').attr('src','http://miflamencoplace.com'+data.img);
		$('#story .authorname').html(data.personname);
		$('#story #onyoutube').attr('href',data.onyoutube);
		var galContent = '';
		data.placegallery.forEach(function(galpic) {
			galContent += '';
		});
		$('#place .gallery').html(galContent);
	}

	function zoomPicture(picture){
		$('#zoom').css('background-image','url('+picture+')');
		$('.md-modal').removeClass('md-hide');
		return false;
	}

	function closeZoom(){
		$('.md-modal').addClass('md-hide');
		$('#zoom').css('background-image','');
	}

	function toggleFilter(){
		if (jQuery('#filter').hasClass('open')) {
			jQuery('#filteropts').slideUp('fast');
			jQuery('#filter').removeClass('open');
		} else {
			jQuery('#filteropts').slideDown();
			jQuery('#filter').addClass('open');
		}
		return false;
	}

(function($){
    $.getQuery = function( query ) {
        query = query.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
        var expr = "[\\?&]"+query+"=([^&#]*)";
        var regex = new RegExp( expr );
        var results = regex.exec( window.location.href );
        if( results !== null ) {
            return results[1];
            return decodeURIComponent(results[1].replace(/\+/g, " "));
        } else {
            return false;
        }
    };
})(jQuery);

	function showPlace(open){

		jQuery('#person').fadeOut('fast');
		jQuery('#story').fadeOut('fast');
		jQuery('#place').fadeIn('slow');
		jQuery('#filteropts a').show();
		jQuery('#filteropts .place').hide();
		if (!open){
			toggleFilter();
		}
		return false;
	}
	function showPerson(open){

		jQuery('#story').fadeOut('fast');
		jQuery('#place').fadeOut('fast');
		jQuery('#person').fadeIn('slow');
		jQuery('#filteropts a').show();
		jQuery('#filteropts .person').hide();
		if (!open){
			toggleFilter();
		}
		return false;
	}
	function showStory(open){

		jQuery('#person').fadeOut('fast');
		jQuery('#place').fadeOut('fast');
		jQuery('#story').fadeIn('slow');
		jQuery('#filteropts a').show();
		jQuery('#filteropts .story').hide();
		if (!open){
			toggleFilter();
		}
		return false;
	}

	function isDownloadedFile(nameFile)
	{
		window.requestFileSystem(LocalFileSystem.PERSISTENT, 0,
			function onFileSystemSuccess(fileSystem) {
				var folderName = 'miflamencoplace'
				var directoryEntry = fileSystem.root;
				directoryEntry.getDirectory(folderName, { create: true, exclusive: false }, onDirectorySuccess, onDirectoryFail); // creating folder in sdcard
				function onDirectorySuccess(parent) {
					var directoryReader = parent.createReader();
					directoryReader.readEntries(successReader,fail);
				}
				function successReader(entries) {
					var i;
					for (i=0; i<entries.length; i++) {
						alert(entries[i].name +" -> "+ nameFile);
						if (entries[i].name == nameFile){
							return true;
						}
					}
					if (!fileFound){
						return false;
					}
				}
			},
			onError
		);
	}

function manageFile(file, nameFile){

window.requestFileSystem(LocalFileSystem.PERSISTENT, 0,
    function onFileSystemSuccess(fileSystem) {
			var folderName = 'miflamencoplace'
			var directoryEntry = fileSystem.root; // to get root path of directory
			directoryEntry.getDirectory(folderName, { create: true, exclusive: false }, onDirectorySuccess, onDirectoryFail); // creating folder in sdcard

			function onDirectorySuccess(parent) {
				 var directoryReader = parent.createReader();
				directoryReader.readEntries(successReader,fail);
			}

			function successReader(entries) {
					var i;
					var fileFound = false;
					for (i=0; i<entries.length; i++) {
					   if (entries[i].name == nameFile){
						fileFound = true;
						playAudio(entries[i]);
					   }
					}
					if (!fileFound){
						var fp = directoryEntry.toURL(); // Returns Fulpath of local directory
						fp = fp + folderName + "/" + nameFile;
						var fileTransfer = new FileTransfer();
						fileTransfer.download(
							file,
							fp,
							function(theFile) {
								alert("download complete: " + theFile.toURI());
								playAudio(theFile);
							},
							function(error) {
								alert("download error source " + error.source);
								alert("download error target " + error.target);
								alert("upload error code: " + error.code);
							}
						);

					}
				};

    }, onError);
};

function onDirectoryFail(error) {
    //Error while creating directory
    alert("Unable to create new directory: " + error.code);
}

 function playAudio(src) {
            // Create Media object from src
	alert(src.toNativeURL());
	my_media = new Media(src.toNativeURL(), onSuccess, onError);

	// Play audio
	my_media.play();

}

function onSuccess() {
	alert("playAudio():Audio Success");
}

// onError Callback
//
function fail(){}
function onError(error) {
	alert('code: '    + error.code    + '\n' +
		  'message: ' + error.message + '\n');
}
	<|endoftext|>


<commit_before>	var map;
	var myLatlng;
	function initProfile() {

			var showTab = jQuery.getQuery('tab');
			switch(showTab){
				case 'person':
					showPerson(true);
					break;
				case 'story':
					showStory(true);
					break;
				case 'place':
				default:
					showPlace(true);
					break;
			}

			var styles = [
							{
								"elementType": "labels.icon",
								"stylers": [
								  { "visibility": "off" }
								]
							  },
							{
								"elementType": "geometry.stroke",
								"stylers": [
								  { "color": "#343434" }
								]
							  },
							{
								"elementType": "geometry.fill",
								"stylers": [
								  { "color": "#232323" }
								]
							  },
							  {
								"featureType": "landscape",
								"elementType": "geometry.fill",
								"stylers": [
								  { "color": "#232323" }
								]
							  },{
								"featureType": "road.local",
								"elementType": "geometry.stroke",
								"stylers": [
								  { "color": "#313131" }
								]
							  },{
								"featureType": "road.local",
								"elementType": "geometry.fill",
								"stylers": [
								  { "color": "#313131" }
								]
							  },{
								"featureType": "road.arterial",
								"elementType": "geometry.fill",
								"stylers": [
								  { "color": "#121212" }
								]
							  },{
								"featureType": "road.arterial",
								"elementType": "geometry.stroke",
								"stylers": [
								  { "color": "#121212" }
								]
							  },{
								"featureType": "water",
								"elementType": "geometry.fill",
								"stylers": [
								  { "color": "#292929" }
								]
							  },{
								"featureType": "poi",
								"stylers": [
								  { "visibility": "off" }
								]
							  },{
								"featureType": "transit",
								"stylers": [
								  { "visibility": "off" }
								]
							  },{
								"featureType": "road.local",
								"elementType": "labels.text",
								"stylers": [
								  { "visibility": "off" }
								]
							  },{
								"featureType": "road.highway",
								"elementType": "geometry.fill",
								"stylers": [
								  { "color": "#565656" }
								]
							  },{
								"featureType": "road.highway",
								"elementType": "labels",
								"stylers": [
								  { "visibility": "off" }
								]
							  },{
								"featureType": "road.highway",
								"elementType": "geometry",
								"stylers": [
								  { "color": "#565656" }
								]
							  },{

								"elementType": "labels.text.stroke",
								"stylers": [
								  { "color": "#111111" }
								]
							  },{
								"featureType": "administrative",
								"elementType": "labels.text.stroke",
								"stylers": [
								  { "color": "#333333" }
								]
							  },{
								"featureType": "administrative",
								"elementType": "labels.text.fill",
								"stylers": [
								  { "color": "#808080" }
								]
							  },
							  {
								"featureType": "landscape.man_made",
								"stylers": [
								  { "visibility": "off" }
								]
							  }
							];
			var styledMap = new google.maps.StyledMapType(styles,{name: "Styled Map"});

			var itemid = jQuery.getQuery('itemid');
			jQuery.getJSON( "http://miflamencoplace.com/rpc/get_profile.php?itemid="+itemid, function( data ) {
				fillProfile(data);
				placeLatlng = new google.maps.LatLng(data.lat, data.long);
				var mapOptions = {
					zoom: 14,
					disableDefaultUI: true,
					center: placeLatlng,
					scrollwheel: false,
					draggable: false
				};
				map = new google.maps.Map(document.getElementById('map-canvas'),mapOptions);
				map.mapTypes.set("map_style",styledMap);
				map.setMapTypeId("map_style");
				var vpw = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);
				var sfx = (vpw > 1024)?'hd':'';
				var marker = new google.maps.Marker({
					position: placeLatlng,
					map: map,
					title: data.title,
					icon: '../img/markers/'+sfx+data.catid+'.png'
				});

			});
	}

	function fillProfile(data){
		$('#place').css('background',' url(../img/overlay.png) repeat,url(http://miflamencoplace.com'+data.img+') no-repeat center top')
		.css('background-size','auto,cover');
		$('#place .title').html(data.title);
		$('#place .author').html('By '+data.personname);
		$('#place .personface img').attr('src','http://miflamencoplace.com'+data.personface);
		if (langid == 'en'){
			$('#place .introtext').html(data.placeintrotexten);
			$('#place .fulltext').html(data.placefulltexten);
			$('#person .authortext').html(data.persontexten);
			if (data.audioen != null){
				$('#story .downloada').click(function(){manageFile('http://miflamencoplace.com/media/k2/attachments/'+data.audioen, data.audioen )});
			}else{
				$('#story .downloada').hide();
			}
		} else {
			$('#place .introtext').html(data.placeintrotext);
			$('#place .fulltext').html(data.placefulltext);
			$('#person .authortext').html(data.persontext);
			if (data.audioes != null){
				$('#story .downloada').click(function(){manageFile('http://miflamencoplace.com/media/k2/attachments/'+data.audioes,data.audioes )});
			}else{
				$('#story .downloada').hide();
			}
		}
		$('#person').css('background','url(http://miflamencoplace.com/media/k2/items/cache/'+data.personpicture+') no-repeat center top');
		$('#person .authorname').html(data.personname);
		$('#story .placetitle').html(data.title);
		$('#story .persontitle').html('By '+data.personname);
		$('#story .right img').attr('src','http://miflamencoplace.com'+data.img);
		$('#story .authorname').html(data.personname);
		$('#story #onyoutube').attr('href',data.onyoutube);
		var galContent = '';
		data.placegallery.forEach(function(galpic) {
			galContent += '';
		});
		$('#place .gallery').html(galContent);
	}

	function zoomPicture(picture){
		$('#zoom').css('background-image','url('+picture+')');
		$('.md-modal').removeClass('md-hide');
		return false;
	}

	function closeZoom(){
		$('.md-modal').addClass('md-hide');
		$('#zoom').css('background-image','');
	}

	function toggleFilter(){
		if (jQuery('#filter').hasClass('open')) {
			jQuery('#filteropts').slideUp('fast');
			jQuery('#filter').removeClass('open');
		} else {
			jQuery('#filteropts').slideDown();
			jQuery('#filter').addClass('open');
		}
		return false;
	}

(function($){
    $.getQuery = function( query ) {
        query = query.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
        var expr = "[\\?&]"+query+"=([^&#]*)";
        var regex = new RegExp( expr );
        var results = regex.exec( window.location.href );
        if( results !== null ) {
            return results[1];
            return decodeURIComponent(results[1].replace(/\+/g, " "));
        } else {
            return false;
        }
    };
})(jQuery);

	function showPlace(open){

		jQuery('#person').fadeOut('fast');
		jQuery('#story').fadeOut('fast');
		jQuery('#place').fadeIn('slow');
		jQuery('#filteropts a').show();
		jQuery('#filteropts .place').hide();
		if (!open){
			toggleFilter();
		}
		return false;
	}
	function showPerson(open){

		jQuery('#story').fadeOut('fast');
		jQuery('#place').fadeOut('fast');
		jQuery('#person').fadeIn('slow');
		jQuery('#filteropts a').show();
		jQuery('#filteropts .person').hide();
		if (!open){
			toggleFilter();
		}
		return false;
	}
	function showStory(open){

		jQuery('#person').fadeOut('fast');
		jQuery('#place').fadeOut('fast');
		jQuery('#story').fadeIn('slow');
		jQuery('#filteropts a').show();
		jQuery('#filteropts .story').hide();
		if (!open){
			toggleFilter();
		}
		return false;
	}

	function isDownloadedFile()
	{
		entry.getFile("newFile.txt", {create: true, exclusive: false}, success, fail);

		return false;
	}

function manageFile(file, nameFile){

window.requestFileSystem(LocalFileSystem.PERSISTENT, 0,
    function onFileSystemSuccess(fileSystem) {
			var folderName = 'miflamencoplace'
			var directoryEntry = fileSystem.root; // to get root path of directory
			directoryEntry.getDirectory(folderName, { create: true, exclusive: false }, onDirectorySuccess, onDirectoryFail); // creating folder in sdcard

			var fp = directoryEntry.toURL(); // Returns Fulpath of local directory

			fp = fp + folderName + "/" + nameFile;
			fp3 = "/" + folderName + "/" + nameFile;

			alert('fp ' + fp);
			alert('fp3 ' + fp3);

			var reader = new FileReader();
			var fileSource = fp3;

			reader.onloadend = function(evt) {

				if(evt.target.result == null) {
				  alert('no existe');
				} else {
					alert('si existe');
				}
			};

			// We are going to check if the file exists
			reader.readAsDataURL(fileSource);

			//fileSystem.root.getFile(fp3, {create: false, exclusive: false}, function(){alert('existe')}, onError);
				/* function playExistingFile(fp){
					alert('existe audio '+fp);
					playAudio(fp.toNativeURL());
				},
				function downloadFile(){
					alert('descargar'); */
					/* var fileTransfer = new FileTransfer();
					fileTransfer.download(
						file,
						fp,
						function(theFile) {
							alert("download complete: " + theFile.toURI());
							//playAudio(theFile.toNativeURL());
						},
						function(error) {
							alert("download error source " + error.source);
							alert("download error target " + error.target);
							alert("upload error code: " + error.code);
						}
					); */
				/* } */

    }, onError);
};

function onDirectorySuccess(parent) {
    // Directory created successfuly
	alert('folder created');
}

function onDirectoryFail(error) {
    //Error while creating directory
    alert("Unable to create new directory: " + error.code);
}

 function playAudio(src) {
            // Create Media object from src
			alert(src);
	my_media = new Media(src, onSuccess, onError);

	// Play audio
	my_media.play();

}

function onSuccess() {
	alert("playAudio():Audio Success");
}

// onError Callback
//
function onError(error) {
	alert('code: '    + error.code    + '\n' +
		  'message: ' + error.message + '\n');
}
	<commit_msg>asdas<commit_after>	var map;
	var myLatlng;
	function initProfile() {

			var showTab = jQuery.getQuery('tab');
			switch(showTab){
				case 'person':
					showPerson(true);
					break;
				case 'story':
					showStory(true);
					break;
				case 'place':
				default:
					showPlace(true);
					break;
			}

			var styles = [
							{
								"elementType": "labels.icon",
								"stylers": [
								  { "visibility": "off" }
								]
							  },
							{
								"elementType": "geometry.stroke",
								"stylers": [
								  { "color": "#343434" }
								]
							  },
							{
								"elementType": "geometry.fill",
								"stylers": [
								  { "color": "#232323" }
								]
							  },
							  {
								"featureType": "landscape",
								"elementType": "geometry.fill",
								"stylers": [
								  { "color": "#232323" }
								]
							  },{
								"featureType": "road.local",
								"elementType": "geometry.stroke",
								"stylers": [
								  { "color": "#313131" }
								]
							  },{
								"featureType": "road.local",
								"elementType": "geometry.fill",
								"stylers": [
								  { "color": "#313131" }
								]
							  },{
								"featureType": "road.arterial",
								"elementType": "geometry.fill",
								"stylers": [
								  { "color": "#121212" }
								]
							  },{
								"featureType": "road.arterial",
								"elementType": "geometry.stroke",
								"stylers": [
								  { "color": "#121212" }
								]
							  },{
								"featureType": "water",
								"elementType": "geometry.fill",
								"stylers": [
								  { "color": "#292929" }
								]
							  },{
								"featureType": "poi",
								"stylers": [
								  { "visibility": "off" }
								]
							  },{
								"featureType": "transit",
								"stylers": [
								  { "visibility": "off" }
								]
							  },{
								"featureType": "road.local",
								"elementType": "labels.text",
								"stylers": [
								  { "visibility": "off" }
								]
							  },{
								"featureType": "road.highway",
								"elementType": "geometry.fill",
								"stylers": [
								  { "color": "#565656" }
								]
							  },{
								"featureType": "road.highway",
								"elementType": "labels",
								"stylers": [
								  { "visibility": "off" }
								]
							  },{
								"featureType": "road.highway",
								"elementType": "geometry",
								"stylers": [
								  { "color": "#565656" }
								]
							  },{

								"elementType": "labels.text.stroke",
								"stylers": [
								  { "color": "#111111" }
								]
							  },{
								"featureType": "administrative",
								"elementType": "labels.text.stroke",
								"stylers": [
								  { "color": "#333333" }
								]
							  },{
								"featureType": "administrative",
								"elementType": "labels.text.fill",
								"stylers": [
								  { "color": "#808080" }
								]
							  },
							  {
								"featureType": "landscape.man_made",
								"stylers": [
								  { "visibility": "off" }
								]
							  }
							];
			var styledMap = new google.maps.StyledMapType(styles,{name: "Styled Map"});

			var itemid = jQuery.getQuery('itemid');
			jQuery.getJSON( "http://miflamencoplace.com/rpc/get_profile.php?itemid="+itemid, function( data ) {
				fillProfile(data);
				placeLatlng = new google.maps.LatLng(data.lat, data.long);
				var mapOptions = {
					zoom: 14,
					disableDefaultUI: true,
					center: placeLatlng,
					scrollwheel: false,
					draggable: false
				};
				map = new google.maps.Map(document.getElementById('map-canvas'),mapOptions);
				map.mapTypes.set("map_style",styledMap);
				map.setMapTypeId("map_style");
				var vpw = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);
				var sfx = (vpw > 1024)?'hd':'';
				var marker = new google.maps.Marker({
					position: placeLatlng,
					map: map,
					title: data.title,
					icon: '../img/markers/'+sfx+data.catid+'.png'
				});

			});
	}

	function fillProfile(data){
		$('#place').css('background',' url(../img/overlay.png) repeat,url(http://miflamencoplace.com'+data.img+') no-repeat center top')
		.css('background-size','auto,cover');
		$('#place .title').html(data.title);
		$('#place .author').html('By '+data.personname);
		$('#place .personface img').attr('src','http://miflamencoplace.com'+data.personface);
		if (langid == 'en'){
			$('#place .introtext').html(data.placeintrotexten);
			$('#place .fulltext').html(data.placefulltexten);
			$('#person .authortext').html(data.persontexten);
			if (data.audioen != null){
				$('#story .downloada').click(function(){manageFile('http://miflamencoplace.com/media/k2/attachments/'+data.audioen, data.audioen )});
			}else{
				$('#story .downloada').hide();
			}
		} else {
			$('#place .introtext').html(data.placeintrotext);
			$('#place .fulltext').html(data.placefulltext);
			$('#person .authortext').html(data.persontext);
			if (data.audioes != null){
				$('#story .downloada').click(function(){manageFile('http://miflamencoplace.com/media/k2/attachments/'+data.audioes,data.audioes )});
			}else{
				$('#story .downloada').hide();
			}
		}
		$('#person').css('background','url(http://miflamencoplace.com/media/k2/items/cache/'+data.personpicture+') no-repeat center top');
		$('#person .authorname').html(data.personname);
		$('#story .placetitle').html(data.title);
		$('#story .persontitle').html('By '+data.personname);
		$('#story .right img').attr('src','http://miflamencoplace.com'+data.img);
		$('#story .authorname').html(data.personname);
		$('#story #onyoutube').attr('href',data.onyoutube);
		var galContent = '';
		data.placegallery.forEach(function(galpic) {
			galContent += '';
		});
		$('#place .gallery').html(galContent);
	}

	function zoomPicture(picture){
		$('#zoom').css('background-image','url('+picture+')');
		$('.md-modal').removeClass('md-hide');
		return false;
	}

	function closeZoom(){
		$('.md-modal').addClass('md-hide');
		$('#zoom').css('background-image','');
	}

	function toggleFilter(){
		if (jQuery('#filter').hasClass('open')) {
			jQuery('#filteropts').slideUp('fast');
			jQuery('#filter').removeClass('open');
		} else {
			jQuery('#filteropts').slideDown();
			jQuery('#filter').addClass('open');
		}
		return false;
	}

(function($){
    $.getQuery = function( query ) {
        query = query.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
        var expr = "[\\?&]"+query+"=([^&#]*)";
        var regex = new RegExp( expr );
        var results = regex.exec( window.location.href );
        if( results !== null ) {
            return results[1];
            return decodeURIComponent(results[1].replace(/\+/g, " "));
        } else {
            return false;
        }
    };
})(jQuery);

	function showPlace(open){

		jQuery('#person').fadeOut('fast');
		jQuery('#story').fadeOut('fast');
		jQuery('#place').fadeIn('slow');
		jQuery('#filteropts a').show();
		jQuery('#filteropts .place').hide();
		if (!open){
			toggleFilter();
		}
		return false;
	}
	function showPerson(open){

		jQuery('#story').fadeOut('fast');
		jQuery('#place').fadeOut('fast');
		jQuery('#person').fadeIn('slow');
		jQuery('#filteropts a').show();
		jQuery('#filteropts .person').hide();
		if (!open){
			toggleFilter();
		}
		return false;
	}
	function showStory(open){

		jQuery('#person').fadeOut('fast');
		jQuery('#place').fadeOut('fast');
		jQuery('#story').fadeIn('slow');
		jQuery('#filteropts a').show();
		jQuery('#filteropts .story').hide();
		if (!open){
			toggleFilter();
		}
		return false;
	}

	function isDownloadedFile()
	{
		entry.getFile("newFile.txt", {create: true, exclusive: false}, success, fail);

		return false;
	}

function manageFile(file, nameFile){

window.requestFileSystem(LocalFileSystem.PERSISTENT, 0,
    function onFileSystemSuccess(fileSystem) {
			var folderName = 'miflamencoplace'
			var directoryEntry = fileSystem.root; // to get root path of directory
			directoryEntry.getDirectory(folderName, { create: true, exclusive: false }, onDirectorySuccess, onDirectoryFail); // creating folder in sdcard

			var fp = directoryEntry.toURL(); // Returns Fulpath of local directory

			fp = fp + folderName + "/" + nameFile;
			fp3 = "/" + folderName + "/" + nameFile;

			alert('fp ' + fp);
			alert('fp3 ' + fp3);

			var reader = new FileReader();

			reader.onloadend = function(evt) {

				if(evt.target.result == null) {
				  alert('no existe');
				} else {
					alert('si existe');
				}
			};

			// We are going to check if the file exists
			reader.readAsDataURL(fp);

			//fileSystem.root.getFile(fp3, {create: false, exclusive: false}, function(){alert('existe')}, onError);
				/* function playExistingFile(fp){
					alert('existe audio '+fp);
					playAudio(fp.toNativeURL());
				},
				function downloadFile(){
					alert('descargar'); */
					/* var fileTransfer = new FileTransfer();
					fileTransfer.download(
						file,
						fp,
						function(theFile) {
							alert("download complete: " + theFile.toURI());
							//playAudio(theFile.toNativeURL());
						},
						function(error) {
							alert("download error source " + error.source);
							alert("download error target " + error.target);
							alert("upload error code: " + error.code);
						}
					); */
				/* } */

    }, onError);
};

function onDirectorySuccess(parent) {
    // Directory created successfuly
	alert('folder created');
}

function onDirectoryFail(error) {
    //Error while creating directory
    alert("Unable to create new directory: " + error.code);
}

 function playAudio(src) {
            // Create Media object from src
			alert(src);
	my_media = new Media(src, onSuccess, onError);

	// Play audio
	my_media.play();

}

function onSuccess() {
	alert("playAudio():Audio Success");
}

// onError Callback
//
function onError(error) {
	alert('code: '    + error.code    + '\n' +
		  'message: ' + error.message + '\n');
}
	<|endoftext|>


<commit_before>// Events
var E_ML_AVAILABLE = 'mirrorlink_available',
    // CERTIFICATION EVENTS
    E_ML_CERTIFICATION_STATUS_CHANGE = 'mirrorlink_certification_status_changed',
    // CONNECTION EVENTS
    E_ML_CONNECTION_AUDIO_CHANGE = 'mirrorlink_connection_audio_changed',
    E_ML_CONNECTION_REMOTE_DISPLAY_CHANGE = 'mirrorlink_connection_remote_display_changed',
    E_ML_CONNECTION_SESSION_CHANGE = 'mirrorlink_connection_session_changed',
    // CONTEXT EVENTS

    // ERRORS
    E_ML_ERR_SERVICE_CONNECTION_FAILED = 'mirrorlink_error_service_connection_failed';

// Event manager.
var cordovaEventManager = {
    callbacks_stacks:{},
    on: function( event, callback ){
        if( !this.callbacks_stacks[event] ){
            this.callbacks_stacks[event] = [callback];
        }
        else{
            this.callbacks_stacks[event].push(callback);
        }
        return this;
    },
    off: function( event, callback){
        if( !callback && this.callbacks_stacks[event] ){
            this.callbacks_stacks[event].length = 0;
        }
        else if( this.callbacks_stacks[event] && callback ){
            var i = this.callbacks_stacks[event].indexOf(callback);
            if( i !== -1 ){
                this.callbacks_stacks[event].splice(i,1);
            }
        }
        return this;
    },
    emit: function( event, datas){
        if( this.callbacks_stacks[event] ){
            this.callbacks_stacks[event].forEach(function(callback){
                callback( datas );
            });
        }
        return this;
    },
    service_listeners:{},
    createServiceListener: function( event, cordovaService, cordovaAction, cordovaParams, onError){
        if( !this.service_listeners[event] || force ){
            this.service_listeners[event] = function( datas ){
                cordovaEventManager.emit(event, datas);
            };
            cordova.exec(this.service_listeners[event], onError, cordovaService, cordovaAction, cordovaParams||[]);
        }
        return this;
    }
};

var mirrorlink = {
    certification:{},
    context:{},
    dataservices:{},
    deviceinfo:{},
    devicestatus:{},
    display:{},
    eventmapping:{},
    notification:{}
};

/**
 * Mirrorlink plugin status
 * {boolean} true if mirrorlink plugin is connected to mirrorlink android service.
 */
mirrorlink.is_available = false;

/**
 * Enable mirrorlink plugin ( connect your app to mirrorlink android service )
 * @param {function} callback Callback executed when mirrorlink plugin connect to mirrorlink android service.
 * @param {function} err Callback executed when mirrorlink plugin failed to connect.
 */
mirrorlink.enable = function( callback, err){
    if( typeof callback === 'function' ){
        if( mirrorlink.is_available ){
            return callback();
        }
        cordova.exec(function(){ mirrolink.is_available=true; callback();}, err||function(){}, 'Api', 'connect');
    }
};

//-------- CERTIFICATION SERVICE -----------//
/**
 * Listen when then application certification status change.
 * The application would receive this callback if, for example, the certification
 * status changes when the certificate is revoked.
 * @param {function} callback Function to execute when certification status changes.
 * @param {function} err Function executed if service failed to bind listener to event.
 */
mirrorlink.certification.onStatusChanged = function( callback, err ){
    if( typeof callback === 'function' && typeof err === 'function' ){
        cordovaEventManager
            .createServiceListener(E_ML_CERTIFICATION_STATUS_CHANGE,'Certification','onCertificationStatusChanged',err)
            .on(E_ML_CERTIFICATION_STATUS_CHANGE, callback);
    }
};

/**
 * Remove listeners from "mirrorlink_certification_status_changed" event.
 * @param {function|undefined} callback Callback you want to stop to listen to event. If 'callback'
 * is undefined, it removes all the event listeners.
 */
mirrorlink.certification.offStatusChanged = function( callback ){
    cordovaEventManager.off(E_ML_CERTIFICATION_STATUS_CHANGE, callback);
};

/**
 * Get Application Certification Information.
 * @param  {string} entity Name of the certifying entity
 * @param {function} callback Function executed with application certification
 * information bundle {entity:string,certified:boolean,restricted:string,nonrestricted:string}
 * or null if the application isn't certified or the entity is not part of the
 * list of certifying entities for the application.
 * @param {function} err Executed if service failed to get information.
 */
mirrolink.certification.getInformation = function( entity, callback, err){
    if( typeof callback === 'function' && typeof err === 'function' && typeof entity === 'string' ){
        cordova.exec(callback, err, 'Certification', 'getApplicationCertificationInformation', [entity]);
    }
};

/**
 * Get Application Certifying Entities.
 * @param {function} callback Function executed with comma-separated list of
 * certifying entities, which certified the application,
 * @param {function} err Executed if service failed to get certifying entities.
 */
mirrorlink.certification.getEntities = function( callback, err){
    if( typeof callback === 'function' && typeof err === 'function' ){
        cordova.exec(callback, err||function(){}, 'Certification', 'getApplicationCertifyingEntities', []);
    }
};

/**
 * Get Application Certification Status.
 * @param {function} callback Function executed with a
 * bundle: {has_valid_certificate:boolean,advertised_as_certifiedapp:boolean}
 * @param {function} err Executed if service failed to get certifying entities.
 */
mirrorlink.certification.getStatus = function( callback, err){
    if( typeof callback === 'function' && typeof err === 'function' ){
        cordova.exec(callback, err, 'Certification', 'getApplicationCertificationStatus', []);
    }
};

/**
 * Stop using mirrorlink certification manager.
 * The application will not receive any more callbacks from certification manager;
 * Listeners are keeped in memory.
 * /!\ To reactivate the manager,  call any method of the manager.
 * @param {function} callback Executed when manager successfully disabled.
 * @param {function} err Executed if mirrorlink failed to disabled certification manager.
 */
mirrorlink.certification.disable = function(callback, err){
    if( typeof callback === 'function' && typeof err === 'function' ){
        cordova.exec(callback, err, 'Certification', 'unregister', []);
    }
};

//-------- CONNECTION SERVICE -----------//

/**
 * Listen when the audio connections changed.
 * @param {function} callback Function to execute when audio connection changes with audioConnections Bundle.
 * @param {function} err Function executed if service failed to bind listener to event.
 */
mirrorlink.connection.onAudioChanged = function( callback, err ){
    if( typeof callback === 'function' && typeof err === 'function' ){
        cordovaEventManager
            .createServiceListener(E_ML_CONNECTION_AUDIO_CHANGE,'Connection','onAudioConnectionsChanged',err)
            .on(E_ML_CONNECTION_AUDIO_CHANGE, callback);
    }
};
/**
 * Listen when the remote display connections changed.
 * @param {function} callback Function to execute when audio connection changes
 * with remoteDisplayConnection integer (see {@link Defs.RemoteDisplayConnection}).
 * @param {function} err Function executed if service failed to bind listener to event.
*/
mirrorlink.connection.onRemoteDisplayChanged = function( callback, err ){
    if( typeof callback === 'function' && typeof err === 'function' ){
        cordovaEventManager
            .createServiceListener(E_ML_CONNECTION_REMOTE_DISPLAY_CHANGE,'Connection','onRemoteDisplayConnectionChanged',err)
            .on(E_ML_CONNECTION_REMOTE_DISPLAY_CHANGE, callback);
    }
};

/**
 * Get established audio connections within mirrorlink session.
 * @param {function} callback Executed with a bundle containing the status of
 * the audio connections available (see {@link Defs.AudioConnections}).
 * @param {function} err Executed if it failed to get audio connections.
 */
mirrorlink.connection.getAudio = function( callback, err){
    if( typeof callback === 'function' && typeof err === 'function' ){
        cordova.exec(callback, err, 'Connection', 'getAudioConnections', []);
    }
};

/**
 * Get established remote display connections within mirrorlink session.
 * @param {function} callback Executed with value containing the status of the remote
 * display connections available (see {@link Defs.RemoteDisplayConnection}).
 * @param {function} err Executed if it failed to get audio connections.
 */
mirrorlink.connection.getRemoteDisplay = function( callback, err){
    if( typeof callback === 'function' && typeof err === 'function' ){
        cordova.exec(callback, err, 'Connection', 'getRemoteDisplayConnections', []);
    }
};

/**
 * Indicates whether a MirrorLink session is currently established.
 * A MirrorLink is considered established if a ClientProfile has been
 * set on the MirrorLink Server for the current tethering session.
 *
 * /!\ The application MUST use this call and its event
 * listener 'mirrorlink.connection.onSessionChanged' to determine whether a
 * MirrorLink session is established. MirrorLink applications SHOULD use
 * other Common API modules only while a MirrorLink Session is running.
 * MirrorLink Servers MUST have the Common API modules available at all
 * times.
 *
 * @param {function} callback Executed with boolean.
 * @param {function} err Executed if it failed to get session status.
 */
mirrorlink.connection.isSessionEstablished = function( callback, err){
    if( typeof callback === 'function' && typeof err === 'function' ){
        cordova.exec(callback, err, 'Connection', 'isMirrorLinkSessionEstablished', []);
    }
};

/**
 * Listen when the mirrorLink session status has changed.
 *
 * /!\ The application MUST use this listener and its equivalent
 * getter 'mirrorlink.connection.isSessionEstablished' to determine whether a
 * MirrorLink session is established. MirrorLink applications SHOULD use
 * other Common API modules only while a MirrorLink Session is running.
 * MirrorLink Servers MUST have the Common API modules available at all
 * times.
 *
 * @param {function} callback Function executed with mirrorlink session status
 * when session status changed.
 * @param {function} err Function executed if service failed to bind listener to event.
*/
mirrorlink.connection.onSessionChanged = function( callback, err ){
    if( typeof callback === 'function' && typeof err === 'function'){
        cordovaEventManager
            .createServiceListener(E_ML_CONNECTION_SESSION_CHANGE,'Connection','onMirrorLinkSessionChanged',err)
            .on(E_ML_CONNECTION_SESSION_CHANGE, callback);
    }
};

/**
 * Stop using mirrorlink connection manager.
 * The application will not receive any more callbacks from connection manager;
 * Listeners are keeped in memory.
 * /!\ To reactivate the manager,  call any method of the manager.
 * @param {function} callback . Executed when manager successfully disabled.
 * @param {function} err . Executed if mirrorlink failed to disabled connection manager.
 */
mirrorlink.certification.disable = function(callback, err){
    if( typeof callback === 'function' && typeof err === 'function' ){
        cordova.exec(callback, err, 'Connection', 'unregister', []);
    }
};

module.exports = mirrolink;

<commit_msg>Dumb error on connection disable function<commit_after>// Events
var E_ML_AVAILABLE = 'mirrorlink_available',
    // CERTIFICATION EVENTS
    E_ML_CERTIFICATION_STATUS_CHANGE = 'mirrorlink_certification_status_changed',
    // CONNECTION EVENTS
    E_ML_CONNECTION_AUDIO_CHANGE = 'mirrorlink_connection_audio_changed',
    E_ML_CONNECTION_REMOTE_DISPLAY_CHANGE = 'mirrorlink_connection_remote_display_changed',
    E_ML_CONNECTION_SESSION_CHANGE = 'mirrorlink_connection_session_changed',
    // CONTEXT EVENTS

    // ERRORS
    E_ML_ERR_SERVICE_CONNECTION_FAILED = 'mirrorlink_error_service_connection_failed';

// Event manager.
var cordovaEventManager = {
    callbacks_stacks:{},
    on: function( event, callback ){
        if( !this.callbacks_stacks[event] ){
            this.callbacks_stacks[event] = [callback];
        }
        else{
            this.callbacks_stacks[event].push(callback);
        }
        return this;
    },
    off: function( event, callback){
        if( !callback && this.callbacks_stacks[event] ){
            this.callbacks_stacks[event].length = 0;
        }
        else if( this.callbacks_stacks[event] && callback ){
            var i = this.callbacks_stacks[event].indexOf(callback);
            if( i !== -1 ){
                this.callbacks_stacks[event].splice(i,1);
            }
        }
        return this;
    },
    emit: function( event, datas){
        if( this.callbacks_stacks[event] ){
            this.callbacks_stacks[event].forEach(function(callback){
                callback( datas );
            });
        }
        return this;
    },
    service_listeners:{},
    createServiceListener: function( event, cordovaService, cordovaAction, cordovaParams, onError){
        if( !this.service_listeners[event] || force ){
            this.service_listeners[event] = function( datas ){
                cordovaEventManager.emit(event, datas);
            };
            cordova.exec(this.service_listeners[event], onError, cordovaService, cordovaAction, cordovaParams||[]);
        }
        return this;
    }
};

var mirrorlink = {
    certification:{},
    context:{},
    dataservices:{},
    deviceinfo:{},
    devicestatus:{},
    display:{},
    eventmapping:{},
    notification:{}
};

/**
 * Mirrorlink plugin status
 * {boolean} true if mirrorlink plugin is connected to mirrorlink android service.
 */
mirrorlink.is_available = false;

/**
 * Enable mirrorlink plugin ( connect your app to mirrorlink android service )
 * @param {function} callback Callback executed when mirrorlink plugin connect to mirrorlink android service.
 * @param {function} err Callback executed when mirrorlink plugin failed to connect.
 */
mirrorlink.enable = function( callback, err){
    if( typeof callback === 'function' ){
        if( mirrorlink.is_available ){
            return callback();
        }
        cordova.exec(function(){ mirrolink.is_available=true; callback();}, err||function(){}, 'Api', 'connect');
    }
};

//-------- CERTIFICATION SERVICE -----------//
/**
 * Listen when then application certification status change.
 * The application would receive this callback if, for example, the certification
 * status changes when the certificate is revoked.
 * @param {function} callback Function to execute when certification status changes.
 * @param {function} err Function executed if service failed to bind listener to event.
 */
mirrorlink.certification.onStatusChanged = function( callback, err ){
    if( typeof callback === 'function' && typeof err === 'function' ){
        cordovaEventManager
            .createServiceListener(E_ML_CERTIFICATION_STATUS_CHANGE,'Certification','onCertificationStatusChanged',err)
            .on(E_ML_CERTIFICATION_STATUS_CHANGE, callback);
    }
};

/**
 * Remove listeners from "mirrorlink_certification_status_changed" event.
 * @param {function|undefined} callback Callback you want to stop to listen to event. If 'callback'
 * is undefined, it removes all the event listeners.
 */
mirrorlink.certification.offStatusChanged = function( callback ){
    cordovaEventManager.off(E_ML_CERTIFICATION_STATUS_CHANGE, callback);
};

/**
 * Get Application Certification Information.
 * @param  {string} entity Name of the certifying entity
 * @param {function} callback Function executed with application certification
 * information bundle {entity:string,certified:boolean,restricted:string,nonrestricted:string}
 * or null if the application isn't certified or the entity is not part of the
 * list of certifying entities for the application.
 * @param {function} err Executed if service failed to get information.
 */
mirrolink.certification.getInformation = function( entity, callback, err){
    if( typeof callback === 'function' && typeof err === 'function' && typeof entity === 'string' ){
        cordova.exec(callback, err, 'Certification', 'getApplicationCertificationInformation', [entity]);
    }
};

/**
 * Get Application Certifying Entities.
 * @param {function} callback Function executed with comma-separated list of
 * certifying entities, which certified the application,
 * @param {function} err Executed if service failed to get certifying entities.
 */
mirrorlink.certification.getEntities = function( callback, err){
    if( typeof callback === 'function' && typeof err === 'function' ){
        cordova.exec(callback, err||function(){}, 'Certification', 'getApplicationCertifyingEntities', []);
    }
};

/**
 * Get Application Certification Status.
 * @param {function} callback Function executed with a
 * bundle: {has_valid_certificate:boolean,advertised_as_certifiedapp:boolean}
 * @param {function} err Executed if service failed to get certifying entities.
 */
mirrorlink.certification.getStatus = function( callback, err){
    if( typeof callback === 'function' && typeof err === 'function' ){
        cordova.exec(callback, err, 'Certification', 'getApplicationCertificationStatus', []);
    }
};

/**
 * Stop using mirrorlink certification manager.
 * The application will not receive any more callbacks from certification manager;
 * Listeners are keeped in memory.
 * /!\ To reactivate the manager,  call any method of the manager.
 * @param {function} callback Executed when manager successfully disabled.
 * @param {function} err Executed if mirrorlink failed to disabled certification manager.
 */
mirrorlink.certification.disable = function(callback, err){
    if( typeof callback === 'function' && typeof err === 'function' ){
        cordova.exec(callback, err, 'Certification', 'unregister', []);
    }
};

//-------- CONNECTION SERVICE -----------//

/**
 * Listen when the audio connections changed.
 * @param {function} callback Function to execute when audio connection changes with audioConnections Bundle.
 * @param {function} err Function executed if service failed to bind listener to event.
 */
mirrorlink.connection.onAudioChanged = function( callback, err ){
    if( typeof callback === 'function' && typeof err === 'function' ){
        cordovaEventManager
            .createServiceListener(E_ML_CONNECTION_AUDIO_CHANGE,'Connection','onAudioConnectionsChanged',err)
            .on(E_ML_CONNECTION_AUDIO_CHANGE, callback);
    }
};
/**
 * Listen when the remote display connections changed.
 * @param {function} callback Function to execute when audio connection changes
 * with remoteDisplayConnection integer (see {@link Defs.RemoteDisplayConnection}).
 * @param {function} err Function executed if service failed to bind listener to event.
*/
mirrorlink.connection.onRemoteDisplayChanged = function( callback, err ){
    if( typeof callback === 'function' && typeof err === 'function' ){
        cordovaEventManager
            .createServiceListener(E_ML_CONNECTION_REMOTE_DISPLAY_CHANGE,'Connection','onRemoteDisplayConnectionChanged',err)
            .on(E_ML_CONNECTION_REMOTE_DISPLAY_CHANGE, callback);
    }
};

/**
 * Get established audio connections within mirrorlink session.
 * @param {function} callback Executed with a bundle containing the status of
 * the audio connections available (see {@link Defs.AudioConnections}).
 * @param {function} err Executed if it failed to get audio connections.
 */
mirrorlink.connection.getAudio = function( callback, err){
    if( typeof callback === 'function' && typeof err === 'function' ){
        cordova.exec(callback, err, 'Connection', 'getAudioConnections', []);
    }
};

/**
 * Get established remote display connections within mirrorlink session.
 * @param {function} callback Executed with value containing the status of the remote
 * display connections available (see {@link Defs.RemoteDisplayConnection}).
 * @param {function} err Executed if it failed to get audio connections.
 */
mirrorlink.connection.getRemoteDisplay = function( callback, err){
    if( typeof callback === 'function' && typeof err === 'function' ){
        cordova.exec(callback, err, 'Connection', 'getRemoteDisplayConnections', []);
    }
};

/**
 * Indicates whether a MirrorLink session is currently established.
 * A MirrorLink is considered established if a ClientProfile has been
 * set on the MirrorLink Server for the current tethering session.
 *
 * /!\ The application MUST use this call and its event
 * listener 'mirrorlink.connection.onSessionChanged' to determine whether a
 * MirrorLink session is established. MirrorLink applications SHOULD use
 * other Common API modules only while a MirrorLink Session is running.
 * MirrorLink Servers MUST have the Common API modules available at all
 * times.
 *
 * @param {function} callback Executed with boolean.
 * @param {function} err Executed if it failed to get session status.
 */
mirrorlink.connection.isSessionEstablished = function( callback, err){
    if( typeof callback === 'function' && typeof err === 'function' ){
        cordova.exec(callback, err, 'Connection', 'isMirrorLinkSessionEstablished', []);
    }
};

/**
 * Listen when the mirrorLink session status has changed.
 *
 * /!\ The application MUST use this listener and its equivalent
 * getter 'mirrorlink.connection.isSessionEstablished' to determine whether a
 * MirrorLink session is established. MirrorLink applications SHOULD use
 * other Common API modules only while a MirrorLink Session is running.
 * MirrorLink Servers MUST have the Common API modules available at all
 * times.
 *
 * @param {function} callback Function executed with mirrorlink session status
 * when session status changed.
 * @param {function} err Function executed if service failed to bind listener to event.
*/
mirrorlink.connection.onSessionChanged = function( callback, err ){
    if( typeof callback === 'function' && typeof err === 'function'){
        cordovaEventManager
            .createServiceListener(E_ML_CONNECTION_SESSION_CHANGE,'Connection','onMirrorLinkSessionChanged',err)
            .on(E_ML_CONNECTION_SESSION_CHANGE, callback);
    }
};

/**
 * Stop using mirrorlink connection manager.
 * The application will not receive any more callbacks from connection manager;
 * Listeners are keeped in memory.
 * /!\ To reactivate the manager,  call any method of the manager.
 * @param {function} callback . Executed when manager successfully disabled.
 * @param {function} err . Executed if mirrorlink failed to disabled connection manager.
 */
mirrorlink.connection.disable = function(callback, err){
    if( typeof callback === 'function' && typeof err === 'function' ){
        cordova.exec(callback, err, 'Connection', 'unregister', []);
    }
};

//-------- CONTEXT SERVICE -----------//

module.exports = mirrolink;

<|endoftext|>


<commit_before>var cordova_exec = require('cordova/exec');
function pluginInit() {
  //-------------------------------------------------------------
  // In some older browsers do not implement these methods.
  // For example, Android 4.4 does not have Array.map()
  //
  // But this plugin needs them.
  // That's why if the browser does not have it, implement it.
  //-------------------------------------------------------------
  if (typeof Array.prototype.forEach !== "function") {
    (function() {
      Array.prototype.forEach = function(fn, thisArg) {
        thisArg = thisArg || this;
        for (var i = 0; i < this.length; i++) {
          fn.call(thisArg, this[i], i, this);
        }
      };
    })();
  }
  if (typeof Array.prototype.filter !== "function") {
    (function() {
      Array.prototype.filter = function(fn, thisArg) {
        thisArg = thisArg || this;
        var results = [];
        for (var i = 0; i < this.length; i++) {
          if (fn.call(thisArg, this[i], i, this) === true) {
            results.push(this[i]);
          }
        }
        return results;
      };
    })();
  }
  if (typeof Array.prototype.map !== "function") {
    (function() {
      Array.prototype.map = function(fn, thisArg) {
        thisArg = thisArg || this;
        var results = [];
        for (var i = 0; i < this.length; i++) {
          results.push(fn.call(thisArg, this[i], i, this));
        }
        return results;
      };
    })();
  }
  /*****************************************************************************
   * To prevent strange things happen,
   * disable the changing of viewport zoom level by double clicking.
   * This code has to run before the device ready event.
   *****************************************************************************/
  var viewportTag = null;
  var metaTags = document.getElementsByTagName('meta');
  for (var i = 0; i < metaTags.length; i++) {
      if (metaTags[i].getAttribute('name') === "viewport") {
          viewportTag = metaTags[i];
          break;
      }
  }
  if (!viewportTag) {
      viewportTag = document.createElement("meta");
      viewportTag.setAttribute('name', 'viewport');
  }

  var viewportTagContent = 'width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no';

  // Detect if iOS device
  if (/(iPhone|iPod|iPad)/i.test(window.navigator.userAgent)) {
    // Get iOS major version
    var iosVersion = parseInt((window.navigator.userAgent).match(/OS (\d+)_(\d+)_?(\d+)? like Mac OS X/i)[1]);
    // Detect if device is running >iOS 11
    // iOS 11's UIWebView and WKWebView changes the viewport behaviour to render viewport without the status bar. Need to override with "viewport-fit: cover" to include the status bar.
    if (iosVersion >= 11) {
      viewportTagContent += ', viewport-fit=cover';
    }
  }

  // Update viewport tag attribute
  viewportTag.setAttribute('content', viewportTagContent);

  /*****************************************************************************
   * Prevent background, background-color, background-image properties
   *****************************************************************************/
  var cssAdjuster = document.createElement("style");
  cssAdjuster.setAttribute("type", "text/css");
  cssAdjuster.innerText = [
    "html, body, ._gmaps_cdv_ {",
    "   background-image: url() !important;",
    "   background: rgba(0,0,0,0) url() !important;",
    "   background-color: rgba(0,0,0,0) !important;",
    "}",
    "._gmaps_cdv_ .nav-decor {",
    "   background-color: rgba(0,0,0,0) !important;",
    "   background: rgba(0,0,0,0) !important;",
    "   display:none !important;",
    "}",
    ".framework7-root .page-previous {",
    "   display:none !important;",
    "}"
  ].join("");
  document.head.appendChild(cssAdjuster);

  // I guess no longer necessary this code at 2018/March
  // //----------------------------------------------
  // // Set transparent mandatory for older browser
  // // http://stackoverflow.com/a/3485654/697856
  // //----------------------------------------------
  // if(document.body){
  //   document.body.style.backgroundColor = "rgba(0,0,0,0)";
  //   //document.body.style.display='none';
  //   document.body.offsetHeight;
  //   //document.body.style.display='';
  // }

  //--------------------------------------------
  // Hook the backbutton of Android action
  //--------------------------------------------
  var anotherBackbuttonHandler = null;
  function onBackButton(e) {

    // Check DOM tree for new page
    cordova.fireDocumentEvent("plugin_touch", {
      force: true
    });

    if (anotherBackbuttonHandler) {
      // anotherBackbuttonHandler must handle the page moving transaction.
      // The plugin does not take care anymore if another callback is registered.
      anotherBackbuttonHandler(e);
    } else {
      cordova_exec(null, null, 'CordovaGoogleMaps', 'backHistory', []);
    }
  }

  document.addEventListener("backbutton", onBackButton);

  var _org_addEventListener = document.addEventListener;
  var _org_removeEventListener = document.removeEventListener;
  document.addEventListener = function(eventName, callback) {
    var args = Array.prototype.slice.call(arguments, 0);
    if (eventName.toLowerCase() !== "backbutton") {
      _org_addEventListener.apply(this, args);
      return;
    }
    if (!anotherBackbuttonHandler) {
      anotherBackbuttonHandler = callback;
    }
  };
  document.removeEventListener = function(eventName, callback) {
    var args = Array.prototype.slice.call(arguments, 0);
    if (eventName.toLowerCase() !== "backbutton") {
      _org_removeEventListener.apply(this, args);
      return;
    }
    if (anotherBackbuttonHandler === callback) {
      anotherBackbuttonHandler = null;
    }
  };

}

module.exports = pluginInit;
<commit_msg>replace iOS userAgent test with browser feature test<commit_after>var cordova_exec = require('cordova/exec');
function pluginInit() {
  //-------------------------------------------------------------
  // In some older browsers do not implement these methods.
  // For example, Android 4.4 does not have Array.map()
  //
  // But this plugin needs them.
  // That's why if the browser does not have it, implement it.
  //-------------------------------------------------------------
  if (typeof Array.prototype.forEach !== "function") {
    (function() {
      Array.prototype.forEach = function(fn, thisArg) {
        thisArg = thisArg || this;
        for (var i = 0; i < this.length; i++) {
          fn.call(thisArg, this[i], i, this);
        }
      };
    })();
  }
  if (typeof Array.prototype.filter !== "function") {
    (function() {
      Array.prototype.filter = function(fn, thisArg) {
        thisArg = thisArg || this;
        var results = [];
        for (var i = 0; i < this.length; i++) {
          if (fn.call(thisArg, this[i], i, this) === true) {
            results.push(this[i]);
          }
        }
        return results;
      };
    })();
  }
  if (typeof Array.prototype.map !== "function") {
    (function() {
      Array.prototype.map = function(fn, thisArg) {
        thisArg = thisArg || this;
        var results = [];
        for (var i = 0; i < this.length; i++) {
          results.push(fn.call(thisArg, this[i], i, this));
        }
        return results;
      };
    })();
  }
  /*****************************************************************************
   * To prevent strange things happen,
   * disable the changing of viewport zoom level by double clicking.
   * This code has to run before the device ready event.
   *****************************************************************************/
  var viewportTag = null;
  var metaTags = document.getElementsByTagName('meta');
  for (var i = 0; i < metaTags.length; i++) {
      if (metaTags[i].getAttribute('name') === "viewport") {
          viewportTag = metaTags[i];
          break;
      }
  }
  if (!viewportTag) {
      viewportTag = document.createElement("meta");
      viewportTag.setAttribute('name', 'viewport');
  }

  var viewportTagContent = 'width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no';

  //
  // Detect support for CSS env() variable
  //
  var envTestDiv = '

';

  document.body.insertAdjacentHTML('afterbegin', envTestDiv);

  var testElement = document.getElementById('envTest');
  var computedStyles = window.getComputedStyle(testElement);
  var testResult = computedStyles.getPropertyValue('margin-top');

  document.body.removeChild(testElement);

  // if browser supports env(), returns a pixel value as string, even if 0px
  if (testResult != '-99px') {
    viewportTagContent += ', viewport-fit=cover';
  }

  // Update viewport tag attribute
  viewportTag.setAttribute('content', viewportTagContent);

  /*****************************************************************************
   * Prevent background, background-color, background-image properties
   *****************************************************************************/
  var cssAdjuster = document.createElement("style");
  cssAdjuster.setAttribute("type", "text/css");
  cssAdjuster.innerText = [
    "html, body, ._gmaps_cdv_ {",
    "   background-image: url() !important;",
    "   background: rgba(0,0,0,0) url() !important;",
    "   background-color: rgba(0,0,0,0) !important;",
    "}",
    "._gmaps_cdv_ .nav-decor {",
    "   background-color: rgba(0,0,0,0) !important;",
    "   background: rgba(0,0,0,0) !important;",
    "   display:none !important;",
    "}",
    ".framework7-root .page-previous {",
    "   display:none !important;",
    "}"
  ].join("");
  document.head.appendChild(cssAdjuster);

  // I guess no longer necessary this code at 2018/March
  // //----------------------------------------------
  // // Set transparent mandatory for older browser
  // // http://stackoverflow.com/a/3485654/697856
  // //----------------------------------------------
  // if(document.body){
  //   document.body.style.backgroundColor = "rgba(0,0,0,0)";
  //   //document.body.style.display='none';
  //   document.body.offsetHeight;
  //   //document.body.style.display='';
  // }

  //--------------------------------------------
  // Hook the backbutton of Android action
  //--------------------------------------------
  var anotherBackbuttonHandler = null;
  function onBackButton(e) {

    // Check DOM tree for new page
    cordova.fireDocumentEvent("plugin_touch", {
      force: true
    });

    if (anotherBackbuttonHandler) {
      // anotherBackbuttonHandler must handle the page moving transaction.
      // The plugin does not take care anymore if another callback is registered.
      anotherBackbuttonHandler(e);
    } else {
      cordova_exec(null, null, 'CordovaGoogleMaps', 'backHistory', []);
    }
  }

  document.addEventListener("backbutton", onBackButton);

  var _org_addEventListener = document.addEventListener;
  var _org_removeEventListener = document.removeEventListener;
  document.addEventListener = function(eventName, callback) {
    var args = Array.prototype.slice.call(arguments, 0);
    if (eventName.toLowerCase() !== "backbutton") {
      _org_addEventListener.apply(this, args);
      return;
    }
    if (!anotherBackbuttonHandler) {
      anotherBackbuttonHandler = callback;
    }
  };
  document.removeEventListener = function(eventName, callback) {
    var args = Array.prototype.slice.call(arguments, 0);
    if (eventName.toLowerCase() !== "backbutton") {
      _org_removeEventListener.apply(this, args);
      return;
    }
    if (anotherBackbuttonHandler === callback) {
      anotherBackbuttonHandler = null;
    }
  };

}

module.exports = pluginInit;
<|endoftext|>