Enabling the past function - fine-uploader

Reading the docs it mentions "also containing the file list" in the paste options for the target element
http://docs.fineuploader.com/integrating/options/fineuploaderbasic.html
What is this? Is there a good example how to implement this? This is what I have so far. #pasteimage is a text box.
Using Chrome 10.6 Do I need to turn it on somewhere in jquery.fineuploader-3.4.1.js
$(document).ready(function(){
var thumbnailuploader = new qq.FineUploader({
element: $('#thumbnail-fine-uploader')[0],
request: {
endpoint: '/Admin/CFC/image-uploader.cfc?method=Upload',
params: {
profileID: '<cfoutput>#profile.ID#</cfoutput>',
profileType:'<cfoutput>#profile.Profile_Type#</cfoutput>',
subDName:'<cfoutput>#DecodeforHTML(profile.Subdomain_Name)#</cfoutput>'
},
},
multiple: true,
validation: {
allowedExtensions: ['jpeg', 'jpg', 'gif', 'png'],
sizeLimit: 102400, // 100 kB = 100 * 1024 bytes
itemLimit: 1,
stopOnFirstInvalidFile: false
},
text: {
uploadButton: "\+ Click or Drop"
},
paste:{
targetElement:$('#pasteimage')
},
callbacks: {
onComplete: function(id, fileName, responseJSON){
if (responseJSON.success) {
$('#thumbnail-fine-uploader').append('<img src="/<cfoutput>#profile.Profile_Type#</cfoutput>/<cfoutput>#profile.ID#</cfoutput>/' + responseJSON.filename + '" alt="' + fileName + '" style="width:120px;height:120px;">');
$('#thumbnail-fine-uploader').append('<br/><b style="color:red;">' + responseJSON.returnedProfileID + '<br/>'+ responseJSON.returnedprofileType+'<br/>'+responseJSON.returnedsubDName+'</b>');
}
}
},
onUpload: function(id, fileName){
$('#file-' + id).addClass('alert-info').html('<img src="/Images/loading.gif" alt="Initializing. Please hold."> ' +
'Initializing ' +
'“' +
fileName +
'”');
},
onProgress: function(id, fileName, loaded, total){
if (loaded < total) {
progress = Math.round(loaded / total * 100) + '% of ' + Math.round(total / 1024) + ' kB';
$('#file-' + id).removeClass('alert-info').html('<img src="/Images/loading.gif" alt="In progress. Please hold."> ' +
'Uploading ' +
'“' +
fileName +
'” ' +
progress);
}
else {
$('#file-' + id).addClass('alert-info').html('<img src="/Images/loading.gif" alt="Saving. Please hold."> ' +
'Saving ' +
'“' +
fileName +
'”');
}
},
})
});

The paste target element can be any container that will receive the pasted image(s). This is where your users will paste any image on their clipboard. There isn't much to demonstrate. Simply create an element in the DOM, preferably one that your users can understand is the location where images can be pasted. Then, set this element as the value of the paste option's targetElement property. You can even use the document as a target, if you want.

Related

TinyMce doesn't call audio_template_callback, but call instead video_template_callback

