w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Defining Multiple Comparators for Sorting and Reverse Sorting Appcelerator Backbone Models
To sort in descending order for strings(case insensitive) or just numbers, try this: var sort_descending = false; /* assuming you are able to set this variable when you need to sort */ var sort_attribute_name = "title"; /* assuming you can set the attribute name on which you want to sort */ book_list.comparator = function(book){ /* book_list is an instance of book_collection */ if(sort_descending){ if(isNaN(book.get(sort_attribute_name)){ var str = book.get(sort_attribute_name); str = str.toLowerCase(); str = str.split(""); str = _.map(str, function(letter){ return String.fromCharCode(-(letter.charCodeAt(0))); /* from an SO answer*/ }); } return -book.get(sort_attribute_name); } return book.get(sort_attribute_name); };

Categories : Sorting

Can Overflow menu on Android be used for "sorting menu" instead of usual help n settings in its options?
As a user, I think that's and odd choice. Depends of what kind of other options there are, but if there aren't any other, I'd suggest you put these in the action bar. The menu is for me the place to hold the other, less frequently used options. So basically that's up to you and what you intend to put as options. If there are more important ones, it's clear you should put them first, and disregard the sorting options in the "overflow menu".

Categories : Android

Sorting collections using Backbone.js
Backbone.Collection doesn't take into account a events hash like Backbone.View does, you have to bind events yourself. You could use the initialize method to do so, something like var ProductCollection = Backbone.Collection.extend({ model:Product, initialize: function() { this.on('sort', this.test); }, test: function(){ console.log('test'); } }); And a demo http://jsfiddle.net/nikoshr/fTwpf/

Categories : Javascript

Collection Sorting not working on Backbone.Marionette using restful Services
Not sure if only writing the model field name as comparator would help. Instead you can write a custom function in comparator something like below: comparator : function (m1, m2) { var str1, str2; str1 = m1.get('firstName'); str2 = m2.get('firstName'); if (str1 && str2) { str1 = str1.toLowerCase(); str2 = str2.toLowerCase(); if (str1 > str2) { return 1; } else if(str2 > str1) { return -1; } } } This would sort your collection every time you add/remove a model to the collection or call the collections sort method

Categories : Backbone Js

sorting my javascript pull down menu by name not key#
In the sort function, the keys array should be receiving the object pointed by the key and not the key instead. You could also store the value of the key in each array object to reference it later. Then the sort function should be comparing the name property of each object: function getSortedKeys(obj) { var keys = []; for(var key in obj) { keys.push(obj[key]); keys[keys.length-1]['key'] = key; } return keys.sort(function(a,b){ return a.name > b.name ? 1 : a.name < b.name ? -1 : 0;}); } // returns [{name:'...', projects:'...', key: '...'}, {}, {}]

Categories : Javascript

Sorting mouse-buffer-menu
I don't think you can get what you are asking for ("a long list of C files and assembly files at the top then subfolders for all other files") without hacking the emacs sources. However, you can arrange all buffers by modes: customize mouse-buffer-menu-mode-mult to 0, either using M-x customize or by adding (custom-set-variables '(mouse-buffer-menu-mode-mult 0)) to your ~/.emacs.el. See also: How do I set the number of items in the mouse buffer menu in Emacs? How to get Emacs buffer-menu always to show mode-names?

Categories : Emacs

Selected field is blank when fetches a Backbone collection with Backbone-forms
Look at the example http://jsfiddle.net/evilcelery/dW2Qu/ var user = new User({ title: 'Mr', name: 'Sterling Archer', email: 'sterling@isis.com', birthday: new Date(1978, 6, 12), password: 'dangerzone', notes: [ 'Buy new turtleneck', 'Call Woodhouse', 'Buy booze' ] }); These are the defaults. In your case you would use something similar to var options = new App.Collection.Tags; class foo extends Backbone.Model schema: tag: type: 'select' options: options for (first in options) break; var Foo = new foo({tag:first});

Categories : Backbone Js

