Error: 'History.Adapter' is null or not an object - javascript

js and all works fine in all browsers except IE8.
I've next error
Error: 'History.Adapter' is null or not an object
My code:
#Scripts.Render("~/bundles/history")
<script type="text/javascript">
var History = window.History;
$(document).ready(function () {
change(1, '#catalog');
History.Adapter.bind(window, 'statechange', function () {
try {
var State = History.getState();
$('#Products').load(State.url);
} catch (e) {
}
});
function change(id, ItemMenu) {
var url = $('#' + id).val();
try
{
History.pushState({}, null, url);
}
catch(e)
{
}
}
</script>
and scripts:
bundles.Add(new ScriptBundle("~/bundles/history").Include(
"~/Scripts/History/history.adapter.jquery.js",
"~/Scripts/History/history.html4.js",
"~/Scripts/History/history.js",
"~/Scripts/History/json2.js"
));

For correct work in IE 8 you need to place initialization history.js and History.Adapter.bind inside $(document).ready(...)
This will work in all browsers...and IE 8 to
#Scripts.Render("~/bundles/history")
<script type="text/javascript">
$(document).ready(function () {
var History = window.History;
History.Adapter.bind(window, 'statechange', function () {
try {
var State = History.getState();
$('#Products').load(State.url);
} catch (e) {
}
});
});
function change(id, ItemMenu) {
var url = $('#' + id).val();
try
{
History.pushState({}, null, url);
}
catch(e)
{
}
}
</script>

Related

sammyjs cannot go back to a route i accessed before

I'm new to SammyJS and I am running into an issue. I have my routes working, however when I access 1, and then i go to the other. It works. The problem is when I try to go back to the first route that I visited. I'm working with ASP.NET MVC and sammyjs.
Here is my code...
<script type="text/javascript" charset="utf-8">
debugger;
; (function ($) {
var app = $.sammy(function () {
debugger;
this.get('#/PartIndex', function () {
var routing = new Routing('#Url.Content("~/")', '#testing', 'CustomerDetail/CustomerEditDetailPartial');
routing.init();
});
this.get('#/ECheckbook', function () {
debugger;
var routing = new Routing('#Url.Content("~/")', '#testing', 'CustomerDetail/CustomerEditDetailPartial');
routing.init();
});
});
$(function () {
app.run()
});
})(jQuery);
<div class="page-container">
Margin
<br />
Main
<div id="testing">
</div>
in my routing.js
var Routing = function (appRoot, contentSelector, defaultRoute) {
function getUrlFromHash(hash) {
debugger;
var secondString = hash.split('/')[2];
var url = hash.replace('#/', '').replace(secondString + '/', '');
if (url === appRoot)
url = defaultRoute;
return url;
}
return {
init: function () {
Sammy(contentSelector, function () {
this.get(/\#\/(.*)/, function (context) {
var url = getUrlFromHash(context.path);
context.load(url).swap();
});
}).run('#/');
}
};
}

Object doesn't support property or method "EditDocument"

I am trying to running this below codes, hoewever it prompt me an error that saying : Object doesn't support property or method "EditDocument". Can anyone help me why this error occurs?
<object id="winFirefoxPlugin" type="application/x-sharepoint" width="0" height="0" style="visibility: hidden;">Test-2.docx</object><a onclick='javascript: editDocument();' href='#'>Word Doc</a>
<script>
var fNewDoc = false;
$(document).ready(function () {
var fNewDoc = false;
var EditDocumentButton = null;
try {
EditDocumentButton = new ActiveXObject('SharePoint.OpenDocuments.2');
if (EditDocumentButton != null) {
fNewDoc = true;
}
} catch (e) {
}
});
var L_EditDocumentError_Text = "Editing not supported.";
var L_EditDocumentRuntimeError_Text = "Sorry, couldn't open the document.";
function editDocument() {
if (fNewDoc) {
if (!EditDocumentButton.EditDocument(strDocument)) {
alert(L_EditDocumentRuntimeError_Text);
}
} else {
try {
var hownowPlugin = document.getElementById("winFirefoxPlugin");
hownowPlugin.EditDocument('http://localhost:46961/wordstorage/Test-2.docx', null);
} catch (e) {
alert(L_EditDocumentError_Text);
}
}
}
</script>
Regards
What is the browser that your are using to test this?
This should work in IE and FireFox browsers.
if (fNewDoc) {
if (!EditDocumentButton.EditDocument(strDocument)) {
alert(L_EditDocumentRuntimeError_Text);
}
} else {
try {
var hownowPlugin = document.getElementById("winFirefoxPlugin");
var version = hownowPlugin.GetOfficeVersion();
hownowPlugin.EditDocument(strDocument, version);
} catch (e) {
// console.log(e);
alert(L_EditDocumentError_Text);
}
}

How can prevent the scroll event execute more times?

I am implementing a new feature to let my page to support endless scroll AJAX show. But when I pull down my page scroll bar, sometimes the same request occurs.
This means that alert(nextPage) method is executed and it shows the same result. I've added the event.stopPropagation() code, but it didn't solve the problem. How can i fix it?
(function(window, undefined) {
var app = {
event: {
add: function(obj, type, handle) {
try {
obj.addEventListener(type, handle, false);
} catch (e) {
try {
obj.attachEvent('on' + type, handle);
} catch (e) {
obj['on' + type] = handle;
}
}
}
},
scroll: function(id, url) {
$.get(url, function(html) {
$("#" + id).append(html)
});
}
}
})(window);
HTML
<script>
$(function() {
app.event.add(window, "scroll", function(event) {
var nextPage = getNextPage();
alert(nextPage);
app.scroll("productTable", '?page=' + nextPage);
if (event && event.stopPropagation) {
event.stopPropagation();
} else {
window.event.cancelBubble = true;
}
});
});
</script>

Create function for CamanJS Plugin

is there any chance to create a function that i can call?
if i'm putting the following lines in the document ready function it works:
Caman("25-02-2014_16-37-13.jpg", "#example-canvas", function () {
this.brightness(brightness);
this.render(function () {
check = this.toBase64();
});
But if i'm doing this i can't call. So I tried this:
function icancall()
{
Caman("25-02-2014_16-37-13.jpg", "#example-canvas", function () {
this.brightness(brightness);
this.render(function () {
check = this.toBase64();
});
}
So i thought i can call this with icancall(); But nothing happened. What am I doing wrong?
What i want do: executing the Caman function on a button click.
I hope you can help me !
function resz(){
Caman("25-02-2014_16-37-13.jpg", "#example-canvas", function () {
try {
this.render(function () {
var image = this.toBase64();
xyz(image); // call that function where you pass filters
});
} catch (e) { alert(e) }
});
}
[Apply CamanJS filters by this function]
function xyz(image){
var filters_k = $('#filters');
filters_k.click(function (e) {
e.preventDefault();
var f = $(this);
if (f.is('.active')) {
// Apply filters only once
return false;
}
filters_k.removeClass('active');
f.addClass('active');
var effect = $.trim(f[0].id);
Caman(canvasID, img, function () {
if (effect in this) {
this.revert(false);
this[effect]();
this.render();
}
});
});
}

Ajax.Request doesn't work in IE

I using prototype javascript
I am using ajax function which works perfectly in FF but not in IE
var MOList_VenuePostBox;
function getPreSearch(tid,tname){
include_js("http://" + getHostPath() + "/_scripts/lib/z_autocomplete_messagecenter.js",
function() {
//,{fetchFile:'/ajax/spot/getmyspots.aspx'}
MOList_VenuePostBox = new MOList('txtTagTheItem_VenueProfile', 'molist-auto1');
var counter = 0;
// fetch and feed
new Ajax.Request('/_service/getTagwordsByName.ashx', {
onSuccess: function(transport) {
transport.responseText.evalJSON(true).each(function(t)
{
MOList_VenuePostBox.autoFeed(t);
});
}
});
});
}
Thanks in advance
I just passed method as get
it solved my problem
include_js("http://" + getHostPath() + "/_scripts/lib/z_autocomplete_messagecenter.js",
function() {
//,{fetchFile:'/ajax/spot/getmyspots.aspx'}
MOList_VenuePostBox = new MOList('txtTagTheItem_VenueProfile', 'molist-auto1');
var counter = 0;
// fetch and feed
new Ajax.Request('/_service/getTagwordsByName.ashx', {
method:get,
onSuccess: function(transport) {
transport.responseText.evalJSON(true).each(function(t)
{
MOList_VenuePostBox.autoFeed(t);
});
}
});
});

Categories

Resources