I am using TinyMce editor with laravel 5.6, and laravel-elfinder. I have to upload audio file, but editor doesn't recognize the audio file, so it render as video format by calling video_template_callback. So I change the editor_config like:
var editor_config = {
selector: "textarea",
plugins: [
"image link lists textcolor imagetools table codesample textpattern media code"
],
video_template_callback: function(data){
console.log('call video');
return '<audio controls>' + '\n<source src="' + data.source1 + '"' + (data.source1mime ? ' type="' + data.source1mime + '"' : '') + ' />\n' + '</audio>';
},
audio_template_callback: function(data) {
console.log('call audio');
return '<audio controls>' + '\n<source src="' + data.source1 + '"' + (data.source1mime ? ' type="' + data.source1mime + '"' : '') + ' />\n' + '</audio>';
},
toolbar: "insertfile undo redo | styleselect | bold italic strikethrough | alignleft aligncenter alignright alignjustify | ltr rtl | bullist numlist outdent indent removeformat formatselect| link image media | emoticons charmap | code codesample | forecolor backcolor",
browser_spellcheck: true,
relative_urls: false,
remove_script_host: false,
media_poster: false,
media_filter_html: false,
file_browser_callback : function(field_name, url, type, win) {
tinymce.activeEditor.windowManager.open({
file: '<?= route('elfinder.tinymce4') ?>',// use an absolute path!
title: 'File Manager',
width: 900,
height: 450,
resizable: 'yes'
}, {
setUrl: function (url) {
win.document.getElementById(field_name).value = url;
}
});
},
setup:function(ed) {
ed.on('change', function(e) {
console.log('the content ', ed.getContent({ format: 'text' }));
});
}
};
[![tinymce.init(editor_config);][1]][1]
when test this setting, console output only "call video".
In the current release of TinyMCE (4.8.1) if you look at the code for the media plugin you would see a section like this:
if (data.type === 'iframe') {
return getIframeHtml(data);
} else if (data.source1mime === 'application/x-shockwave-flash') {
return getFlashHtml(data);
} else if (data.source1mime.indexOf('audio') !== -1) {
return getAudioHtml(data, audioTemplateCallback);
} else if (data.type === 'script') {
return getScriptHtml(data);
} else {
return getVideoHtml(data, videoTemplateCallback);
}
In order for something to get triggered as Audio its mime type needs to contain the string audio. If all the other tests fail its treated as Video so my guess is that the mime type on that file does not include the string audio.

To fetch Latitude Longitude using Kendo-ui in telerik appbuilder

I am using below function to display a map using kendo ui in telerik appbuilder.
As you see, I have assigned static latitude & longitude to this.
Please suggest some way to fetch lat long using kendo ui.
I want to pass the latitude and longitude values to createMap(x,y) function.
function createMap(x,y) {
console.log("createmap");
// console.log("x=" + x + " " + "y=" + y);
var ds = [
{ "shape": "green", "location": [30.667936 ,76.732688] },
];
// 30.710458600000000000 30.657762
// 76.703347099999970000 76.740835
$("#map, #addAddFav").kendoMap({
center: [30.667936, 76.732688],
zoom: 10,
layers: [{
type: "tile",
urlTemplate: "http://#= subdomain #.tile2.opencyclemap.org/transport/#= zoom #/#= x #/#= y #.png",
subdomains: ["a", "b", "c"],
attribution: "© <a href='http://osm.org/copyright'>OpenStreetMap contributors</a>." +
"Tiles courtesy of <a href='http://www.opencyclemap.org/'>Andy Allan</a>"
},
{
type: "marker",
/* dataSource: {
transport: {
read: {
url: "map/store-locations.json",
dataType: "json"
}
}
},*/
// locationField: "latlng",
// titleField: "name"
}
],
markers: ds,
click: onMapMarkerClick,
shapeClick: onShapeClick,
shapeCreated: onShapeCreated
});
}
From the Apache Cordova docs:
navigator.geolocation.getCurrentPosition(onSuccess, onError);
// onSuccess Callback
// This method accepts a Position object, which contains the
// current GPS coordinates
//
var onSuccess = function(position) {
alert('Latitude: ' + position.coords.latitude + '\n' +
'Longitude: ' + position.coords.longitude + '\n' +
'Altitude: ' + position.coords.altitude + '\n' +
'Accuracy: ' + position.coords.accuracy + '\n' +
'Altitude Accuracy: ' + position.coords.altitudeAccuracy + '\n' +
'Heading: ' + position.coords.heading + '\n' +
'Speed: ' + position.coords.speed + '\n' +
'Timestamp: ' + position.timestamp + '\n');
};
// onError Callback receives a PositionError object
//
function onError(error) {
alert('code: ' + error.code + '\n' +
'message: ' + error.message + '\n');
}

How to make XMLHttpRequest work over HTTPS on google chrome?