How to create / update a Backbone View based on a response from a Backbone Model?
You can structure the view and model in the following way: var Item_m = Backbone.Model.extend({ urlRoot: '/welcome/item' }); var ItemView = Backbone.View.extend({ initialize: function() { this.model = new Item_m (); this.listenTo(this.model, "change", this.render); /*Can setup the periodic pull using Backbone.poller.*/ //https://github.com/uzikilon/backbone-poller }, render: function() { //Do UI rendering stuffs } }); var itemVieww = new ItemView ();

Categories : Javascript

backbone-forms how do I submit the generated form in Backbone rest?
Usual way is to create a 'master' Backbone view that contains the submit button, then insert the form into that. Then handle the submit click event from within your master view. That would be done by doing form.commit() to set it on the model, and then calling model.save()

Categories : Backbone Js

Backbone model is not rendering default? Need Jade and Backbone gurus
Try removing this line from your view model: App.Models.User, You are trying to assign a Backbone function directly to your view. Also the problem is because of this line in your render method.. render: function() { var template = Handlebars.compile($("#userTemplate").html()); var editTemplate = Handlebars.compile($("#userEditTemplate").html()); The editemplate is local to the render method and not available in other methods. editProfile: function () { this.$el.html(this.editTemplate(this.model.toJSON())); }, You are trying to access the template using this.editTemplate , but the variable is local to the render method and not to the view.. So you are not able to access it.. Instead of creating it in the local scope, instantiate to the view it self so that it

Categories : Javascript

How can I fetch data asynchronously in backbone using backbone layout manager?
You can always listenTo to events on the collection. initialize : function() { this.collection = new BobLawBlaw.Collection(); this.listenTo(this.collection, 'sync', this.render); this.collection.fetch(); } So if you listenTo the sync event , the render method will be called when the collection is in sync with the server.

Categories : Javascript

Twitter Bootstrap responsive menu/small devices: close/collapse menu on clicking a menu item
You can try something like.. $('.nav li a').on('click',function(){ $('.nav-collapse').collapse('hide'); }) This will work for menu links that are referencing '#'. The menu should already be collapsing if your menu links navigate to another page on the site as this would cause a full page refresh.

Categories : Twitter

How To Change Backbone Dynamic URL with Backbone Events/Vent?
Assuming UniqueArticle to be the Backbone Model, for the Model with a specific id to be fetched you would need to define the urlRoot property which will append the id of the model to the request. So the id attribute will be appended to the end of the request the model from the server when you do a fetch on it var UniqueArticle = Backbone.Model.extend({ idAttribute : 'someuser', urlRoot : function(someuser){ return '/api/visitingarticles/' } // this would send a request for // /api/visitingarticles/someId }); var UniqueArticles = Backbone.Collection.extend({ model: Article, url : function(someuser){ return '/api/visitingarticles/' } // /api/visitingarticles -- All Articles will be fetched })

Categories : Backbone Js

How to parse the json response of backbone js in the backbone view?
This code snippet does the job for me. this.getSegment = new CustomerCollection(); this.getSegment.fetch({ success: function(response) { var data = response.toJSON(); console.log(data[0].custId); } }); i looped it to the length of the json to get custId of all the JSON.

Categories : Json

Optimal URL structure for Backbone.js and Backbone implementation
If questiongroups can only appear in a single quiz, then the first option (the hierarchical one) is an obvious choice. To comply with RESTful conventions, you might want to consider using singular nouns instead: /quiz/:id/questiongroups/:id/question/:id/answer/:id To solve your fetching problem, I would recommend using nested backbone models as per this answer: http://stackoverflow.com/a/9904874/1941552. I've also added a cheeky little parentModel attribute. For example, your QuizModel could look something like this: var Quiz = Backbone.Model.extend({ urlRoot: '/quiz/', // backbone appends the id automatically :) defaults: { title: 'My Quiz' description: 'A quiz containing some question groups.' }, model: { questionGroups: QuestionGroups,

Categories : Javascript

CUDA parallel sorting algorithm vs single thread sorting algorithms
Sorting is an operation that has received a lot of attention. Writing your own sort isn't advisable if you are interested in high performance. I would consider something like thrust, back40computing, moderngpu, or CUB for sorting on the GPU. Most of the above will be handling an array at a time, using the full GPU to sort an array. There are techniques within thrust to do a vectorized sort which can handle multiple arrays "at once", and CUB may also be an option for doing a "per-thread" sort (let's say, "per thread block"). Generally I would say the same thing about CPU sorting code. Don't write your own. EDIT: I guess one more comment. I would lean heavily towards the first approach you mention (i.e. not doing a sort per thread.) There are two related reasons for this: Most

Categories : Sorting

css drop down menu :: sub menu is appearing within main menu after hover
You have to make some changes in the code. Fiddle css .menu{ width:70%; background:green; position:relative; } .menu ul{list-style:none;} .menu ul li{ margin-left:20px;position:relative; float:left} .menu ul ul{display:none;} .menu ul li:hover ul{display:block; background:black; position: absolute; margin: -2px 0 0 0; z-index: 11110;} .menu ul li:hover ul li{ float:none; height:20px; } Updated Fiddle Changes: display: inline-block; occupies the combined width of the inner container. position:relative; using it in menu will cause increase in the height of the outer container. you can read it at w3school

Categories : HTML

Backbone & Rails. Why do you set routes in backbone?
Backbone is designed to be used in single-page applications, therefore it has a little to do with Rails routing. All Rails has to do is land a .html page, and everything else is client's concern. If you intend to use Rails as an API, then its routing does not matter at all. You can even keep Rails application and frontend on different servers. In this case all what Rails has to do is process requests from the client. For example, you can build your client-side without any hard ties to a backend, they can be absolutely separated. You just make AJAX calls from a client, then server processes them and responds with JSON. Also, Backbone does not "route the javascript files to that html pages". It just executes functions according to a hash "route: action". These are just plain JavaScript fun

Categories : Ruby On Rails

Backbone, RequireJS & Backbone-MVC, MVC = null
you try with this code. require.config({ paths: { jquery: 'libs/jquery/jquery-min', bootstrap: 'libs/bootstrap/bootstrap-min', underscore: 'libs/underscore/underscore-min', backbone: 'libs/backbone/backbone-min', backbonemvc: 'libs/backbone/backbone-mvc', templates: '../templates' }, shim:{ 'backbone': { deps: ["underscore", "jquery"], exports: "Backbone" }, 'backbonemvc': { deps: ["backbone"], exports: "MVC" } } }); The shim config can be wrong.

Categories : Javascript

Whats the difference between Backbone.Model.extend() vs class X extends Backbone.Model?
coffeescript creates the extends method at the top of the closure: __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; underscore defines it as such: http://underscorejs.org/docs/underscore.html#section-76 The implementation is slightly different but the effect is the same. If you are using Backbone or more specifically Underscore, you can choose to do either method, but extends in coffeescript allows you to extend any class without the need of a dependency like Underscore or Backbone. An example of what you can do with the method while using backbon

Categories : Javascript

Ext.menu.Menu (Context Menu) is displayed only once on right click - Ext JS 4.2.1
Because you're creating a new menu instance every time, which means: a) Memory leak b) Duplicate component id So, remove the id from the class definition, you don't need it. Secondly, only create the menu once: onViewItemContextMenu: function(dataview, record, item, index, e, eOpts) { e.stopEvent(); if (!this.menu) { this.menu = Ext.create('MyApp.view.TreeContextMenu'); } this.menu.showAt(e.getXY()); }

Categories : Javascript

Backbone.model.save sending the whole backbone.model in request body
patch works only for already created models. In case if your model is new it wouldn't work. How to fix it: var model = new Backbone.Model(); var attributesToSave = {}; model.save(null, {attrs:attributesToSave});

Categories : Javascript

C++ Bubble Sorting and Selection Sorting
#include <iostream> #include <string> #include <iomanip> using namespace std; void sortArray (int [ ], int ) ; void showArray (int [ ], int ) ; int count = 0; int main () { const int SIZE = 6; int values[SIZE] = {7, 2, 3, 8, 9, 1} ; cout << "The unsorted values are: "; showArray (values, SIZE) ; sortArray (values, SIZE) ; cout<< "The sorted values are: " ; showArray (values, SIZE) ; return 0; } void sortArray (int array [ ], int SIZE) { int temp; bool swap; do { swap = false; for (int count = 0 ; count < (size - 1 ) ; count ++) { if (array [count] > array [count + 1] ) { temp = array [count] ; array [count] = array [count + 1] ; array [count + 1] = temp ; swap = true ; count++; dispCount(); } } } while (swap) ; } void dispCount(){ cout <<

Categories : C++

JS object sorting date sorting
Both console.log show the same array because when you use console.log(sortable), sortable is passed by reference, and console output happens AFTER finishing your script - when sortable has been already sorted. Making your code simple: var arr = [3,2,1]; console.log(arr); // Produces `[1,2,3]` because its printed // to the console after `arr.sort();` arr.sort(); console.log(arr); // Produces `[1,2,3]`, as expected Demo: http://jsfiddle.net/Rfwph/ Workaround If you want to be able to do console.log with an array to see it before being modifyed, you can use .slice(0) to copy the array, i.e. to obtain another array which contains the same elements as your array. var arr = [3,2,1]; console.log(arr.slice(0)); // [3,2,1] arr.sort(); console.log(arr); // [1,2,3] Demo:

Categories : Javascript

Architecture/Design of PageObjects for Pages with hierarchy: menu-items/menu-sub-items/menu-sub-items-tabs
I think the following will be a simple and efficient solution, Class for Main page with methods to navigate(or click) other menu items and logout. Class for each menu item with methods for sub menu items, extend the Main page class

Categories : Java

sorting tr elements with nested tables, hide nested tbody while sorting
jsFiddle Demo At first I'd like to say that it's clear you really put effort in finding a solution on your own so it really made me want to help. The problem is that if you hide parts of the element after it begins to be dragged, the size isn't recalculated. The solution is like in the code you've linked. You have to catch a more preliminary event (like mousedown) and hide it before the dragging begins. $('tr.draggable_item').mousedown(function() { $(this).find("tbody").hide(); }); $('tr.draggable_item').mouseup(function() { $(this).find("tbody").show(); });

Categories : Jquery

HTML 5 navigation menu showing overlapping list items in sub menu on hover
Make this change .MainMenu li:hover .SubMenu li{ display: block; position: relative; } position:relative; FIDDLE

Categories : HTML

I have made one post on WordPress http://www.rigelnetworks.com/service-menu/ wherein I created menu tab
If you don't want Google or other search engines to crawl a page, add: <META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW"> to your header. If you only want that tag to be on one page, you could use something like the following in your header file: <?php if( is_page( 'service-menu' ) ) : ?> <META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW"> <?php endif; ?> Then, it will put the no-index, no-follow tag on just that page. If you want it site wide, there is an option in WP admin area under Settings > Reading Settings > Discourage Search Engines From Indexing This Site -- check that off for a sitewide solution.

Categories : Wordpress

VSTO (Document-level): Individual context menu in Excel (right click menu)
Here's some rough sample code with comments This was created in VS2010 and tested against Excel 2010 First step was to created a new Excel 2010 Add-In project Then added the sample code below to the default code generated inside ThisAddin.cs. This code will add a new menu item and remove the cut/copy/paste menu items when right-clicking on a single cell containing 'abc'. This is to simulate changing the context menu based on the contents of a cell. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Xml.Linq; using Excel = Microsoft.Office.Interop.Excel; using Office = Microsoft.Office.Core; using Microsoft.Office.Tools.Excel; using System.Diagnostics; using Microsoft.Office.Interop.Excel; nam

Categories : C#

Show previous visited drop down menu item color different than other menu items.
If I understand your question correctly then you want to use the :visited selector in your css. Hard to give specifics without you providing some code, but this is the general idea: a:visted { color: orange; } You can go Here for an example. That link also contains examples for other related selectors which might be useful to you, such as :hover

Categories : CSS

jQuery current-menu-item-highlight in tandem with js anylink menu
This should help: In menucontents.js change make the following changes: anylinkmenuINDIA={divclass:'anylinkmenu' // to anylinkmenuINDIA={divclass:'anylinkmenuINDIA' anylinkmenuPROJECTS={divclass:'anylinkmenu' // to anylinkmenuPROJECTS={divclass:'anylinkmenuPROJECTS' and so on. Basically, make the divclass the same as the object name. Then update anylinkmenu.css so that your new classes will be styled properly. Line 14 would become: .anylinkmenuINDIA, .anylinkmenuPROJECTS, /* your other classes here */ { Then you can use this: $(document).ready(function () { var loc = window.location.href.replace(window.location.hash, ''); $('#bcp-nav a, div[class^="anylinkmenu"] a').each(function (index) { if (this.href.trim() == loc) { var linkClass = $(this).closest(

Categories : Javascript

twitter bootstrap input click outside of dropdown-menu; is hiding menu
You have to use stopPropagation event to avoid closing of the dropdown menu. $(function () { $('.dropdown-menu').find('input[type="text"]').click(function (e) { e.stopPropagation(); }); }); Here is one bootply example for you. http://bootply.com/63262 . NB Please make sure that you research a bit before asking questions, and also please provide relevant codes that you have used.

Categories : Twitter

Angular options for single select menu with child select2.js tag menu
I did not fully understand your question. But if you are trying to populate the second dropdown based on the first one then you can as below: As a first step, I converted your events model from a list to a hash. This makes accessing the contents quite easy: $scope.events = { "EscapeCape":{ "name":"Escape The Cape", "playlists":[ { "name":"Run Course Preview", "tag":"RunCoursePreview" } ] }, "WildwoodTriathlon":{ "name":"Wildwood Triathlon", "playlists":[ { "name":"Bike Course Preview", "tag":"BikeCoursePreview" }, { "name":"Race Announcements", "tag":"RaceAnnouncements

Categories : Angularjs

Keeping the accordion menu open to show selected menu item
The initMenu() function, should look like this: function initMenu() { $(".sub-menu").hide(); $(".current_page_item .sub-menu").show(); $('#menu li a').click( function() { var checkElement = $(this).next(); if ((checkElement.is('ul')) && (checkElement.is(':visible'))) { checkElement.slideUp('normal'); return false; } if ((checkElement.is('ul')) && (!checkElement.is(':visible'))) { $('#menu ul:visible').not(checkElement.parentsUntil('#menu')).slideUp('normal'); checkElement.slideDown('normal'); return false; } }); $('.current-menu-item').parentsUntil('#menu').slideDown('normal'); var FullCurrentURL = window.location.href; var CurrentURLparts = FullCurrentURL.split("/"); var CurrentURLindex = CurrentURLparts.lengt

Categories : Misc

Menu animation and hover state - simple jQuery solution (LavaLamp menu's idea)
I found this example page: http://www.script-tutorials.com/demos/249/index.html In it, the selection returns to the "home" when the mouse is not hovering over the menu. There's also a tutorial for it. It does not contain any javascript I think.

Categories : Jquery

Clicking on a list item containing sub menu in a drop down menu, closes the rest but doesn't expand the new one
Made a little change here: http://jsfiddle.net/JWMarchant/nUrjy/7/ Simplified the code to this: $('#main-navigation a').click(function (e) { /* Finding the drop down list that corresponds to the current section: */ var dropdownMenu = $(this).next(); if ($(this).parent('li').children('.sub-menu').length > 0) { $('.sub-menu').not(dropdownMenu).not(dropdownMenu.parents()).slideUp('fast'); $(dropdownMenu).slideToggle('fast'); } });

Categories : Javascript

In Jquery Jpanel menu , on mobile, if page length is increasing , menu is opening with a jerkness
There was no solution yet. As far I find out, it can be minimize using some ways. like:- There are two main events that jquery jpanel menu provides. BeforeOpen. AfterClose. These events solved my issues for a limit. You can hide or set display none for page that is non in display area on event BeforeOpen. And unhide in afterClose Event. This is pure you logic how do u maintain that.

Categories : Jquery

jquery mobile menu to close after i click a menu item
Add an extra event to make it happen. You could trigger the click of #menu-icon when some menu item is clicked: $("#nav").on("click", "li", function () { $("#menu-icon").click(); //or $("#nav").slideToggle(); }); Demo : http://jsfiddle.net/hungerpain/RtMNj/2/

Categories : Jquery

Android Menu not showing in emulator on clicking on Menu button
A very late post, but: Press the F2 key when running in the emulator to toggle display of the menu (similar to pressing the menu button on a device). The menu button on the standard emulator does not work if Android3.0+ is used as the emulated OS

Categories : Android

Sub menu wont show when menu item hovered over (css html)
Pretty easy. The submenu ul#sub-menu is not a child of the anchor element, but of the list element. You must either put the submenu inside the anchor element or check for the hover on the list element as following: ul#nav-1 li:hover > ul#sub-menu { instead of ul#nav-1 li a:hover > ul#sub-menu { http://jsfiddle.net/ULSsa/2/

Categories : HTML



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.