I researched about this a lot, but couldn't find the magic.
Actually I want to populate a list of city pin code no. using JQuery autocomplete UI. It's a https page. It's working in Firefox but not in Google Chrome. Can anyone help me to resolve this issue. Thanks in Advance.
In the following is my code:
function zipAutoCompletet(prefix) {
jQuery("#" + prefix + "_zip").autocomplete({
source: function(request, response) {
jQuery.ajax({
url: "http://ws.geonames.org/postalCodeSearchJSON",
dataType: "jsonp",
data: {
style: "full",
maxRows: 12,
postalcode_startsWith: request.term
},
success: function(data) {
response(
jQuery.map(data.postalCodes, function(item) {
return {
label:
item.placeName +
(item.adminCode1
? ", " + item.adminCode1
: "") +
", " +
item.postalCode +
", " +
item.countryCode,
value: item.postalCode
};
})
);
jQuery(".ui-autocomplete").css("width", "188px");
}
});
},
minLength: 2,
select: function(event, ui) {
var myString = new String(ui.item.label);
var address = myString.split(",");
jQuery("#" + prefix + "_city").val(address[0]);
jQuery("#" + prefix + "_city").addClass("activated");
jQuery("#" + prefix + "_city").trigger("change");
jQuery("#" + prefix + "_city")
.parents(".row")
.removeClass("error-row");
jQuery("#" + prefix + "_city")
.parents(".row")
.addClass("ok-row");
var countryCode = address[3] ? address[3] : address[2];
countryCode = jQuery.trim(countryCode);
var countryName = jQuery(
"#" +
prefix +
'_country option[value="' +
jQuery.trim(countryCode) +
'"]'
).text();
jQuery("#countryContainer .jqTransformSelectWrapper span").html(
countryName
);
jQuery("#countryContainer .jqTransformSelectWrapper").addClass(
"selected-jqtranform"
);
jQuery("#" + prefix + "_country")
.parents(".row")
.addClass("ok-row");
jQuery("#" + prefix + "_country")
.parents(".row")
.removeClass("error-row");
jQuery("#" + prefix + "_country").val(jQuery.trim(countryCode));
var stateCode = address[2] ? address[1] : "";
stateCode = jQuery.trim(stateCode);
if (countryCode == "US") {
var base = base_url;
base = base.replace("https", "http");
jQuery.ajax({
url: base + "/getStateName",
dataType: "jsonp",
data: { stateCode: stateCode },
success: function(data) {
stateName = data;
jQuery("#jc_state").val(stateName);
jQuery("#jc_state").addClass("activated");
jQuery("#jc_state")
.parents(".row")
.removeClass("error-row");
jQuery("#jc_state")
.parents(".row")
.addClass("ok-row");
jQuery("#jc_state").trigger("change");
formValidate();
}
});
} else {
stateName = stateCode;
jQuery("#jc_state").val(stateName);
jQuery("#jc_state").addClass("activated");
jQuery("#jc_state")
.parents(".row")
.removeClass("error-row");
jQuery("#jc_state")
.parents(".row")
.addClass("ok-row");
jQuery("#jc_state").trigger("change");
formValidate();
}
jQuery("#" + prefix + "_zip")
.parents(".row")
.addClass("ok-row");
jQuery("#" + prefix + "_zip")
.parents(".row")
.removeClass("error-row");
},
open: function() {
jQuery(this)
.removeClass("ui-corner-all")
.addClass("ui-corner-top");
},
close: function() {
jQuery(this)
.removeClass("ui-corner-top")
.addClass("ui-corner-all");
},
change: function(event, ui) {
if (ui.item === null) {
jQuery("#" + prefix + "_zip")
.parents(".row")
.removeClass("ok-row");
jQuery("#" + prefix + "_zip")
.parents(".row")
.addClass("error-row");
$("#" + prefix + "_zip").val("");
}
}
});
}
If you are on https page, browser will block requests to non-secure resources (http).
Regularly you should see some notification about that. Looks like other browsers does not block non secure AJAX requests on secured pages by default, but google chrome does.
In your code, you have hardcoded URL:
url: "http://ws.geonames.org/postalCodeSearchJSON",
If that is cross domain request and it supports HTTPS, you can change it like this:
url: "//ws.geonames.org/postalCodeSearchJSON",
As you can see, protocol is not specified there. Browser will take page default protocol (http or https) and use it to request data.

Cant open images with Fancybox after appending to Flexslider after AJAX call

The following code below is in CoffeeScript and after a couple of hours playing around with it and finally reading the documentation on WooThemes, I was able to get the Flexslider to append images correctly after clicking on my button to load the rest of the images from Instagram.
However, now when I click on the image, it isn't opening the Fancybox like the rest of the images that load on page load and was wondering if I could get some help here.
Slider =
flexi: ->
$('.flexslider').flexslider
animation: 'slide'
animationLoop: true
slideshow: false
itemWidth: 160
itemMargin: 5
minItems: 1
maxItems: 10
start: (slider) ->
$('#load-more').on 'click', (event) ->
event.preventDefault()
$.ajax
type: 'get'
url: $(this).find('a').attr('href')
dataType: 'jsonp'
success: (data) ->
$.each data.data, (index, value) ->
slider.addSlide '<li class="thumb" data-profile="' + value.user.profile_picture + '" data-lat="0" data-long="0" data-id="' + value.id + '" data-thumb="' + value.images.thumbnail.url + '" data-username="' + value.user.username + '" data-comments="' + value.comments.count + '" data-likes="' + value.likes.count + '" data-text="' + value.caption.text + '" data-link="' + value.link + '"><img alt="' + value.images.thumbnail.url.split('/')[3].split('.jpg')[0] + '" src="' + value.images.thumbnail.url + '" /></li>'
Fancy =
box: (lat, lng, pid) ->
street = undefined
latLng = new google.maps.LatLng lat, lng
view = new google.maps.StreetViewService()
$('.fancybox').fancybox
width: 1155
height: '95%'
maxWidth: '95%'
maxHeight: '95%'
openEffect: 'none'
autoSize: true
autoResize: false
closeEffect: 'fade'
scrolling: 'auto'
type: 'iframe'
helpers:
media:{}
beforeShow: ->
........
You can try wrapping the fancybox call with live() or on() or go and change the FancyBox source code to use the live() instead of regular bind() method. Here's sort of an untested code to give you a sense.
// on
$(document.body).on('click', '.fancybox', function() {
$(this).fancybox({ /* options */ }).trigger('click');
return false;
}
// live
$('.fancybox').live('click', function() {
$(this).fancybox({ /* options */ }).trigger('click');
return false;
}

MVC 3 & Uploadify - how to show custom error message?

After uploading a file, before I save it on the disk, I'm doing some validation.
If something fails, I want to show my custom error message to the user.
I've found something sililar here Uploadify: show error message from HTTP response
How to do this in MVC 3 ?
Tony,
Taken straight from ab mvc3 app that I'm working on right now:
<script type="text/javascript">
function initupLoadify() {
$("#fileInput").uploadify({
uploader: '#Url.Content("~/scripts/swf/uploadify.swf")',
script: '#Url.Action("Upload", "Home")',
cancelImg: '#Url.Content("~/Content/cancel.png")',
auto: true,
sizeLimit: 5500000,
fileDataName: 'fileData',
//scriptData: { 'propertyId': $("#PropertyID").val() },
buttonText: 'Add Schedule',
wmode: 'transparent',
//buttonImg: '#Url.Content("~/Content/button.png")', // make nice gradient image for button
onComplete: function (event, queueId, fileObj, response) {
$("#msg").html(response);
// do something
setTimeout(2000, window.location = '#Url.Action("Index")' + '?id=' + response);
return true;
},
onCancel: function (evt, queueId, fileObj, data) {
$("#msg").html("<br />Operation cancelled");
return true;
},
onOpen: function (evt, queueId, fileObj) {
$("#msg").html("<br />Upload in progress");
return true;
},
onError: function (event, queueId, fileObj, errorObj) {
$("#msg").html(fileObj.name + " was not uploaded ");
if (errorObj.status == 404)
$("#msg").html("Could not find upload script. Use a path relative to: " + "<?= getcwd() ?>");
else if (errorObj.type === "HTTP")
$("#msg").html("error " + errorObj.type + ": " + errorObj.status);
else if (errorObj.type === "File Size")
$("#msg").html(fileObj.name + " " + errorObj.type + " Limit: " + errorObj.info / 1000 + " KB");
else
$("#msg").html("error " + errorObj.type + ": " + errorObj.text);
}
});
};
</script>
hope this helps
Here is an MVC 3 example.
If you're using versions 3.0+ use onUploadComplete instead of onComplete (realize their parameters differ).

Resources